Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
2153 Zobrazení

I use customized Workorders in my model but want to keep the base sales orders for retail etc.

So I used  _inherits in my model and it looked very promising i.e. in the beginning.


Here what I did...

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>

When opening my work_order_form view it all appears just like I want it to. As desired, the original sale.order.form is not modified, so far so good....


Here the problem:

In my new view, 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: )>"


To be honest, I don't even know where to start with this problem. From what I can read, it seemingly has something to do with the validity of the Many2One field (partner_ID).
Avatar
Zrušit
Nejlepší odpověď

Hi,

Partner_id is already a many2one field of res.partner as co-model in the sale.order model. So it is better is better to rename the field you have used here and give an another name.

class YachtService(models.Model):
_name = 'yacht.service'
_description = 'Workorder Data'
_inherits = {'sale.order': 'sale_order_id'}

sale_order_id = fields.Many2one('sale.order', ondelete='cascade', required='false', string='Sale Order')
my_field_2 = fields.Boolean(string="Is MyField 2")

Try with the above code and see. If you face any issue in installing again, uninstall this module once, upgrade the sales module and then install the custom module again.


Reference: Delegation Inheritance in Odoo


Thanks

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
led 23
4055
1
srp 21
9467
1
dub 17
5522
1
zář 15
4523
0
čvn 15
4308