I am setting up function in a wizard which will do following actions:
- Add new record and linked to current existing
Many2manyField. - Update record of current existing
Many2manyField. - Delete current existing
Many2manyField. Wizard model and Actual model having twoMany2manyfields customers_ids = fields.Many2many('res.partners', 'Customers')new_customers_ids = fields.Many2many('res.partners', 'New Customers')
In View Customers_ids are read only view where as new_customers_ids allowing add item (customer) and delete.
When I am adding new customers new_customers_ids from view but can't now updating customers_ids(Customers ids) via clicking button save on wizard.
How can add/ delete and update records from customers_ids via adding/ deleting and updating in new_customers_ids ?
@api.multi
def applychanges(self):
for record in self:
customers = []
new_customers = []
for customer in record.customers_ids:
customers.append(customer.id)
customers = list(set(customers))
for x in record.new_customers_ids:
new_customers.append(x.id)
new_customers = list(set(new_customers_ids))
record.customers_ids = [(1, 0, new_customers)]