跳至内容
菜单
此问题已终结
1 回复
2138 查看

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).
形象
丢弃
最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
1
1月 23
4038
1
8月 21
9452
1
4月 17
5504
1
9月 15
4522
0
6月 15
4302