0

我成功生成了供应商发票。我现在遇到的问题是我无法支付我创建的发票(通过代码)。似乎是由于用于付款的帐户不正确?

错误是:没有任何反应,如果状态没有从打开变为已付款,但是当我从演示数据手动将帐户更改为“X111111 债权人(测试)”时,它会毫无问题地获得付款。

这是我的代码:

    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)
4

1 回答 1

1

关于发票创建,

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

在这里,您需要使用应付账款而不是应收账款,因为您要创建供应商发票。所以代码应该是这样的:

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

关于发票行创建,

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

在这里您需要使用产品或产品类别的费用帐户。

于 2013-04-10T05:15:33.787 回答