diff --git a/controllers/main.py b/controllers/main.py index 6e7c4d5eeae2ac43294000529949c4e4aa9d9509..b33e54c9f7c72efd82458385d66d4f4b9655809b 100644 --- a/controllers/main.py +++ b/controllers/main.py @@ -1,17 +1,17 @@ # Copyright 2023 Le Filament (<http://www.le-filament.com>) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import _, http +from odoo import http +from odoo.addons.oacc_portal.controllers.main import \ + CustomerPortal as CustomerPortal from odoo.http import request -# from odoo.addons.portal.controllers.portal import CustomerPortal as CustomerPortal -from odoo.addons.oacc_portal.controllers.main import CustomerPortal as CustomerPortal - class CustomerPortal(CustomerPortal): def _get_data_date(self, is_data_cdc, operation=None): vals = {} - # Si des données existent, récupérer les dates min/max/début/fin de l'opération + # Si des données existent, récupérer les dates min/max/début/fin + # de l'opération if is_data_cdc: vals["data_values"] = operation.get_values_init_graph() @@ -38,7 +38,8 @@ class CustomerPortal(CustomerPortal): website=True, ) def pmo(self, operation, **kw): - render_values = self._get_operation_values(operation) + render_values = {} + render_values.update(self._get_role(operation)) render_values.update( self._get_data_date(render_values.get("isDataCdc"), operation) ) @@ -60,7 +61,8 @@ class CustomerPortal(CustomerPortal): website=True, ) def consumer(self, operation, **kw): - render_values = self._get_operation_values(operation) + render_values = {} + render_values.update(self._get_role(operation)) render_values.update( self._get_data_date(render_values.get("isDataCdc"), operation) @@ -83,13 +85,16 @@ class CustomerPortal(CustomerPortal): ) @http.route( - ['/operation/<model("acc.operation"):operation>/productor',], + [ + '/operation/<model("acc.operation"):operation>/productor', + ], type="http", auth="user", website=True, ) def productor(self, operation, **kw): - render_values = self._get_operation_values(operation) + render_values = {} + render_values.update(self._get_role(operation)) render_values.update( self._get_data_date(render_values.get("isDataCdc"), operation) @@ -113,7 +118,11 @@ class CustomerPortal(CustomerPortal): @http.route( ["/chart/update_json"], - type="json", auth="public", methods=["POST"], website=True, csrf=False, + type="json", + auth="public", + methods=["POST"], + website=True, + csrf=False, ) def chart_update_json( self, diff --git a/static/src/js/canvas.js b/static/src/js/canvas.js index 748179d811d5e443fad24af7b5f897f2954dceda..8fb92d78aca69399d8e83a0763fab339a6f01df0 100644 --- a/static/src/js/canvas.js +++ b/static/src/js/canvas.js @@ -1,11 +1,8 @@ odoo.define("oacc_portal_overview_cdc.canvas", function (require) { "use strict"; - var core = require("web.core"); var publicWidget = require("web.public.widget"); - var concurrency = require("web.concurrency"); - publicWidget.registry.oaccPortalOverviewCdc = publicWidget.Widget.extend({ jsLibs: [ "/web/static/lib/Chart/Chart.js", @@ -69,8 +66,10 @@ odoo.define("oacc_portal_overview_cdc.canvas", function (require) { */ start: function () { var self = this; - $('select[name="endpoint"]').select2({placeholder: "Sélectionner"}); - $('button[id="next-period"]').prop("disabled",true); + $('select[name="endpoint"]').select2({ + placeholder: "Sélectionner", + }); + $('button[id="next-period"]').prop("disabled", true); return this._super().then(function () { // Récupération des dates de début et fin @@ -169,38 +168,38 @@ odoo.define("oacc_portal_overview_cdc.canvas", function (require) { render_daterangepicker: function () { var self = this; - this.date_range_picker = this - .$('input[name="daterange"]') - .daterangepicker( - { - showDropdowns: true, - startDate: self.first_day, - endDate: self.last_day, - minDate: self.minDate, - maxDate: self.maxDate, - autoApply: true, - alwaysShowCalendars: true, - autoUpdateInput: true, - linkedCalendars: true, - }, - function (start, end, label) { - self.first_day = start.format("DD/MM/YYYY"); - self.last_day = end.format("DD/MM/YYYY"); - self._rpc({ - route: "/chart/update_json", - params: { - operation_id: self.operation, - date_start: self.first_day, - date_end: self.last_day, - partner_id: self.partner_id, - prm_id: self.prm_id, - data_type: self.data_type, - }, - }).then(function (data) { - self._updateDataTemplate(data); - }); - } - ); + this.date_range_picker = this.$( + 'input[name="daterange"]' + ).daterangepicker( + { + showDropdowns: true, + startDate: self.first_day, + endDate: self.last_day, + minDate: self.minDate, + maxDate: self.maxDate, + autoApply: true, + alwaysShowCalendars: true, + autoUpdateInput: true, + linkedCalendars: true, + }, + function (start, end, label) { + self.first_day = start.format("DD/MM/YYYY"); + self.last_day = end.format("DD/MM/YYYY"); + self._rpc({ + route: "/chart/update_json", + params: { + operation_id: self.operation, + date_start: self.first_day, + date_end: self.last_day, + partner_id: self.partner_id, + prm_id: self.prm_id, + data_type: self.data_type, + }, + }).then(function (data) { + self._updateDataTemplate(data); + }); + } + ); }, /** @@ -647,7 +646,9 @@ odoo.define("oacc_portal_overview_cdc.canvas", function (require) { if (title_name) { var title_cdc = $(".title_cdc"); var title_upd = - '<h3 class="title_cdc text-center mt-2">' + title_name + "</h3>"; + '<h3 class="title_cdc text-center mt-2">' + + title_name + + "</h3>"; title_cdc.replaceWith(title_upd); } self._updateDataTemplate(data); @@ -669,14 +670,14 @@ odoo.define("oacc_portal_overview_cdc.canvas", function (require) { // Disable buttons if first or last date if (this.last_day == this.maxDate) { - $('button[id="next-period"]').prop("disabled",true); + $('button[id="next-period"]').prop("disabled", true); } else { - $('button[id="next-period"]').prop("disabled",false); + $('button[id="next-period"]').prop("disabled", false); } if (this.first_day == this.minDate) { - $('button[id="previous-period"]').prop("disabled",true); + $('button[id="previous-period"]').prop("disabled", true); } else { - $('button[id="previous-period"]').prop("disabled",false); + $('button[id="previous-period"]').prop("disabled", false); } if (self.chart_line_conso !== null) { @@ -733,7 +734,7 @@ odoo.define("oacc_portal_overview_cdc.canvas", function (require) { }, _onChangePrm: function (ev) { - var selected = $(ev.currentTarget).find('option:selected'); + var selected = $(ev.currentTarget).find("option:selected"); this.title_name = selected.data("name"); this.partner_id = parseInt(selected.data("partner-id")); this.prm_id = parseInt(selected.data("prm-id")); @@ -752,48 +753,59 @@ odoo.define("oacc_portal_overview_cdc.canvas", function (require) { const delta_days = last_day - first_day; let delta_month = 0; - if (first_day.isSame(first_day.clone().startOf('month'), 'day') && last_day.isSame(last_day.clone().endOf('month'), 'day')) { + if ( + first_day.isSame(first_day.clone().startOf("month"), "day") && + last_day.isSame(last_day.clone().endOf("month"), "day") + ) { delta_month = last_day.month() - first_day.month() + 1; } if (type == "previous") { // Compare for first day - let next_first = first_day.clone().subtract(delta_days).subtract(1, 'd'); - let moment_min = moment(this.minDate, "DD/MM/YYYY"); - this.last_day = moment(this.last_day, "DD/MM/YYYY").subtract(delta_days).subtract(1, 'd').format("DD/MM/YYYY"); + let next_first = first_day + .clone() + .subtract(delta_days) + .subtract(1, "d"); + const moment_min = moment(this.minDate, "DD/MM/YYYY"); + this.last_day = moment(this.first_day, "DD/MM/YYYY") + .subtract(1, "d") + .format("DD/MM/YYYY"); if (delta_month > 0) { - next_first = first_day.subtract(delta_month, 'months'); - this.last_day = last_day.subtract(delta_month, 'months').endOf('month').format("DD/MM/YYYY"); + next_first = first_day + .clone() + .subtract(delta_month, "months"); } - this.first_day = moment.max([next_first, moment_min]).format("DD/MM/YYYY"); - - this.date_range_picker - .data("daterangepicker") - .setStartDate(this.first_day); - this.date_range_picker - .data("daterangepicker") - .setEndDate(this.last_day); + this.first_day = moment + .max([next_first, moment_min]) + .format("DD/MM/YYYY"); } if (type == "next") { // Compare for last day - let next_last = last_day.clone().add(delta_days).add(1, 'd'); - let moment_max = moment(this.maxDate, "DD/MM/YYYY"); + let next_last = last_day.clone().add(delta_days).add(1, "d"); + const moment_max = moment(this.maxDate, "DD/MM/YYYY"); + this.first_day = moment(this.last_day, "DD/MM/YYYY") + .add(1, "d") + .format("DD/MM/YYYY"); + if (delta_month > 0) { - next_last = last_day.add(delta_month, 'months').endOf('month'); - this.first_day = first_day.add(1, 'months').format("DD/MM/YYYY"); + next_last = last_day + .clone() + .add(delta_month, "months") + .endOf("month"); } - this.last_day = moment.min([next_last, moment_max]).format("DD/MM/YYYY"); - - this.date_range_picker - .data("daterangepicker") - .setStartDate(this.first_day); - this.date_range_picker - .data("daterangepicker") - .setEndDate(this.last_day); + this.last_day = moment + .min([next_last, moment_max]) + .format("DD/MM/YYYY"); } + this.date_range_picker + .data("daterangepicker") + .setStartDate(this.first_day); + this.date_range_picker + .data("daterangepicker") + .setEndDate(this.last_day); this._updateChartData(this.title_name); }, });