如何在 odoo 14 中通过继承自定义产品模板视图?

How do i customise product template views by inheritance in odoo 14?

我正在尝试通过这样做在 product_templte_form_vieew 中添加自定义字段:

<!-- product template -->
<record id="mymoduleproduct_view_form" model="ir.ui.view">
    <field name="name">mymodule.product</field>
    <field name="model">mymodule.product</field>
    <field name="inherit_id" ref="product.product_template_form_view"/>
    <field name="arch" type="xml">
        <xpath expr="//notebook/page[@name='general_information']/group[2]" position="attributes">
            <field name="prixass"/>
            <field name="taxes_id" position="attributes">
                <attribute name="invisible">1</attribute>
            </field>  
        </xpath>
    </field>
</record>

执行没有错误,但是好像不行。需要帮助来检测或纠正错误。

我已经像这样定义了“prixass”字段:

class MyModuleProduct(models.Model):
    _name = "mymodule.product"
    _description = "table des articles"
    _inherit = "product.template"

    prixass = fields.Float(string='Prix Assurance')
    taxes_id = fields.Many2many('account.tax', 'product_hospi_taxes', 'prod_hospi_id', 'tax_id', string='Customer Taxes')
    supplier_taxes_id = fields.Many2many('account.tax', 'product_hospi_supplier_taxes', 'prod_hospi_id', 'tax_id', string='Vendor Taxes')
    route_ids = fields.Many2many('stock.location.route', 'stock_route_product_hospi', 'product_hospi_id', 'route_id', string='Routes',)

我还想从视图中删除字段 taxes_id,我该怎么做?

。 the resume of the question in image here

谢谢。

试试这个。

class MyModuleProduct(models.Model):
    _inherit = "product.template"

    prixass = fields.Float(string='Prix Assurance')
    taxes_id = fields.Many2many('account.tax', 'product_hospi_taxes', 'prod_hospi_id', 'tax_id', string='Customer Taxes')
    supplier_taxes_id = fields.Many2many('account.tax', 'product_hospi_supplier_taxes', 'prod_hospi_id', 'tax_id', string='Vendor Taxes')
    route_ids = fields.Many2many('stock.location.route', 'stock_route_product_hospi', 'product_hospi_id', 'route_id', string='Routes',)

<record id="product_inherit_view" model="ir.ui.view">
    <field name="name">product.template</field>
    <field name="model">product.template</field>
    <field name="inherit_id" ref="product.product_template_form_view"/>
    <field name="arch" type="xml">
        <xpath expr="//notebook/page[@name='general_information']/field[@name='default_code']" position="after">
            <field name="prixass"/>
        </xpath>
        <field name="taxes_id" position="replace">
                <field name="taxes_id" invisible="1"/>
            </field>  
    </field>
</record>

但这现在对我有用

//model
class MyModuleProduct(models.Model):
    _inherit = "product.template"

    prixass = fields.Float(string='Prix Assurance')
    taxes_id = fields.Many2many('account.tax', 'product_hospi_taxes', 'prod_hospi_id', 'tax_id', string='Customer Taxes')
    supplier_taxes_id = fields.Many2many('account.tax', 'product_hospi_supplier_taxes', 'prod_hospi_id', 'tax_id', string='Vendor Taxes')
    route_ids = fields.Many2many('stock.location.route', 'stock_route_product_hospi', 'product_hospi_id', 'route_id', string='Routes',)


//views
<record id="product_inherit_view" model="ir.ui.view">
    <field name="name">product.template</field>
    <field name="model">product.template</field>
    <field name="inherit_id" ref="product.product_template_form_view"/>
    <field name="arch" type="xml">
        <xpath expr="//notebook/page[@name='general_information']/group[1]" position="after">
            <group>
                <field name="prixass"/>
            </group>
        </xpath>
        <field name="taxes_id" position="replace">
            <field name="taxes_id" invisible="1"/>
        </field> 
</record>

谢谢。