diff --git a/agreement_legal/models/__init__.py b/agreement_legal/models/__init__.py index bc1e26a6..0516d792 100644 --- a/agreement_legal/models/__init__.py +++ b/agreement_legal/models/__init__.py @@ -2,6 +2,7 @@ from . import res_config_settings from . import agreement_stage +from . import agreement_dynamic_content_mixin from . import agreement from . import agreement_appendix from . import agreement_clause diff --git a/agreement_legal/models/agreement.py b/agreement_legal/models/agreement.py index fcb1185e..05b616b4 100644 --- a/agreement_legal/models/agreement.py +++ b/agreement_legal/models/agreement.py @@ -9,7 +9,8 @@ class Agreement(models.Model): - _inherit = "agreement" + _name = "agreement" + _inherit = ["agreement", "agreement.dynamic.content.mixin"] name = fields.Char(string="Title", required=True) version = fields.Integer( @@ -226,34 +227,6 @@ def _get_default_parties(self): ) signed_contract_filename = fields.Char(string="Filename") signed_contract = fields.Binary(string="Signed Document", tracking=True) - field_id = fields.Many2one( - "ir.model.fields", - string="Field", - help="""You can select a target field from the related document model. - If it is a relationship field you will be able to select a target field - at the destination of the relationship.""", - ) - sub_object_id = fields.Many2one( - "ir.model", - string="Sub-model", - help="""When a relationship field is selected as first field, this - field shows the document model the relationship goes to.""", - ) - sub_model_object_field_id = fields.Many2one( - "ir.model.fields", - string="Sub-field", - help="""When a relationship field is selected as first field, this - field lets you select the target field within the destination document - model (sub-model).""", - ) - default_value = fields.Char( - help="Optional value to use if the target field is empty." - ) - copyvalue = fields.Char( - string="Placeholder Expression", - help="""Final placeholder expression, to be copy-pasted in the desired - template field.""", - ) template_id = fields.Many2one( "agreement", string="Template", domain=[("is_template", "=", True)] ) @@ -322,26 +295,6 @@ def _compute_dynamic_special_terms(self): )[agreement.id] agreement.dynamic_special_terms = special_terms - @api.onchange("field_id", "sub_model_object_field_id", "default_value") - def onchange_copyvalue(self): - self.sub_object_id = False - self.copyvalue = False - if self.field_id and not self.field_id.relation: - self.copyvalue = "{{{{object.{} or {}}}}}".format( - self.field_id.name, self.default_value or "''" - ) - 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.{}.{} or {}}}}}".format( - self.field_id.name, - self.sub_model_object_field_id.name, - self.default_value or "''", - ) - # Used for Kanban grouped_by view @api.model def _read_group_stage_ids(self, stages, domain, order=None): diff --git a/agreement_legal/models/agreement_appendix.py b/agreement_legal/models/agreement_appendix.py index f2aab358..ab1aeed1 100644 --- a/agreement_legal/models/agreement_appendix.py +++ b/agreement_legal/models/agreement_appendix.py @@ -1,11 +1,12 @@ # Copyright (C) 2018 - TODAY, Pavlov Media # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, fields, models +from odoo import fields, models class AgreementAppendix(models.Model): _name = "agreement.appendix" + _inherit = ["agreement.dynamic.content.mixin"] _description = "Agreement Appendices" _order = "sequence" @@ -25,56 +26,6 @@ class AgreementAppendix(models.Model): "removing it.", ) - # Dynamic field editor - field_id = fields.Many2one( - "ir.model.fields", - string="Field", - help="""Select target field from the related document model. If it is a - relationship field you will be able to select a target field at the - destination of the relationship.""", - ) - sub_object_id = fields.Many2one( - "ir.model", - string="Sub-model", - help="""When a relationship field is selected as first field, this - field shows the document model the relationship goes to.""", - ) - sub_model_object_field_id = fields.Many2one( - "ir.model.fields", - string="Sub-field", - help="""When a relationship field is selected as first field, this - field lets you select the target field within the destination document - model (sub-model).""", - ) - default_value = fields.Char( - help="Optional value to use if the target field is empty." - ) - copyvalue = fields.Char( - string="Placeholder Expression", - help="""Final placeholder expression, to be copy-pasted in the desired - template field.""", - ) - - @api.onchange("field_id", "sub_model_object_field_id", "default_value") - def onchange_copyvalue(self): - self.sub_object_id = False - self.copyvalue = False - if self.field_id and not self.field_id.relation: - self.copyvalue = "{{{{object.{} or {}}}}}".format( - self.field_id.name, self.default_value or "''" - ) - 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.{}.{} or {}}}}}".format( - self.field_id.name, - self.sub_model_object_field_id.name, - self.default_value or "''", - ) - # compute the dynamic content for jinja expression def _compute_dynamic_content(self): MailTemplates = self.env["mail.template"] diff --git a/agreement_legal/models/agreement_clause.py b/agreement_legal/models/agreement_clause.py index 298b01b8..c275d9a3 100644 --- a/agreement_legal/models/agreement_clause.py +++ b/agreement_legal/models/agreement_clause.py @@ -1,11 +1,12 @@ # Copyright (C) 2018 - TODAY, Pavlov Media # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, fields, models +from odoo import fields, models class AgreementClause(models.Model): _name = "agreement.clause" + _inherit = ["agreement.dynamic.content.mixin"] _description = "Agreement Clauses" _order = "sequence" @@ -29,56 +30,6 @@ class AgreementClause(models.Model): "removing it.", ) - # Dynamic field editor - field_id = fields.Many2one( - "ir.model.fields", - string="Field", - help="""Select target field from the related document model. If it is a - relationship field you will be able to select a target field at the - destination of the relationship.""", - ) - sub_object_id = fields.Many2one( - "ir.model", - string="Sub-model", - help="""When a relationship field is selected as first field, this - field shows the document model the relationship goes to.""", - ) - sub_model_object_field_id = fields.Many2one( - "ir.model.fields", - string="Sub-field", - help="""When a relationship field is selected as first field, this - field lets you select the target field within the destination document - model (sub-model).""", - ) - default_value = fields.Char( - help="Optional value to use if the target field is empty." - ) - copyvalue = fields.Char( - string="Placeholder Expression", - help="""Final placeholder expression, to be copy-pasted in the desired - template field.""", - ) - - @api.onchange("field_id", "sub_model_object_field_id", "default_value") - def onchange_copyvalue(self): - self.sub_object_id = False - self.copyvalue = False - if self.field_id and not self.field_id.relation: - self.copyvalue = "{{{{object.{} or {}}}}}".format( - self.field_id.name, self.default_value or "''" - ) - 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.{}.{} or {}}}}}".format( - self.field_id.name, - self.sub_model_object_field_id.name, - self.default_value or "''", - ) - # compute the dynamic content for jinja expression def _compute_dynamic_content(self): MailTemplates = self.env["mail.template"] diff --git a/agreement_legal/models/agreement_dynamic_content_mixin.py b/agreement_legal/models/agreement_dynamic_content_mixin.py new file mode 100644 index 00000000..312faf82 --- /dev/null +++ b/agreement_legal/models/agreement_dynamic_content_mixin.py @@ -0,0 +1,55 @@ +from odoo import api, fields, models + + +class AgreementDynamicContentMixin(models.AbstractModel): + _name = "agreement.dynamic.content.mixin" + _description = "Agreement Dynamic Content Mixin" + + field_id = fields.Many2one( + "ir.model.fields", + string="Field", + help="""Select target field from the related document model. If it is a + relationship field you will be able to select a target field at the + destination of the relationship.""", + ) + sub_object_id = fields.Many2one( + "ir.model", + string="Sub-model", + help="""When a relationship field is selected as first field, this + field shows the document model the relationship goes to.""", + ) + sub_model_object_field_id = fields.Many2one( + "ir.model.fields", + string="Sub-field", + help="""When a relationship field is selected as first field, this + field lets you select the target field within the destination document + model (sub-model).""", + ) + default_value = fields.Char( + help="Optional value to use if the target field is empty." + ) + copyvalue = fields.Char( + string="Placeholder Expression", + help="""Final placeholder expression, to be copy-pasted in the desired + template field.""", + ) + + @api.onchange("field_id", "sub_model_object_field_id", "default_value") + def onchange_copyvalue(self): + self.sub_object_id = False + self.copyvalue = False + if self.field_id and not self.field_id.relation: + self.copyvalue = "{{{{object.{} or {}}}}}".format( + self.field_id.name, self.default_value or "''" + ) + 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.{}.{} or {}}}}}".format( + self.field_id.name, + self.sub_model_object_field_id.name, + self.default_value or "''", + ) diff --git a/agreement_legal/models/agreement_recital.py b/agreement_legal/models/agreement_recital.py index ba17e9e2..1ab62495 100644 --- a/agreement_legal/models/agreement_recital.py +++ b/agreement_legal/models/agreement_recital.py @@ -1,11 +1,12 @@ # Copyright (C) 2018 - TODAY, Pavlov Media # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, fields, models +from odoo import fields, models class AgreementRecital(models.Model): _name = "agreement.recital" + _inherit = ["agreement.dynamic.content.mixin"] _description = "Agreement Recitals" _order = "sequence" @@ -23,56 +24,6 @@ class AgreementRecital(models.Model): "removing it.", ) - # Dynamic field editor - field_id = fields.Many2one( - "ir.model.fields", - string="Field", - help="""Select target field from the related document model. If it is a - relationship field you will be able to select a target field at the - destination of the relationship.""", - ) - sub_object_id = fields.Many2one( - "ir.model", - string="Sub-model", - help="""When a relationship field is selected as first field, this - field shows the document model the relationship goes to.""", - ) - sub_model_object_field_id = fields.Many2one( - "ir.model.fields", - string="Sub-field", - help="""When a relationship field is selected as first field, this - field lets you select the target field within the destination document - model (sub-model).""", - ) - default_value = fields.Char( - help="Optional value to use if the target field is empty." - ) - copyvalue = fields.Char( - string="Placeholder Expression", - help="""Final placeholder expression, to be copy-pasted in the desired - template field.""", - ) - - @api.onchange("field_id", "sub_model_object_field_id", "default_value") - def onchange_copyvalue(self): - self.sub_object_id = False - self.copyvalue = False - if self.field_id and not self.field_id.relation: - self.copyvalue = "{{{{object.{} or {}}}}}".format( - self.field_id.name, self.default_value or "''" - ) - 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.{}.{} or {}}}}}".format( - self.field_id.name, - self.sub_model_object_field_id.name, - self.default_value or "''", - ) - # compute the dynamic content for jinja expression def _compute_dynamic_content(self): MailTemplates = self.env["mail.template"] diff --git a/agreement_legal/models/agreement_section.py b/agreement_legal/models/agreement_section.py index 0ae3eafe..f1d54b88 100644 --- a/agreement_legal/models/agreement_section.py +++ b/agreement_legal/models/agreement_section.py @@ -1,11 +1,12 @@ # Copyright (C) 2018 - TODAY, Pavlov Media # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, fields, models +from odoo import fields, models class AgreementSection(models.Model): _name = "agreement.section" + _inherit = ["agreement.dynamic.content.mixin"] _description = "Agreement Sections" _order = "sequence" @@ -26,56 +27,6 @@ class AgreementSection(models.Model): "removing it.", ) - # Dynamic field editor - field_id = fields.Many2one( - "ir.model.fields", - string="Field", - help="""Select target field from the related document model. If it is a - relationship field you will be able to select a target field at the - destination of the relationship.""", - ) - sub_object_id = fields.Many2one( - "ir.model", - string="Sub-model", - help="""When a relationship field is selected as first field, this - field shows the document model the relationship goes to.""", - ) - sub_model_object_field_id = fields.Many2one( - "ir.model.fields", - string="Sub-field", - help="""When a relationship field is selected as first field, this - field lets you select the target field within the destination document - model (sub-model).""", - ) - default_value = fields.Char( - help="Optional value to use if the target field is empty." - ) - copyvalue = fields.Char( - string="Placeholder Expression", - help="""Final placeholder expression, to be copy-pasted in the desired - template field.""", - ) - - @api.onchange("field_id", "sub_model_object_field_id", "default_value") - def onchange_copyvalue(self): - self.sub_object_id = False - self.copyvalue = False - if self.field_id and not self.field_id.relation: - self.copyvalue = "{{{{object.{} or {}}}}}".format( - self.field_id.name, self.default_value or "''" - ) - 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.{}.{} or {}}}}}".format( - self.field_id.name, - self.sub_model_object_field_id.name, - self.default_value or "''", - ) - # compute the dynamic content for jinja expression def _compute_dynamic_content(self): MailTemplates = self.env["mail.template"]