Skip to Content
Menu
This question has been flagged
2 Replies
4099 Views

I have some strange behavior when I inherit the sales order form view into my model/view.

I inherited the view into my model without changing the original view.

---

<record id="work_order_form" model="ir.ui.view">
        <field name="name">Extend the Sale Order</field>
        <field name="model">sale.order</field>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <field name="mode">primary</field>
        <field name="arch" type="xml">

            <field name="payment_term_id" position="after">
                <field name='my_field'/>
            </field>

        </field>
    </record>

---

Therefore I used the primary field (see my code) and I get what I want. Well...

My new view shows the extended field (my_field) and the sales order form view does not, as it should.


Within the sales module so, if I open a quotation, I can see that the quotation form also have the additional field (my_field). But if I am correct both (sales order & quotations use the same view i.e. sale.order.form)


For some reason quotations now also use the extended view.

Some of the code for completeness:

---

To open the view I added:

 <!-- Action to open the Workorder list -->
    <act_window id="action_yacht_service" name="Workorders"
                res_model="sale.order" view_mode="tree,form"/>

    <!-- Menu item to open the Workorder list -->
    <menuitem id="menu_yacht_service" name="Workorder"
              parent="menu_yachtservice" action="action_yacht_service" sequence="2"/>

---

code to inherit the model:

from odoo import fields, models


class YachtService(models.Model):
    _name = 'yacht.service'
    _description = 'Workorder Data'

    name = fields.Char(string="Name")
    description = fields.Text(string="Description")
    cost = fields.Float(string="Cost")



class WorkorderInheritSale(models.Model):
    _inherit = 'sale.order'

   my_field = fields.Boolean(string="Is Workorder")
   my_field_2 = fields.Boolean(string="Is Platzhalter 2")

Really confusing, pls help.


Avatar
Discard
Best Answer

hello Kai Brossmann,
you need to give  proper xpath for inheriting base view of sale order and give the right external id (including right base module)

Hope this clarify your query..

Avatar
Discard
Author

Thank you for your answer, is there any way to achieve this without xpath? I tried also a different attempt (see my 2nd post) but that seems to be a different issue altogether.

Author Best Answer

I think, I still haven't gotten my head around the view inheritance. I did more research and from what I can read inheritance delegation is used for what I have in mind. I.e. to create a new model based on an existing one, use the features it already has but also add some additional ones.  We use customized Workorders for our repairs but also the standard sales orders for retail etc.

So I tried _inherits and it looked very promising in the beginning.

class YachtService(models.Model):
    _name = 'yacht.service'
    _description = 'Workorder Data'
    _inherits = {'sale.order': 'partner_id'}
    partner_id = fields.Many2one(
        'sale.order',
        ondelete='cascade', required='false', string='Customer')

    my_field_2 = fields.Boolean(string="Is MyField 2")

My view looks like this:

<record id="work_order_form" model="ir.ui.view">
        <field name="name">workorder.form</field>
        <field name="model">yacht.service</field>
        <field name="inherit_id" ref="sale.view_order_form"/> 
        <field name="arch" type="xml">

            <field name="payment_term_id" position="after">
                <field name='my_field_2'/>
            </field>
        </field>
    </record>

Now when starting the model the form appears just like I want it to. The original sale.order.form is not modified, just like it should, sweet....

But the moment I enter data into the customer field (partner_id) I get the following error.

Error:
Odoo Server Error

Traceback (most recent call last):
>
>
>
    raise ValueError("Invalid field %r in leaf %r" % (left, str(leaf)))
ValueError: Invalid field 'customer' in leaf "<osv.ExtendedLeaf: ('customer', '=', True) on sale_order (ctx: )>"

I seem so close but now I have now idea where to pick up the tread..



Avatar
Discard