Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agreement_legal/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 2 additions & 49 deletions agreement_legal/models/agreement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)]
)
Expand Down Expand Up @@ -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):
Expand Down
53 changes: 2 additions & 51 deletions agreement_legal/models/agreement_appendix.py
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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"]
Expand Down
53 changes: 2 additions & 51 deletions agreement_legal/models/agreement_clause.py
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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"]
Expand Down
55 changes: 55 additions & 0 deletions agreement_legal/models/agreement_dynamic_content_mixin.py
Original file line number Diff line number Diff line change
@@ -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 "''",
)
53 changes: 2 additions & 51 deletions agreement_legal/models/agreement_recital.py
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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"]
Expand Down
Loading