Skip to content
Snippets Groups Projects
Commit 0df9d54510ca authored by Brendan Masson's avatar Brendan Masson
Browse files

Change data integrity logic + Allow CRUD calls with custom args

parent 37e93d7f1a8f
No related branches found
No related tags found
No related merge requests found
......@@ -182,45 +182,13 @@
return res
@AddMethod(superclass)
@api.cr_uid_ids_context
def unlink(self, cr, uid, ids, context=None):
"""When removing this object, remove all associated analytic
codes referenced by this object.
Note: the method will fail if the code is referenced by any other
object due to the RESTRICT constraint. That is the intended
behavior.
"""
analytic_obj = self.pool['analytic.structure']
code_obj = self.pool['analytic.code']
# Gather analytic values
analytic_values = []
for record in self.browse(cr, uid, ids, context=context):
for prefix, struct in analytic.iteritems():
values = analytic_obj.extract_values(
cr, uid, record, struct,
prefix=prefix, context=context
)
analytic_values.append(values)
# Find all related codes
code_ids = []
for values in analytic_values:
filtered_code_ids = filter(None, values.values())
code_ids.extend(filtered_code_ids)
# Set analytic fields to null
if analytic_values:
# The keys are all the same
fields = analytic_values[0].keys()
vals = {field: False for field in fields}
self.write(cr, uid, ids, vals)
code_obj.unlink(cr, uid, code_ids, context=context)
res = super(superclass, self).unlink(
cr, uid, ids, context=context
)
@api.model
@api.returns(orm_name, lambda value: value.id)
def create(self, vals, **kwargs):
"""Performs analytic field validation"""
res = super(superclass, self).create(vals, **kwargs)
# Throws in case of error
res._validate_analytic_fields(frozendict(analytic))
return res
@AddMethod(superclass)
......@@ -224,7 +192,6 @@
return res
@AddMethod(superclass)
@api.cr_uid_context
@api.returns(orm_name)
def create(self, cr, uid, vals, context=None):
@api.multi
def write(self, vals, **kwargs):
"""Performs analytic field validation"""
......@@ -230,5 +197,3 @@
"""Performs analytic field validation"""
res = super(superclass, self).create(
cr, uid, vals, context=context
)
res = super(superclass, self).write(vals, **kwargs)
# Throws in case of error
......@@ -234,6 +199,5 @@
# Throws in case of error
self._validate_analytic_fields(cr, uid, res, frozendict(analytic))
self._validate_analytic_fields(frozendict(analytic))
return res
@AddMethod(superclass)
......@@ -237,21 +201,8 @@
return res
@AddMethod(superclass)
@api.cr_uid_ids_context
def write(self, cr, uid, ids, vals, context=None):
"""Performs analytic field validation"""
res = super(superclass, self).write(
cr, uid, ids, vals, context=context
)
# Throws in case of error
self._validate_analytic_fields(cr, uid, ids, frozendict(analytic))
return res
@AddMethod(superclass)
@api.cr_uid_ids_context
def _validate_analytic_fields(self, cr, uid, ids, analytic,
context=None):
@api.multi
def _validate_analytic_fields(self, analytic):
"""Validation function to validate analytic fields.
The base implementation doesn't actually do anything.
:param analytic: frozendict, analytic field parameters, such as
......@@ -448,8 +399,8 @@
@AddMethod(superclass)
@api.cr_uid_context
@api.returns(orm_name)
def create(self, cr, uid, vals, context=None):
@api.returns(orm_name, lambda a: a.id)
def create(self, cr, uid, vals, context=None, **kwargs):
"""Create the analytic code."""
code_vals = {}
......@@ -492,7 +443,7 @@
new_code_id = code_id
res = super(superclass, self).create(
cr, uid, vals, context=context
cr, uid, vals, context=context, **kwargs
)
if code_ref_ids:
......@@ -507,7 +458,7 @@
@AddMethod(superclass)
@api.cr_uid_ids_context
def write(self, cr, uid, ids, vals, context=None):
def write(self, cr, uid, ids, vals, context=None, **kwargs):
"""Update the analytic code's name if it is not inherited,
and its parent code if parent-child relations are synchronized.
"""
......@@ -559,7 +510,7 @@
)
res = super(superclass, self).write(
cr, uid, ids, vals, context=context
cr, uid, ids, vals, context=context, **kwargs
)
if code_ref_ids and new is not False:
......@@ -569,7 +520,7 @@
@AddMethod(superclass)
@api.cr_uid_ids_context
def unlink(self, cr, uid, ids, context=None):
def unlink(self, cr, uid, ids, context=None, **kwargs):
"""When removing this object, remove all associated analytic
codes referenced by this object.
Note: the method will fail if the code is referenced by any other
......@@ -588,8 +539,7 @@
cr, uid, ids, context=context
)
# self.write(cr, uid, ids, {column: False}, context=context)
code_obj.unlink(cr, uid, code_ids, context=context)
code_obj.unlink(cr, uid, code_ids, context=context, **kwargs)
return res
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment