[ADD] mis_builder_pms: Selector of pms properties fot MIS reports

This commit is contained in:
Omar (Comunitea)
2022-12-18 10:59:26 +01:00
committed by Darío Lodeiros
parent cf08eeccdd
commit 75a0269040
13 changed files with 229 additions and 0 deletions

View File

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -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,
}

View File

@@ -0,0 +1 @@
from . import mis_builder

View File

@@ -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

View File

@@ -0,0 +1 @@
* Omar Castiñeira <omar@comunitea.com>

View File

@@ -0,0 +1 @@
Introduces the PMS property to MIS Builder report instances.

View File

@@ -0,0 +1 @@
Set the PMS property in a MIS Builder instance.

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@@ -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;
},
});
});

View File

@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record model="ir.ui.view" id="mis_report_instance_view_tree">
<field name="name">mis.report.instance.view.tree</field>
<field name="model">mis.report.instance</field>
<field name="inherit_id" ref="mis_builder.mis_report_instance_view_tree" />
<field name="arch" type="xml">
<field name="target_move" position="after">
<field name="pms_property_ids" widget="many2many_tags" />
</field>
</field>
</record>
<record model="ir.ui.view" id="mis_report_instance_view_form">
<field name="name">mis.report.instance.view.form</field>
<field name="model">mis.report.instance</field>
<field name="inherit_id" ref="mis_builder.mis_report_instance_view_form" />
<field name="priority" eval="16" />
<field name="arch" type="xml">
<field name="target_move" position="after">
<field name="pms_property_ids" widget="many2many_tags" />
</field>
</field>
</record>
<record model="ir.ui.view" id="mis_report_instance_period_view_form">
<field name="name">mis.report.instance.period.view.form</field>
<field name="model">mis.report.instance.period</field>
<field
name="inherit_id"
ref="mis_builder.mis_report_instance_period_view_form"
/>
<field name="priority" eval="16" />
<field name="arch" type="xml">
<xpath expr="//group[@name='source_data']" position="inside">
<field
name="pms_property_ids"
widget="many2many_tags"
attrs="{'invisible': [('source', 'not in', ('actuals', 'actuals_alt'))]}"
/>
</xpath>
</field>
</record>
<template id="assets_backend" name="mis_builder" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script
type="text/javascript"
src="/mis_builder_pms/static/src/js/mis_report_widget.js"
/>
</xpath>
</template>
</odoo>

View File

@@ -0,0 +1 @@
../../../../mis_builder_pms

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)