i am new in odoo development.i have to create new xml file for inherited model,and also need to add some extra fields.
how can i do it?anyone help me please
i tried below program, but i didn't get inherited model ,only creating new model.when adding model name stock.picking in xml model name i got inherited model but my new field are not there.really ,i don't know how exactly do this.
.py file is
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 file is
<?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"/>
CodePudding user response:
_inherit
and _name
attributes are the same, Odoo will create a new model
, check Classical inheritance documentation for more details:
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.
To Extend stock.picking
in-place (add features), do not provide the _name
then inherit the stock picking views to add the new fields.
Example
Inherit stock.picking
in-place:
class StockPicking(models.Model):
_inherit = 'stock.picking'
nf_date = fields.Date(string="Loading Date")
Extend stock.picking
tree view:
<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>
Extend stock.picking
form view:
<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>