我成功生成了供应商发票。 我现在的问题是我无法支付我创建的发票(通过代码)。 这似乎是由于不正确的帐户用于付款?
错误是:没有任何反应,事件状态不会从打开变为付费 但是当我从演示数据手动将帐户更改为“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)
答案 0 :(得分: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,
您需要使用产品或产品类别的费用帐户。