Kế thừa trong odoo cho ta các biện pháp can thiện sâu hơn vào hệ thống odoo như là thêm các trường cơ sở
Mục đích : Thêm 1 trường tên là mã vận chuyển vào trong sale
Các bước làm
thêm ở models :
from odoo import api,fields,models class Sale_Mavc(models.Model): _inherit = 'sale.order' mavc = fields.Char(string='Mã vận chuyển ',required = False)
Thêm ở views/inherit 2 file form_mavc.xml và index_mavc.xml
File form_mavc.xml :
<?xml version="1.0" encoding="utf-8"?> <odoo> <data> <!-- Inherit Form View to Modify it --> <record id="app1_inheritvc_form" model="ir.ui.view"> <field name="name">app1.inherit.sale.order</field> <field name="model">sale.order</field> <field name="inherit_id" ref="sale.view_order_form"/> <field name="arch" type="xml"> <field name="partner_id" position="after"> <field name="mavc"/> </field> </field> </record> </data> </odoo>
File index_mavc.xml
<?xml version="1.0" encoding="utf-8"?> <odoo> <data> <!-- Inherit Form View to Modify it --> <record id="app1_mavc" model="ir.ui.view"> <field name="name">app1.inheritvc_index</field> <field name="model">sale.order</field> <field name="inherit_id" ref="sale.view_quotation_tree_with_onboarding"/> <field name="arch" type="xml"> <field name="partner_id" position="after"> <field name="mavc"/> </field> </field> </record> </data> </odoo>
Ở bài viết tiếp theo mình sẽ hướng dẫn custom search cách search theo mã vận chuyển