From 2d450ad4372739fbdd127ed0346dfb07e20b2ae2 Mon Sep 17 00:00:00 2001 From: Maxime Chambreuil Date: Wed, 27 Mar 2019 16:21:06 -0600 Subject: [PATCH] [FIX] agreement: dynamic field computation --- agreement/models/agreement.py | 21 +++++++++++---------- agreement/models/agreement_appendix.py | 21 +++++++++++---------- agreement/models/agreement_clause.py | 21 +++++++++++---------- agreement/models/agreement_recital.py | 21 +++++++++++---------- agreement/models/agreement_section.py | 20 +++++++++----------- 5 files changed, 53 insertions(+), 51 deletions(-) diff --git a/agreement/models/agreement.py b/agreement/models/agreement.py index 1cf44a1f..37feb4b4 100644 --- a/agreement/models/agreement.py +++ b/agreement/models/agreement.py @@ -334,20 +334,21 @@ class Agreement(models.Model): for record in self: record.total_company_mrc = amount_total - @api.onchange('field_id') - def onchange_sub_object_id(self): - if self.field_id and self.field_id.relation: - self.sub_object_id = self.env['ir.model'].search( - [('model', '=', self.field_id.relation)])[0] - - @api.onchange('sub_model_object_field_id', 'default_value') + @api.onchange('field_id', 'sub_model_object_field_id', 'default_value') def onchange_copyvalue(self): - if self.field_id or self.default_value: + self.sub_object_id = False + self.copyvalue = False + self.sub_object_id = False + if self.field_id and not self.field_id.relation: self.copyvalue = "${object.%s or %s}" % \ (self.field_id.name, self.default_value or '\'\'') - if self.sub_model_object_field_id or self.default_value: - self.copyvalue = "${object.%s.%s or %s}" % \ + self.sub_model_object_field_id = False + if self.field_id and self.field_id.relation: + self.sub_object_id = self.env['ir.model'].search( + [('model', '=', self.field_id.relation)])[0] + if self.sub_model_object_field_id: + self.copyvalue = "${object.%s.%s or %s}" %\ (self.field_id.name, self.sub_model_object_field_id.name, self.default_value or '\'\'') diff --git a/agreement/models/agreement_appendix.py b/agreement/models/agreement_appendix.py index 0d3d2a55..a224d7a0 100644 --- a/agreement/models/agreement_appendix.py +++ b/agreement/models/agreement_appendix.py @@ -49,20 +49,21 @@ class AgreementAppendix(models.Model): help="""Final placeholder expression, to be copy-pasted in the desired template field.""") - @api.onchange('field_id') - def onchange_sub_object_id(self): - if self.field_id and self.field_id.relation: - self.sub_object_id = self.env['ir.model'].search( - [('model', '=', self.field_id.relation)])[0] - - @api.onchange('sub_model_object_field_id', 'default_value') + @api.onchange('field_id', 'sub_model_object_field_id', 'default_value') def onchange_copyvalue(self): - if self.field_id or self.default_value: + self.sub_object_id = False + self.copyvalue = False + self.sub_object_id = False + if self.field_id and not self.field_id.relation: self.copyvalue = "${object.%s or %s}" % \ (self.field_id.name, self.default_value or '\'\'') - if self.sub_model_object_field_id or self.default_value: - self.copyvalue = "${object.%s.%s or %s}" % \ + self.sub_model_object_field_id = False + if self.field_id and self.field_id.relation: + self.sub_object_id = self.env['ir.model'].search( + [('model', '=', self.field_id.relation)])[0] + if self.sub_model_object_field_id: + self.copyvalue = "${object.%s.%s or %s}" %\ (self.field_id.name, self.sub_model_object_field_id.name, self.default_value or '\'\'') diff --git a/agreement/models/agreement_clause.py b/agreement/models/agreement_clause.py index 38e37ab6..84dbc19b 100644 --- a/agreement/models/agreement_clause.py +++ b/agreement/models/agreement_clause.py @@ -58,20 +58,21 @@ class AgreementClause(models.Model): help="""Final placeholder expression, to be copy-pasted in the desired template field.""") - @api.onchange('field_id') - def onchange_sub_object_id(self): - if self.field_id and self.field_id.relation: - self.sub_object_id = self.env['ir.model'].search( - [('model', '=', self.field_id.relation)])[0] - - @api.onchange('sub_model_object_field_id', 'default_value') + @api.onchange('field_id', 'sub_model_object_field_id', 'default_value') def onchange_copyvalue(self): - if self.field_id or self.default_value: + self.sub_object_id = False + self.copyvalue = False + self.sub_object_id = False + if self.field_id and not self.field_id.relation: self.copyvalue = "${object.%s or %s}" % \ (self.field_id.name, self.default_value or '\'\'') - if self.sub_model_object_field_id or self.default_value: - self.copyvalue = "${object.%s.%s or %s}" % \ + self.sub_model_object_field_id = False + if self.field_id and self.field_id.relation: + self.sub_object_id = self.env['ir.model'].search( + [('model', '=', self.field_id.relation)])[0] + if self.sub_model_object_field_id: + self.copyvalue = "${object.%s.%s or %s}" %\ (self.field_id.name, self.sub_model_object_field_id.name, self.default_value or '\'\'') diff --git a/agreement/models/agreement_recital.py b/agreement/models/agreement_recital.py index 4cc43db4..b10ea4a3 100644 --- a/agreement/models/agreement_recital.py +++ b/agreement/models/agreement_recital.py @@ -50,20 +50,21 @@ class AgreementRecital(models.Model): help="""Final placeholder expression, to be copy-pasted in the desired template field.""") - @api.onchange('field_id') - def onchange_sub_object_id(self): - if self.field_id and self.field_id.relation: - self.sub_object_id = self.env['ir.model'].search( - [('model', '=', self.field_id.relation)])[0] - - @api.onchange('sub_model_object_field_id', 'default_value') + @api.onchange('field_id', 'sub_model_object_field_id', 'default_value') def onchange_copyvalue(self): - if self.field_id or self.default_value: + self.sub_object_id = False + self.copyvalue = False + self.sub_object_id = False + if self.field_id and not self.field_id.relation: self.copyvalue = "${object.%s or %s}" % \ (self.field_id.name, self.default_value or '\'\'') - if self.sub_model_object_field_id or self.default_value: - self.copyvalue = "${object.%s.%s or %s}" % \ + self.sub_model_object_field_id = False + if self.field_id and self.field_id.relation: + self.sub_object_id = self.env['ir.model'].search( + [('model', '=', self.field_id.relation)])[0] + if self.sub_model_object_field_id: + self.copyvalue = "${object.%s.%s or %s}" %\ (self.field_id.name, self.sub_model_object_field_id.name, self.default_value or '\'\'') diff --git a/agreement/models/agreement_section.py b/agreement/models/agreement_section.py index 86e9db16..74e7ebba 100644 --- a/agreement/models/agreement_section.py +++ b/agreement/models/agreement_section.py @@ -49,22 +49,20 @@ class AgreementSection(models.Model): help="""Final placeholder expression, to be copy-pasted in the desired template field.""") - @api.onchange('field_id') - def onchange_sub_object_id(self): - if self.field_id and self.field_id.relation: - self.sub_object_id = self.env['ir.model'].search( - [('model', '=', self.field_id.relation)])[0] - else: - self.sub_object_id = False - - @api.onchange('field_id', 'sub_model_object_field_id', 'default_value') def onchange_copyvalue(self): - if self.field_id or self.default_value: + self.sub_object_id = False + self.copyvalue = False + self.sub_object_id = False + if self.field_id and not self.field_id.relation: self.copyvalue = "${object.%s or %s}" % \ (self.field_id.name, self.default_value or '\'\'') - if self.sub_model_object_field_id or self.default_value: + self.sub_model_object_field_id = False + if self.field_id and self.field_id.relation: + self.sub_object_id = self.env['ir.model'].search( + [('model', '=', self.field_id.relation)])[0] + if self.sub_model_object_field_id: self.copyvalue = "${object.%s.%s or %s}" %\ (self.field_id.name, self.sub_model_object_field_id.name,