Inheritance 如何显示型号“;销售订单”;在“;账户、发票和#x201D;在奥多12

Inheritance 如何显示型号“;销售订单”;在“;账户、发票和#x201D;在奥多12,inheritance,field,odoo,Inheritance,Field,Odoo,我已将自定义字段“佣金”添加到我的采购订单模型中。单击“采购.订单.表格”视图的“创建账单”时,我想在“账户.发票.供应商.表格”视图中显示“佣金”字段。我从采购模块继承了操作\u查看\u发票功能 我的领域.py # -*- coding: utf-8 -*- from odoo import api, models,fields import logging _logger = logging.getLogger(__name__) class ConfirmComm(models.Mod

我已将自定义字段“佣金”添加到我的采购订单模型中。单击“采购.订单.表格”视图的“创建账单”时,我想在“账户.发票.供应商.表格”视图中显示“佣金”字段。我从采购模块继承了操作\u查看\u发票功能

我的领域.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
my 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>

账户、发票、供应商、表格
帐户、发票
使用相关字段()

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