我已经在我的采购订单模型中添加了一个定制字段“佣金”。单击“ purchase.order.form”视图的“创建帐单”时,我想在“ account.invoice.supplier.form”视图中显示“佣金”字段。我继承了购买模块中的action_view_invoice函数
我的field.py
# -*- coding: utf-8 -*-
from odoo import api, models,fields
import logging
_logger = logging.getLogger(__name__)
class ConfirmComm(models.Model):
_inherit = "account.invoice"
commission = fields.Float(string='Commission', required='true', default=0)
@api.multi
def action_view_invoice(self,order):
'''
This function returns an action that display existing vendor bills of given purchase order ids.
When only one found, show the vendor bill immediately.
'''
action = self.env.ref('account.action_vendor_bill_template')
result = action.read()[0]
create_bill = self.env.context.get('create_bill', False)
# override the context to get rid of the default filtering
result['context'] = {
'type': 'in_invoice',
'default_purchase_id': self.id,
'default_currency_id': self.currency_id.id,
'default_company_id': self.company_id.id,
'company_id': self.company_id.id
'commission': order.commission,
}
_logger.info("KTR this is save invoice$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ %d", self.commission)
# choose the view_mode accordingly
if len(self.invoice_ids) > 1 and not create_bill:
result['domain'] = "[('id', 'in', " + str(self.invoice_ids.ids) + ")]"
else:
res = self.env.ref('account.invoice_supplier_form', False)
result['views'] = [(res and res.id or False, 'form')]
# Do not set an invoice_id if we want to create a new bill.
if not create_bill:
result['res_id'] = self.invoice_ids.id or False
result['context']['default_origin'] = self.name
result['context']['default_reference'] = self.partner_ref
return result
我的field.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="view_invoice_form_inherit" model="ir.ui.view">
<field name="name">account.invoice.supplier.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_supplier_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='user_id']" position="after">
<field name="commission"/>
</xpath>
</field>
</record>
</data>
</odoo>
答案 0 :(得分:0)
使用相关字段(https://www.odoo.com/documentation/12.0/reference/orm.html#fields)
class ConfirmComm(models.Model):
_inherit = "account.invoice"
purchase_order_id = fields.Many2one("purchase.order", string="Related purchase order")
commission = fields.Float(related="purchase_order_id.commission")