Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def check_value(self, value):
if value:
if not isinstance(value, list) \
and not isinstance(value, Model) \
and not isinstance(value, IncrementalRecords):
raise ValueError(
"The value supplied has to be a list, a recordset "
"or 'False'")
return super(Many2many, self).check_value(value)
except TypeError:
records = [records]
parent = self._from_record[0]
field = self._from_record[1]
updated_values = parent._values_to_write[field.name]
values = []
if updated_values.get(parent.id):
values = updated_values[parent.id][:] # Copy
from odoorpc import fields
for id_ in fields.records2ids(records):
if (3, id_) in values:
values.remove((3, id_))
if (4, id_) not in values:
values.append((4, id_))
return IncrementalRecords(values)
def check_value(self, value):
if value:
if (
not isinstance(value, list)
and not isinstance(value, Model)
and not isinstance(value, IncrementalRecords)
):
raise ValueError(
"The value supplied has to be a list, a recordset "
"or 'False'"
)
return super(Many2many, self).check_value(value)
def __set__(self, instance, value):
value = self.check_value(value)
if isinstance(value, IncrementalRecords):
value = value.tuples
else:
if value and not odoo_tuple_in(value):
value = [(6, 0, records2ids(value))]
elif not value:
value = [(5, )]
instance._values_to_write[self.name][instance.id] = value
super(Many2many, self).__set__(instance, value)
list(records)
except TypeError:
records = [records]
parent = self._from_record[0]
field = self._from_record[1]
updated_values = parent._values_to_write[field.name]
values = []
if updated_values.get(parent.id):
values = updated_values[parent.id][:] # Copy
from odoorpc import fields
for id_ in fields.records2ids(records):
if (3, id_) in values:
values.remove((3, id_))
if (4, id_) not in values:
values.append((4, id_))
return IncrementalRecords(values)