Skip to Content
Menu
This question has been flagged
3 Replies
8974 Views

hello everyone 

i have 2 many2many fields same object and give me same value (sale order of res.partner)


one field name is sale_ids

second field name is sale_orders

when i select res.partner sale_ids give me saleorder of selected res.partner 

now i want when i click save button i want same value in sale_orders 



what can i do?


thank you in advance

Avatar
Discard
Author

i solved by this code:-

def write(self,vals):
if self.sale_ids:

Author

def write(self,vals):

if self.sale_ids:
vals['sale_orders'] = [(6,0,self.sale_ids.ids)]

res = super(bookingschedual,self).write(vals)
return res

Best Answer

Hello Ra_one_1_11,


You can add sale_ids onchange to create a record or append to sale_orders.
Or add related in sale_order


for example: sale_orders = fields.Many2many("sale.order","booking_sale_rel","booking_id_rec","sale_id_rec",string="sale ids", related='sale_ids')

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard
Best Answer

Hi,

In your write function add as this:


def write
(self, vals):
for order in self.sale_ids:
self.sale_orders = [(4, [order.id])]
return super(BookingSchedule, self).write(vals)

For other options available with many2many field check this post: https://www.odoo.com/forum/help-1/many2many-write-replaces-all-existing-records-in-the-set-by-the-ids-148267

Thank you


Avatar
Discard
Author Best Answer

i can't get any value in my second many2many fields 


lass bookingschedual(models.Model):

_name = "booking.schedule"

partner_id = fields.Many2one("res.partner", string="Customer")

sale_ids = fields.Many2many("sale.order", "sale_order_rel", "booking_id", "sale_id", string="Sale order")

sale_orders = fields.Many2many("sale.order","booking_sale_rel","booking_id_rec","sale_id_rec",string="sale ids",)


this is my code :

when i select res.partner in partner_id field then i got value of his sale order in sale_ids field 

now i want same value in sale_orders fields when i click on the save button 


i guess you are understand 


Avatar
Discard
Related Posts Replies Views Activity
1
Dec 23
996
2
Aug 23
929
1
Dec 23
2068
1
Jul 23
1520
0
May 23
1283