diff --git a/agreement_legal/__manifest__.py b/agreement_legal/__manifest__.py index aae585b4..bbaee16d 100644 --- a/agreement_legal/__manifest__.py +++ b/agreement_legal/__manifest__.py @@ -35,6 +35,9 @@ "views/agreement.xml", "views/menu.xml", ], + 'qweb': [ + "static/src/xml/domain_widget_view.xml", + ], "post_init_hook": "post_init_agreement_legal", "application": True, "development_status": "Beta", diff --git a/agreement_legal/models/agreement.py b/agreement_legal/models/agreement.py index 65683254..fb5f1205 100644 --- a/agreement_legal/models/agreement.py +++ b/agreement_legal/models/agreement.py @@ -246,23 +246,10 @@ class Agreement(models.Model): signed_contract_filename = fields.Char(string="Filename") signed_contract = fields.Binary( string="Signed Document", track_visibility="always") - 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).""") + + # Dynamic field editor + field_domain = fields.Char(string='Field Expression', + default='[["active", "=", True]]') default_value = fields.Char( string="Default Value", help="Optional value to use if the target field is empty.") @@ -271,6 +258,17 @@ class Agreement(models.Model): help="""Final placeholder expression, to be copy-pasted in the desired template field.""") + @api.onchange("field_domain", "default_value") + def onchange_copyvalue(self): + self.copyvalue = False + if self.field_domain: + string_list = self.field_domain.split(",") + if string_list: + field_domain = string_list[0][3:-1] + self.copyvalue = "${{object.{} or {}}}".format( + field_domain, + self.default_value or "''") + # compute the dynamic content for mako expression @api.multi def _compute_dynamic_description(self): @@ -308,24 +306,6 @@ class Agreement(models.Model): ) 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 - self.sub_object_id = 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): diff --git a/agreement_legal/models/agreement_appendix.py b/agreement_legal/models/agreement_appendix.py index e81bd53c..5e7fe410 100644 --- a/agreement_legal/models/agreement_appendix.py +++ b/agreement_legal/models/agreement_appendix.py @@ -36,54 +36,26 @@ class AgreementAppendix(models.Model): ) # 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).""", - ) + field_domain = fields.Char(string='Field Expression', + default='[["active", "=", True]]') default_value = fields.Char( string="Default Value", - help="Optional value to use if the target field is empty.", - ) + 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 field.""") - @api.onchange('field_id', 'sub_model_object_field_id', 'default_value') + @api.onchange("field_domain", "default_value") def onchange_copyvalue(self): - 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 '\'\'') - 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 '\'\'') + if self.field_domain: + string_list = self.field_domain.split(",") + if string_list: + field_domain = string_list[0][3:-1] + self.copyvalue = "${{object.{} or {}}}".format( + field_domain, + self.default_value or "''") # compute the dynamic content for mako expression @api.multi diff --git a/agreement_legal/models/agreement_clause.py b/agreement_legal/models/agreement_clause.py index e7ab066f..02cbfc57 100644 --- a/agreement_legal/models/agreement_clause.py +++ b/agreement_legal/models/agreement_clause.py @@ -34,23 +34,8 @@ 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).""") + field_domain = fields.Char(string='Field Expression', + default='[["active", "=", True]]') default_value = fields.Char( string="Default Value", help="Optional value to use if the target field is empty.") @@ -59,24 +44,16 @@ class AgreementClause(models.Model): help="""Final placeholder expression, to be copy-pasted in the desired template field.""") - @api.onchange('field_id', 'sub_model_object_field_id', 'default_value') + @api.onchange("field_domain", "default_value") def onchange_copyvalue(self): - 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 '\'\'') - 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 '\'\'') + if self.field_domain: + string_list = self.field_domain.split(",") + if string_list: + field_domain = string_list[0][3:-1] + self.copyvalue = "${{object.{} or {}}}".format( + field_domain, + self.default_value or "''") # compute the dynamic content for mako expression @api.multi diff --git a/agreement_legal/models/agreement_recital.py b/agreement_legal/models/agreement_recital.py index 15b04517..74a814ce 100644 --- a/agreement_legal/models/agreement_recital.py +++ b/agreement_legal/models/agreement_recital.py @@ -12,76 +12,42 @@ class AgreementRecital(models.Model): name = fields.Char(string="Name", required=True) title = fields.Char( string="Title", - help="The title is displayed on the PDF." "The name is not.", - ) + help="The title is displayed on the PDF." "The name is not.") sequence = fields.Integer(string="Sequence", default=10) content = fields.Html(string="Content") dynamic_content = fields.Html( compute="_compute_dynamic_content", string="Dynamic Content", - help="compute dynamic Content", - ) + help="compute dynamic Content") agreement_id = fields.Many2one( - "agreement", string="Agreement", ondelete="cascade" - ) + "agreement", string="Agreement", ondelete="cascade") active = fields.Boolean( string="Active", default=True, help="If unchecked, it will allow you to hide this recital without " - "removing it.", - ) + "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).""", - ) + field_domain = fields.Char(string='Field Expression', + default='[["active", "=", True]]') default_value = fields.Char( string="Default Value", - help="Optional value to use if the target field is empty.", - ) + 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 field.""") - @api.onchange("field_id", "sub_model_object_field_id", "default_value") + @api.onchange("field_domain", "default_value") def onchange_copyvalue(self): - 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.{} 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 "''", - ) + if self.field_domain: + string_list = self.field_domain.split(",") + if string_list: + field_domain = string_list[0][3:-1] + self.copyvalue = "${{object.{} or {}}}".format( + field_domain, + self.default_value or "''") # compute the dynamic content for mako expression @api.multi @@ -91,9 +57,7 @@ class AgreementRecital(models.Model): lang = ( recital.agreement_id and recital.agreement_id.partner_id.lang - or "en_US" - ) + or "en_US") content = MailTemplates.with_context(lang=lang)._render_template( - recital.content, "agreement.recital", recital.id - ) + recital.content, "agreement.recital", recital.id) recital.dynamic_content = content diff --git a/agreement_legal/models/agreement_section.py b/agreement_legal/models/agreement_section.py index 2d9220df..4ac9f639 100644 --- a/agreement_legal/models/agreement_section.py +++ b/agreement_legal/models/agreement_section.py @@ -30,23 +30,8 @@ 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).""") + field_domain = fields.Char(string='Field Expression', + default='[["active", "=", True]]') default_value = fields.Char( string="Default Value", help="Optional value to use if the target field is empty.") @@ -55,25 +40,16 @@ class AgreementSection(models.Model): help="""Final placeholder expression, to be copy-pasted in the desired template field.""") - @api.onchange("field_id", "sub_model_object_field_id", "default_value") + @api.onchange("field_domain", "default_value") def onchange_copyvalue(self): - 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.{} 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 "''", - ) + if self.field_domain: + string_list = self.field_domain.split(",") + if string_list: + field_domain = string_list[0][3:-1] + self.copyvalue = "${{object.{} or {}}}".format( + field_domain, + self.default_value or "''") # compute the dynamic content for mako expression @api.multi diff --git a/agreement_legal/readme/USAGE.rst b/agreement_legal/readme/USAGE.rst index 7e899648..4030c158 100644 --- a/agreement_legal/readme/USAGE.rst +++ b/agreement_legal/readme/USAGE.rst @@ -5,3 +5,9 @@ To use this module: * Select a template * Follow the process to get the required approval * Send the invitation to the customer to review and sign the agreement + +* Define Field using widget domain but having partial_use option true: +* For Ex: +* diff --git a/agreement_legal/report/agreement.xml b/agreement_legal/report/agreement.xml index 6a621d0f..5688ae3e 100644 --- a/agreement_legal/report/agreement.xml +++ b/agreement_legal/report/agreement.xml @@ -93,7 +93,7 @@ - +

Special Terms

diff --git a/agreement_legal/static/src/js/domain_widget_ext.js b/agreement_legal/static/src/js/domain_widget_ext.js new file mode 100644 index 00000000..11da12f6 --- /dev/null +++ b/agreement_legal/static/src/js/domain_widget_ext.js @@ -0,0 +1,77 @@ +odoo.define('agreement_legal.domain_widget_ext', function (require) { + 'use strict'; + + var basic_fields = require('web.basic_fields'); + var DomainSelector = require('web.DomainSelector'); + var session = require('web.session'); + var core = require('web.core'); + var qweb = core.qweb; + var _t = core._t; + + basic_fields.FieldDomain.include({ + /** + * Init + */ + init : function () { + this._super.apply(this, arguments); + // Add Additional options + this.partialUse = this.nodeOptions.partial_use || false; + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @private + * @override _render from AbstractField + * @returns {Deferred} + */ + _render: function () { + // If there is no model, only change the non-domain-selector content + if (!this._domainModel) { + this._replaceContent(); + return $.when(); + } + + // Convert char value to array value + var value = this.value || "[]"; + + // Create the domain selector or change the value of the current one... + var def; + if (!this.domainSelector) { + this.domainSelector = new DomainSelector(this, this._domainModel, value, { + readonly: this.mode === "readonly" || this.inDialog, + filters: this.fsFilters, + debugMode: session.debug, + partialUse: this.partialUse || false, + }); + def = this.domainSelector.prependTo(this.$el); + } else { + def = this.domainSelector.setDomain(value); + } + // ... then replace the other content (matched records, etc) + return def.then(this._replaceContent.bind(this)); + }, + /** + * Render the field DOM except for the domain selector part. The full field + * DOM is composed of a DIV which contains the domain selector widget, + * followed by other content. This other content is handled by this method. + * + * @private + */ + _replaceContent: function () { + if (this._$content) { + this._$content.remove(); + } + this._$content = $(qweb.render("FieldDomain.content", { + hasModel: !!this._domainModel, + isValid: !!this._isValidForModel, + nbRecords: this.record.specialData[this.name].nbRecords || 0, + inDialogEdit: this.inDialog && this.mode === "edit", + partialUse: this.partialUse || false, + })); + this._$content.appendTo(this.$el); + }, + }); +}); diff --git a/agreement_legal/static/src/xml/domain_widget_view.xml b/agreement_legal/static/src/xml/domain_widget_view.xml new file mode 100644 index 00000000..580d1a2e --- /dev/null +++ b/agreement_legal/static/src/xml/domain_widget_view.xml @@ -0,0 +1,179 @@ + + + + +

+ +
+ + +
+ + + + Invalid domain + + +
+
Select a model to add a filter.
+
+ + +
+ + + SMatch all records + + + +
+ Please navigate below and select field: + + SSMatch records with + + of the following rules: + +
+ +
+ + + + + Match all records + + + +
+ Match records with the following rule: + + Match records with + + of the following rules: + +
+ +
+ + + + +
+ + + + + + + + +
+ + +
+ + +
+ +
+
+ + + + + +
+ + + +
+
+ +
+
+ + + +
+
+
+
+
+ + + + "" + + + + + "" + or + + + + + + + + is + not + set + +
+
+
+
+ +
+ +
+
+
+
+ +
+ +
+
+
    +
+ +
+
+ \ No newline at end of file diff --git a/agreement_legal/views/agreement.xml b/agreement_legal/views/agreement.xml index 3a7e3204..72774995 100644 --- a/agreement_legal/views/agreement.xml +++ b/agreement_legal/views/agreement.xml @@ -1,6 +1,14 @@ +