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
+ 68
63
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 66
63
@@ -182,5 +182,5 @@
@@ -182,5 +182,5 @@
@AddMethod(superclass)
@AddMethod(superclass)
@api.model_create_multi
@api.model_create_multi
@api.returns(orm_name, lambda value: value.id)
@api.returns(orm_name, lambda value: value.id)
def create(self, vals_list, **kwargs):
def create(self, vals_list):
"""Performs analytic field validation"""
"""Performs analytic field validation"""
@@ -186,7 +186,7 @@
@@ -186,7 +186,7 @@
"""Performs analytic field validation"""
"""Performs analytic field validation"""
res = super(superclass, self).create(vals_list, **kwargs)
res = super(superclass, self).create(vals_list)
# Throws in case of error
# Throws in case of error
res._validate_analytic_fields(frozendict(analytic))
res._validate_analytic_fields(frozendict(analytic))
return res
return res
@AddMethod(superclass)
@AddMethod(superclass)
@@ -188,7 +188,7 @@
@@ -188,7 +188,7 @@
# Throws in case of error
# Throws in case of error
res._validate_analytic_fields(frozendict(analytic))
res._validate_analytic_fields(frozendict(analytic))
return res
return res
@AddMethod(superclass)
@AddMethod(superclass)
def write(self, vals, **kwargs):
def write(self, vals):
"""Performs analytic field validation"""
"""Performs analytic field validation"""
@@ -194,5 +194,5 @@
@@ -194,5 +194,5 @@
"""Performs analytic field validation"""
"""Performs analytic field validation"""
res = super(superclass, self).write(vals, **kwargs)
res = super(superclass, self).write(vals)
# Throws in case of error
# Throws in case of error
self._validate_analytic_fields(frozendict(analytic))
self._validate_analytic_fields(frozendict(analytic))
return res
return res
@@ -241,6 +241,8 @@
@@ -241,6 +241,8 @@
code_name = dimension.get("code_name", "name")
code_name = dimension.get("code_name", "name")
code_description = dimension.get("code_description", "description")
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.
# To use an inherited, renamed parent field, you have to give its name.
sync_parent = dimension.get("sync_parent", False)
sync_parent = dimension.get("sync_parent", False)
@@ -453,5 +455,5 @@
@@ -453,5 +455,5 @@
return new_code, vals
return new_code, vals
@AddMethod(superclass)
@AddMethod(superclass)
@api.model
@api.model_create_multi
@api.returns(orm_name, lambda value: value.id)
@api.returns(orm_name, lambda value: value.id)
@@ -457,3 +459,3 @@
@@ -457,3 +459,3 @@
@api.returns(orm_name, lambda value: value.id)
@api.returns(orm_name, lambda value: value.id)
def create(self, vals, **kwargs):
def create(self, vals_list):
"""Create the analytic code."""
"""Create the analytic code."""
@@ -459,37 +461,9 @@
@@ -459,37 +461,9 @@
"""Create the analytic code."""
"""Create the analytic code."""
context = self.env.context
new_records = None
code_vals = {}
for vals in vals_list:
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)
# 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:
if sync_parent:
parent_code = self._get_code_parent(vals)
parent_code = self._get_code_parent(vals)
if parent_code is not None and parent_code:
if parent_code is not None and parent_code:
code_vals["code_parent_id"] = parent_code.id
code_vals["code_parent_id"] = parent_code.id
@@ -492,5 +466,54 @@
@@ -492,5 +466,54 @@
if sync_parent:
if sync_parent:
parent_code = self._get_code_parent(vals)
parent_code = self._get_code_parent(vals)
if parent_code is not None and parent_code:
if parent_code is not None and parent_code:
code_vals["code_parent_id"] = parent_code.id
code_vals["code_parent_id"] = parent_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)
 
 
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
 
 
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})
 
 
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)})
@@ -496,21 +519,4 @@
@@ -496,21 +519,4 @@
new_code, vals = self._create_analytic_code(
return new_records
{
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})
if code_ref_ids:
self._generate_code_ref_id(res)
if new_code:
# These are behind-the-scenes links so bypass security rules.
new_code.sudo().write({"origin_id": "{},{}".format(self._name, res.id)})
return res
@AddMethod(superclass)
@AddMethod(superclass)
@@ -515,6 +521,6 @@
@@ -515,6 +521,6 @@
@AddMethod(superclass)
@AddMethod(superclass)
def write(self, vals, **kwargs):
def write(self, vals):
"""Update the analytic code's name if it is not inherited,
"""Update the analytic code's name if it is not inherited,
and its parent code if parent-child relations are synchronized.
and its parent code if parent-child relations are synchronized.
"""
"""
@@ -518,8 +524,6 @@
@@ -518,8 +524,6 @@
"""Update the analytic code's name if it is not inherited,
"""Update the analytic code's name if it is not inherited,
and its parent code if parent-child relations are synchronized.
and its parent code if parent-child relations are synchronized.
"""
"""
context = self.env.context
code_vals = {}
code_vals = {}
news = []
news = []
standard_process = False
standard_process = False
@@ -538,8 +542,7 @@
@@ -538,8 +542,7 @@
# Direct changes to the 'bound analytic code' field are ignored
# Direct changes to the 'bound analytic code' field are ignored
# unless the 'force_code_id' context key is passed as True.
# unless the 'force_code_id' context key is passed as True.
force_code_id = vals.pop(column, False)
force_code_id = vals.pop(column, False)
if self.env.context.get("force_code_id"):
if context and context.get("force_code_id", False):
self._force_code(force_code_id, code_vals)
self._force_code(force_code_id, code_vals)
vals[column] = force_code_id
vals[column] = force_code_id
@@ -557,7 +560,7 @@
@@ -557,7 +560,7 @@
code_vals["description"] = vals[description_col]
code_vals["description"] = vals[description_col]
standard_process = True
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 updating records with no code, create these.
if standard_process:
if standard_process:
@@ -584,7 +587,7 @@
@@ -584,7 +587,7 @@
# rules.
# rules.
rec_vals[column] = code_obj.sudo().create(rec_code_vals).id
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:
elif rec_code_vals:
# These are behind-the-scenes links so bypass security
# These are behind-the-scenes links so bypass security
Loading