Skip to content
Snippets Groups Projects

View fixes, bound dimension fixes, code QoL

Merged Houzefa Abbasbhay requested to merge topic/16.0/zouzou into branch/16.0
2 files
+ 69
59
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 67
59
@@ -189,5 +189,5 @@
@AddMethod(superclass)
@api.model_create_multi
@api.returns(orm_name, lambda value: value.id)
def create(self, vals_list, **kwargs):
def create(self, vals_list):
"""Performs analytic field validation"""
@@ -193,7 +193,7 @@
"""Performs analytic field validation"""
res = super(superclass, self).create(vals_list, **kwargs)
res = super(superclass, self).create(vals_list)
# Throws in case of error
res._validate_analytic_fields(frozendict(analytic))
return res
@AddMethod(superclass)
@@ -195,7 +195,7 @@
# Throws in case of error
res._validate_analytic_fields(frozendict(analytic))
return res
@AddMethod(superclass)
def write(self, vals, **kwargs):
def write(self, vals):
"""Performs analytic field validation"""
@@ -201,5 +201,5 @@
"""Performs analytic field validation"""
res = super(superclass, self).write(vals, **kwargs)
res = super(superclass, self).write(vals)
# Throws in case of error
self._validate_analytic_fields(frozendict(analytic))
return res
@@ -248,6 +248,8 @@
code_name = dimension.get("code_name", "name")
code_description = dimension.get("code_description", "description")
if code_description not in nmspc:
code_description = code_name # Easier for auto-dimensions when no descr.
# To use an inherited, renamed parent field, you have to give its name.
sync_parent = dimension.get("sync_parent", False)
@@ -460,5 +462,5 @@
return new_code, vals
@AddMethod(superclass)
@api.model
@api.model_create_multi
@api.returns(orm_name, lambda value: value.id)
@@ -464,3 +466,3 @@
@api.returns(orm_name, lambda value: value.id)
def create(self, vals, **kwargs):
def create(self, vals_list):
"""Create the analytic code."""
@@ -466,13 +468,5 @@
"""Create the analytic code."""
context = self.env.context
code_vals = {}
if sync_parent:
parent_code = self._get_code_parent(vals)
if parent_code is not None and parent_code:
code_vals["code_parent_id"] = parent_code.id
# Direct changes to the 'bound analytic code' field are ignored
# unless the 'force_code_id' context key is passed as True.
force_code_id = vals.pop(column, False)
new_records = None
for vals in vals_list:
code_vals = {}
@@ -478,26 +472,6 @@
# Will be set if a new code is created
new_code = False
if context and context.get("force_code_id", False):
self._force_code(force_code_id, code_vals)
vals[column] = force_code_id
else:
new_code, vals = self._create_analytic_code(vals, code_vals)
res = super(superclass, self).create(vals, **kwargs)
# update code_description in case it is a computed field
if (
new_code
and self._fields.get(code_description) in self.pool.field_computed
):
new_code.description = getattr(res, code_description)
if not getattr(res, column):
if sync_parent:
parent_code = self._get_code_parent(vals)
if parent_code is not None and parent_code:
code_vals["code_parent_id"] = parent_code.id
@@ -499,15 +473,31 @@
if sync_parent:
parent_code = self._get_code_parent(vals)
if parent_code is not None and parent_code:
code_vals["code_parent_id"] = parent_code.id
new_code, vals = self._create_analytic_code(
{
field: extract(getattr(res, field), field_data["type"])
for field, field_data in res.fields_get().items()
if field in (list(vals.keys()) + [code_name, code_description])
},
code_vals,
)
super(superclass, res).write({column: new_code.id})
# Will be set if a new code is created
new_code = False
# Direct changes to the 'bound analytic code' field are ignored
# unless the 'force_code_id' context key is passed as True.
force_code_id = vals.pop(column, False)
if self.env.context.get("force_code_id"):
self._force_code(force_code_id, code_vals)
vals[column] = force_code_id
else:
new_code, vals = self._create_analytic_code(vals, code_vals)
new_record = super(superclass, self).create([vals])
if new_records is None:
new_records = new_record
else:
new_records |= new_record
# update code_description in case it is a computed field
if (
new_code
and self._fields.get(code_description) in self.pool.field_computed
):
new_code.description = getattr(new_record, code_description)
@@ -513,4 +503,7 @@
if code_ref_ids:
self._generate_code_ref_id(res)
if not getattr(new_record, column):
if sync_parent:
parent_code = self._get_code_parent(vals)
if parent_code is not None and parent_code:
code_vals["code_parent_id"] = parent_code.id
@@ -516,5 +509,14 @@
if new_code:
# These are behind-the-scenes links so bypass security rules.
new_code.sudo().write({"origin_id": "{},{}".format(self._name, res.id)})
new_code, vals = self._create_analytic_code(
{
field: extract(
getattr(new_record, field), field_data["type"]
)
for field, field_data in new_record.fields_get().items()
if field
in (list(vals.keys()) + [code_name, code_description])
},
code_vals,
)
super(superclass, new_record).write({column: new_code.id})
@@ -520,4 +522,13 @@
return res
if code_ref_ids:
self._generate_code_ref_id(new_record)
if new_code:
# These are behind-the-scenes links so bypass security rules.
new_code.sudo().write(
{"origin_id": "{},{}".format(self._name, new_record.id)}
)
return new_records
@AddMethod(superclass)
@@ -522,6 +533,6 @@
@AddMethod(superclass)
def write(self, vals, **kwargs):
def write(self, vals):
"""Update the analytic code's name if it is not inherited,
and its parent code if parent-child relations are synchronized.
"""
@@ -525,8 +536,6 @@
"""Update the analytic code's name if it is not inherited,
and its parent code if parent-child relations are synchronized.
"""
context = self.env.context
code_vals = {}
news = []
standard_process = False
@@ -545,8 +554,7 @@
# Direct changes to the 'bound analytic code' field are ignored
# unless the 'force_code_id' context key is passed as True.
force_code_id = vals.pop(column, False)
if context and context.get("force_code_id", False):
if self.env.context.get("force_code_id"):
self._force_code(force_code_id, code_vals)
vals[column] = force_code_id
@@ -564,7 +572,7 @@
code_vals["description"] = vals[description_col]
standard_process = True
res = super(superclass, self).write(vals, **kwargs)
res = super(superclass, self).write(vals)
# If updating records with no code, create these.
if standard_process:
@@ -591,7 +599,7 @@
# rules.
rec_vals[column] = code_obj.sudo().create(rec_code_vals).id
super(superclass, rec).write(rec_vals, **kwargs)
super(superclass, rec).write(rec_vals)
elif rec_code_vals:
# These are behind-the-scenes links so bypass security
Loading