diff --git a/mis_builder_pms/README.rst b/mis_builder_pms/README.rst new file mode 100644 index 000000000..e69de29bb diff --git a/mis_builder_pms/__init__.py b/mis_builder_pms/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/mis_builder_pms/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mis_builder_pms/__manifest__.py b/mis_builder_pms/__manifest__.py new file mode 100644 index 000000000..10436e7a8 --- /dev/null +++ b/mis_builder_pms/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2022 Comunitea Servicios Tecnológicos S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "MIS Builder with PMS Properties", + "summary": "Add property in mis builder", + "version": "14.0.1.0.0", + "development_status": "Beta", + "category": "Reporting", + "website": "https://github.com/OCA/pms", + "author": "Comunitea, Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "depends": ["mis_builder", "pms"], + "data": [ + "views/mis_builder_view.xml", + ], + "auto_install": True, +} diff --git a/mis_builder_pms/models/__init__.py b/mis_builder_pms/models/__init__.py new file mode 100644 index 000000000..d7e31d891 --- /dev/null +++ b/mis_builder_pms/models/__init__.py @@ -0,0 +1 @@ +from . import mis_builder diff --git a/mis_builder_pms/models/mis_builder.py b/mis_builder_pms/models/mis_builder.py new file mode 100644 index 000000000..f3ebbfa2a --- /dev/null +++ b/mis_builder_pms/models/mis_builder.py @@ -0,0 +1,60 @@ +# Copyright 2022 Comunitea Servicios Tecnológicos S.L. (https://comunitea.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import _, api, fields, models + + +class MisReportInstance(models.Model): + + _inherit = "mis.report.instance" + + pms_property_ids = fields.Many2many( + "pms.property", + string="PMS Properties", + ) + + def _add_analytic_filters_to_context(self, context): + super()._add_analytic_filters_to_context(context) + if self.pms_property_ids: + context["mis_report_filters"]["pms_property_id"] = { + "value": self.pms_property_ids.ids, + "operator": "in", + } + + @api.model + def get_filter_descriptions_from_context(self): + filter_descriptions = super().get_filter_descriptions_from_context() + filters = self.env.context.get("mis_report_filters", {}) + pms_property_value = filters.get("pms_property_id", {}).get("value") + if pms_property_value: + pms_properties = self.env["pms.property"].browse(pms_property_value) + filter_descriptions.append( + _("PMS Properties: %s") % ", ".join(pms_properties.mapped("name")) + ) + return filter_descriptions + + +class MisReportInstancePeriod(models.Model): + + _inherit = "mis.report.instance.period" + + pms_property_ids = fields.Many2many( + "pms.property", + string="PMS Properties", + ) + + def _get_additional_move_line_filter(self): + aml_domain = super()._get_additional_move_line_filter() + if self.report_instance_id.pms_property_ids: + aml_domain.append( + ( + "pms_property_id", + "in", + self.report_instance_id.pms_property_ids.ids, + ) + ) + if self.pms_property_ids: + aml_domain.append( + ("pms_property_id", "in", self.pms_property_ids.ids), + ) + return aml_domain diff --git a/mis_builder_pms/readme/CONTRIBUTORS.rst b/mis_builder_pms/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..35552577f --- /dev/null +++ b/mis_builder_pms/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Omar Castiñeira diff --git a/mis_builder_pms/readme/DESCRIPTION.rst b/mis_builder_pms/readme/DESCRIPTION.rst new file mode 100644 index 000000000..c3fb66239 --- /dev/null +++ b/mis_builder_pms/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Introduces the PMS property to MIS Builder report instances. diff --git a/mis_builder_pms/readme/USAGE.rst b/mis_builder_pms/readme/USAGE.rst new file mode 100644 index 000000000..fb7b007a2 --- /dev/null +++ b/mis_builder_pms/readme/USAGE.rst @@ -0,0 +1 @@ +Set the PMS property in a MIS Builder instance. diff --git a/mis_builder_pms/static/description/icon.png b/mis_builder_pms/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mis_builder_pms/static/description/icon.png differ diff --git a/mis_builder_pms/static/src/js/mis_report_widget.js b/mis_builder_pms/static/src/js/mis_report_widget.js new file mode 100644 index 000000000..c267ef39d --- /dev/null +++ b/mis_builder_pms/static/src/js/mis_report_widget.js @@ -0,0 +1,87 @@ +/* +Copyright 2022 Comunitea. +License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +*/ +odoo.define("mis_builder_widget_add_pms_properties", function (require) { + "use strict"; + + var core = require("web.core"); + var relational_fields = require("web.relational_fields"); + var MisBuilderWidget = require("mis_builder.widget"); + var _t = core._t; + + MisBuilderWidget.include({ + init: function () { + this._super.apply(this, arguments); + this.pms_property_ids_domain = []; + this.pms_property_ids_label = _t("PMS Properties Filter"); + this.pms_property_ids_m2m = undefined; + }, + + _getFilterFields: function () { + var fields = this._super.apply(this, arguments); + fields.push({ + relation: "pms.property", + type: "many2many", + name: "filter_pms_property_ids", + value: this._getFilterValue("pms_property_id"), + }); + return fields; + }, + + _makeFilterFieldWidgets: function (record) { + this._super.apply(this, arguments); + this.pms_property_ids_m2m = new relational_fields.FieldMany2ManyTags( + this, + "filter_pms_property_ids", + record, + { + mode: "edit", + attrs: { + placeholder: this.pms_property_ids_label, + options: { + no_create: "True", + no_open: "True", + }, + }, + } + ); + this._registerWidget( + record.id, + this.pms_property_ids_m2m.name, + this.pms_property_ids_m2m + ); + this.pms_property_ids_m2m.appendTo(this.getMisBuilderFilterBox()); + }, + + _beforeCreateWidgets: function (record) { + var defs = this._super.apply(this, arguments); + + var dataPoint = record.data.filter_pms_property_ids; + dataPoint.fieldsInfo.default.display_name = {}; + defs.push(this.model.reload(dataPoint.id)); + + return defs; + }, + + _confirmChange: function () { + var result = this._super.apply(this, arguments); + + if (this.pms_property_ids_m2m !== undefined) { + if ( + this.pms_property_ids_m2m.value && + this.pms_property_ids_m2m.value.res_ids.length > 0 + ) { + this._setFilterValue( + "pms_property_id", + this.pms_property_ids_m2m.value.res_ids, + "in" + ); + } else { + this._setFilterValue("pms_property_id", undefined); + } + } + return result; + }, + }); +}); diff --git a/mis_builder_pms/views/mis_builder_view.xml b/mis_builder_pms/views/mis_builder_view.xml new file mode 100644 index 000000000..8f3a9a107 --- /dev/null +++ b/mis_builder_pms/views/mis_builder_view.xml @@ -0,0 +1,51 @@ + + + + mis.report.instance.view.tree + mis.report.instance + + + + + + + + + mis.report.instance.view.form + mis.report.instance + + + + + + + + + + mis.report.instance.period.view.form + mis.report.instance.period + + + + + + + + + +