我在采购订单模型中添加了佣金字段,当我单击“创建帐单”时,我想在帐户发票中显示该字段。下面是我的代码,但是它不起作用,希望有人可以帮助我。预先非常感谢。
class ConfirmComm(models.Model):
_inherit = "purchase.order"
commission = fields.Float(string='Commission', required='true', default=0)
@api.multi
def action_view_invoice(self, cr, uid, order, context=None):
if context is None:
context = {}
journal_id = self.pool['account.invoice'].default_get(cr, uid, ['journal_id'], context=context)['journal_id']
if not journal_id:
raise UserError(_('Error!'),
_('Please define purchase journal for this company: "%s" (id:%d).') % (
order.company_id.name, order.company_id.id))
invoice_vals = {
'name': order.partner_ref or '',
'origin': order.name,
# 'type': 'in_invoice',
# Sale order id as source_id
# 'source_id': order.id,
'reference': order.partner_ref or order.name,
'account_id': order.partner_invoice_id.property_account_receivable.id,
'partner_id': order.partner_invoice_id.id,
'journal_id': journal_id,
'commission': order.commission,
# 'invoice_line': [(6, 0, lines)],
'currency_id': order.pricelist_id.currency_id.id,
# 'comment': order.note,
'payment_term_id': order.payment_term_id or False,
'fiscal_position_id': order.fiscal_position_id,
'date_invoice': context.get('date_invoice', False),
'company_id': order.company_id.id,
'user_id': order.user_id and order.user_id.id or False,
}
_logger.info("KTR this is commissionTest $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ %d", order.commission)
invoice_vals.update(self._inv_get(cr, uid, order, context=context))
return invoice_vals
答案 0 :(得分:0)
您还需要将此字段添加到模型account.invoice
中,因为使用相关字段或某些奇特用法,purchase.order
和account.invoice
之间没有直接关系。要在发票表单视图中查看该字段,您也必须像往常一样在此添加它。
其余的代码应该没问题,因为下一个重要的部分是使用purchase.order.action_view_invoice()
来设置值,但是您已经完成了;-)