继承模型并在 odoo 中为其创建新的 xml 文件

Inherit a model and create new xml file for it in odoo

我是 odoo 开发的新手。我必须为继承模型创建新的 xml 文件,并且还需要添加一些额外的字段

我该怎么做?有人帮我吗

我试过下面的程序,但我没有得到继承的模型,只创建新的 model.when 在 xml 模型名称中添加模型名称 stock.picking 我得到了继承的模型,但我的新模型字段不是 there.really,我不知道该怎么做。

.py 文件是

class LoadingChart(models.Model):
    _inherit = 'stock.picking'
    _name = 'loading.chart'
     _description = "Loading Chart"

    nf_date = fields.Date(string="Loading Date")
    nf_date1 = fields.Datetime(string="Date")
    nf_reference = fields.Char(string="Reference")
    nf_seq = fields.Char(string='Loading Sequence', required=True, copy=False, readonly=True,
                         index=True, default=lambda self: _('New'))

.xml 文件是

<?xml version='1.0' encoding='utf-8'?>
<odoo>
   
        <record model="ir.ui.view" id="nf_unloading_view">
        <field name="name">Loading.chart.tree</field>
        <field name="model">loading.chart</field>
        <field name="arch" type="xml">
            <tree>
                <field name="nf_date"/>
                <field name="nf_date1"/>
            </tree>
        </field>
    </record>

     <record id="stock_picking_form" model="ir.ui.view">
        <field name="name">stock.picking.form</field>
        <field name="model">loading.chart</field>
        <field name="arch" type="xml">
            <form>

                <sheet>
                    <div class='oe_title'>
                        <h1>
                            <field name="nf_seq" readonly="1"/>

                        </h1>
                    </div>
                    <group>
                        <group>
                             <field name="nf_date"/>
                             <field name="nf_date1"/>
                        </group>
                          <group>
                             <field name=" nf_reference"/>
                             
                        </group>
                    </group>

    <record model="ir.actions.act_window" id="loading_chart_action_window">
        <field name="name">loading Chart</field>
        <field name="res_model">loading.chart</field>
        <field name="view_mode">tree,form</field>
    </record>
    <!--*************************MENU*****************************************************-->

    <menuitem id="loading_chart_root_menu" name="Loading Chart"
              parent="stock.menu_stock_warehouse_mgmt" action="loading_chart_action_window" sequence="20"/>

_inherit_name 属性相同,Odoo 将创建一个新的 model,查看 Classical inheritance 文档了解更多详情:

When using the _inherit and _name attributes together, Odoo creates a new model using the existing one (provided via _inherit) as a base. The new model gets all the fields, methods and meta-information (defaults & al) from its base.

Extend stock.picking in-place (add features), do not provide the _name then inherit选股视图添加新字段。

例子

就地继承stock.picking

class StockPicking(models.Model):
    _inherit = 'stock.picking'

    nf_date = fields.Date(string="Loading Date")  

扩展 stock.picking 树视图:

<record id="stock_picking_tree" model="ir.ui.view">
    <field name="name">stock.picking.tree</field>
    <field name="model">stock.picking</field>
    <field name="inherit_id" ref="stock.vpicktree"/>
    <field name="arch" type="xml">
        <field name="scheduled_date" position="after">
            <field name="nf_date"/>
        </field>
    </field>
</record>

扩展 stock.picking 表单视图:

<record id="stock_picking_form" model="ir.ui.view">
    <field name="name">stock.picking.form</field>
    <field name="model">stock.picking</field>
    <field name="inherit_id" ref="stock.view_picking_form"/>
    <field name="arch" type="xml">
        <field name="date_deadline" position="after">
            <field name="nf_date"/>
        </field>
    </field>
</record>