Skip to Content
Menu
This question has been flagged
1 Reply
26621 Views

Hello,

I have a Many2many fields in sale order form, and I want that only that order line will show in many2many fields related to that sale order. So what domain I will use.

I have also made a field in order line name 'number' of char type in which when we create order line then the same sale order name is copied in 'number ' field. This field I have created  to make relationship between sale order and sale order line.

Code:

sale.py.

class SaleOrder(models.Model):

item_delivered_ids = fields.Many2many('sale.order.line',

'sale_order_sale_order_line_rel',

'sale_order_id',

'order_line_id',

string='Item Delivered')

class SaleOrderLine(models.Model):

    number = fields.Char(string='Order Number')

sale_view.xml:

<record id="view_sale_order_form_inherit" model="ir.ui.view">

<field name="name">sale.order.form.inherited</field>

<field name="model">sale.order</field>

<field name="inherit_id" ref="sale.view_order_form"/>

<field name="arch" type="xml">

    <xpath expr="//field[@name='partner_id']" position="after>

        <field name="item_delivered_ids" widget="many2many_tags" />

</xpath>

</field>

</record>

Thanks,


Avatar
Discard

Populate related values in a field on the change of many2one filed.

http://learnopenerp.blogspot.com/2016/10/onchange-many2one-filed-in-odoo.html

Best Answer

Hello Ramit,

Try below onchange method for adding domain and display only those sale order line which is related to particular sale order.


@api.onchange('item_delivered_ids')

def item_delivered_ids_onchange(self):

    return {'domain': {'item_delivered_ids': [('order_id', '=', self.id)]}}


Hope it will works for you.

Thanks,

Avatar
Discard

This won't work when the form is saved and then loaded again since when loading again the items didn't change..

Related Posts Replies Views Activity
1
Jun 18
13693
1
Mar 18
3349
0
Mar 18
1703
2
Oct 23
4743
3
Oct 23
4380