Question

i succeeded in generating a supplier invoice. The problem i have now is that i can not pay the invoice i create (by code). It seems it is due to the incorrect account being used for payment ?

The error is : nothing happens , event the state does not change from open to paid but when i manually changes the account to the 'X111111 creditors (test)' from the demo data it gets paid without problems.

Here is my code:

    for commission in self.browse(cr, uid, ids, context=context):
        if commission.supplier_invoice.id:
            continue
        journal_ids = self.pool.get('account.journal').search(cr, uid,
                                                              [('type', '=', 'purchase'),
                                                               ('company_id', '=',
                                                                commission.invoice.company_id.id)],
                                                              limit=1)
        if not journal_ids:
            raise osv.except_osv(_('Error!'),  # TODO change text message
                                 _('Please define sales journal for this company: "%s" (id:%d).') % (
                                     'dummy', 'dummy'))
        invoice_line = {
            'name': 'commission',
            'sequence': 5,
            'invoice_id': False,
            'account_id': commission.salesperson.partner_id.property_account_receivable.id,
            'price_unit': commission.commission_total,
            'quantity': 1.0,
        }

        invoice_line_id = self.pool.get('account.invoice.line').create(cr, uid, invoice_line, context=context)
        new_invoice = {
            'name': 'commission on sale',
            'type': 'in_invoice',
            'reference': '',
            'account_id': commission.salesperson.partner_id.property_account_receivable.id,
            'partner_id': commission.salesperson.partner_id.id,
            'journal_id': journal_ids[0],
            'invoice_line': [(6, 0, [invoice_line_id])],
            'currency_id': commission.invoice.currency_id.id,
            'comment': 'test',
            'fiscal_position': commission.salesperson.partner_id.property_account_position.id,
            'company_id': commission.invoice.company_id.id,
            'user_id': uid
        }
        invoice_id = self.pool.get('account.invoice').create(cr, uid, new_invoice, context=context)

        self.write(cr,
                   uid,
                   [commission.id],
                   {'supplier_invoice': invoice_id},
                   context=context)
Was it helpful?

Solution

Regarding Invoice Creation,

'account_id': commission.salesperson.partner_id.property_account_receivable.id

Here you need to use Payable Account instead of Receivable Account as you are going to create Supplier invoice. So code should be like this:

'account_id': commission.salesperson.partner_id.property_account_payable.id

Regarding Invoice line Creation,

'account_id': commission.salesperson.partner_id.property_account_receivable.id,

Here you need to use Expense Account of Product or Product category.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top