From b4d41b4ccb2da7a20377bebaac58e51889aaa6ad Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Wed, 4 Nov 2020 11:39:25 +0000 Subject: [PATCH 1/5] [FIX] website: use correct action domain on dashboard Without this commit, when clicking on a metric on the website dashboard, it would not load the correct data. Indeed, the dashboard is loaded for a specific website only, but clicking on a metric opens the data for every website together. Step to reproduce: - Make some orders on 2 differents website ecommerce - OPTIONAL: Get through the payment on some orders, then just leave some products in the cart afterward to have some unpaid orders - Go to the website dashboard, you see some metrics - Change the selected website on top right, you see the metrics adapts correctly - Click on a metric, it doesn't fit the number you clicked on. For instance, if you had 1 Unpaid Orders for website 1 and 3 Unpaid Orders for website 2, you see 4 orders in the tree view once you have clicked the metric. This commit ensures the correct website is appended to every dashboard action domain. opw-2369420 Fixes #44926, fixes #51125 X-original-commit: 06f954787cf60e657768e365a15ea4513d459c0b --- .../website/static/src/js/backend/dashboard.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/addons/website/static/src/js/backend/dashboard.js b/addons/website/static/src/js/backend/dashboard.js index c1dcfdb39d1..7b37557987c 100644 --- a/addons/website/static/src/js/backend/dashboard.js +++ b/addons/website/static/src/js/backend/dashboard.js @@ -6,6 +6,7 @@ var ajax = require('web.ajax'); var core = require('web.core'); var Dialog = require('web.Dialog'); var field_utils = require('web.field_utils'); +var pyUtils = require('web.py_utils'); var session = require('web.session'); var time = require('web.time'); var web_client = require('web.web_client'); @@ -353,6 +354,7 @@ var Dashboard = AbstractAction.extend({ on_dashboard_action: function (ev) { ev.preventDefault(); + var self = this var $action = $(ev.currentTarget); var additional_context = {}; if (this.date_range === 'week') { @@ -362,9 +364,18 @@ var Dashboard = AbstractAction.extend({ } else if (this.date_range === 'year') { additional_context = {search_default_year: true}; } - this.do_action($action.attr('name'), { - additional_context: additional_context, - on_reverse_breadcrumb: this.on_reverse_breadcrumb + this._rpc({ + route: '/web/action/load', + params: { + 'action_id': $action.attr('name'), + }, + }) + .then(function (action) { + action.domain = pyUtils.assembleDomains([action.domain, `[('website_id', '=', ${self.website_id})]`]); + return self.do_action(action, { + 'additional_context': additional_context, + 'on_reverse_breadcrumb': self.on_reverse_breadcrumb + }); }); }, From c8a40e847e2924169b866ae842067090c665a97f Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Wed, 4 Nov 2020 11:59:41 +0000 Subject: [PATCH 2/5] [FIX] website_sale: make dashboard action domain same as displayed data The metrics displayed on the dashboard are retrieved through a domain used in `fetch_dashboard_data()` route. When clicking on one of those metrics, an action is called with a domain. This commit fixes incoherences between those domains. task-2369420 X-original-commit: 84a759af1e29aa5181a6ccf08b1dec5e79f63586 --- addons/website_sale/views/sale_order_views.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/website_sale/views/sale_order_views.xml b/addons/website_sale/views/sale_order_views.xml index e443b078c1b..79ebac81b68 100644 --- a/addons/website_sale/views/sale_order_views.xml +++ b/addons/website_sale/views/sale_order_views.xml @@ -115,7 +115,7 @@ Orders To Invoice sale.order tree,form,kanban - [('state', 'in', ('sale', 'done')), ('invoice_status', '=', 'to invoice'), ('website_id', '!=', False)] + [('state', 'in', ('sale', 'done')), ('order_line', '!=', False), ('invoice_status', '=', 'to invoice'), ('website_id', '!=', False)] {'show_sale': True, 'search_default_order_confirmed': 1, 'create': False} From 0bce015cb4b748a63fc7e617f3b4374fa5202e62 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Wed, 4 Nov 2020 12:48:01 +0000 Subject: [PATCH 3/5] [FIX] website_sale: align domain from route and act window Act window domain are used to load tree view data when clicking on dashboard metric. That metric is retrieved through domain in backend. This domain part wasn't adapted in act window domain (can't use ref). As searching on website is enough to get ecommerce order, this line can be safely removed, it is an old code that was needed before website_id was set on order, as it can be noticed in f6fc7c23192. X-original-commit: b31abe06583c06dfc8b0df047d2659e657785b89 --- addons/website_sale/controllers/backend.py | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/website_sale/controllers/backend.py b/addons/website_sale/controllers/backend.py index 154effb6328..a689e232481 100644 --- a/addons/website_sale/controllers/backend.py +++ b/addons/website_sale/controllers/backend.py @@ -67,7 +67,6 @@ class WebsiteSaleBackend(WebsiteBackend): # Sale-based results computation sale_order_domain = [ ('website_id', '=', current_website.id), - ('team_id', 'in', request.env['crm.team'].search([('website_ids', '!=', False)]).ids), ('date_order', '>=', fields.Datetime.to_string(datetime_from)), ('date_order', '<=', fields.Datetime.to_string(datetime_to))] so_group_data = request.env['sale.order'].read_group(sale_order_domain, fields=['state'], groupby='state') From aebe84555f3d847c6c05e2a47935ba7253ba6ea3 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Wed, 4 Nov 2020 13:12:08 +0000 Subject: [PATCH 4/5] [FIX] website_sale: restore date filters Those were removed with f9874b2b047332b and restored in 14.0 (master at that point) with cc6000abfae651. This commit restores the missing filters for the context filters to work on the view used in stable. X-original-commit: 0fd1a8ce30ff83030577b95b2ac10669425671e9 --- addons/website_sale/views/sale_order_views.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/website_sale/views/sale_order_views.xml b/addons/website_sale/views/sale_order_views.xml index 79ebac81b68..b0b88f5a960 100644 --- a/addons/website_sale/views/sale_order_views.xml +++ b/addons/website_sale/views/sale_order_views.xml @@ -15,6 +15,10 @@ + + + + From 8ea18f2270d9ac251d2cc0a17943f5227af1057f Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Thu, 5 Nov 2020 12:37:41 +0000 Subject: [PATCH 5/5] [FIX] website_sale: align dashboard data Before this commit, the python domain on sale.report would not get today's data as it would do `date >= 2020-03-03`, but it means `2020-03-03 00:00:00`, actually excluding today. Then the JS domains to retrieve those data once you click on the metric (it loads an act window with his domain + additional domain though js) would have a different date domain, including today. Note that there is still some inconsistencies between python and JS such as last month filter which is in python (in template filter) today - 30 days while in JS it is moment.subtract 1 month which might be 31 days. X-original-commit: 23e65d70baf2444b35c81a10cdc09fee9d625c75 --- addons/website_sale/controllers/backend.py | 6 +++--- addons/website_sale/views/sale_order_views.xml | 2 ++ addons/website_sale/views/sale_report_views.xml | 4 ++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/addons/website_sale/controllers/backend.py b/addons/website_sale/controllers/backend.py index a689e232481..bff9790fe8b 100644 --- a/addons/website_sale/controllers/backend.py +++ b/addons/website_sale/controllers/backend.py @@ -48,7 +48,7 @@ class WebsiteSaleBackend(WebsiteBackend): sale_report_domain = [ ('website_id', '=', current_website.id), ('state', 'in', ['sale', 'done']), - ('date', '>=', date_from), + ('date', '>=', datetime_from), ('date', '<=', fields.Datetime.now()) ] report_product_lines = request.env['sale.report'].read_group( @@ -81,8 +81,8 @@ class WebsiteSaleBackend(WebsiteBackend): domain=[ ('website_id', '=', current_website.id), ('state', 'in', ['sale', 'done']), - ('date', '>=', date_from), - ('date', '<=', date_to)], + ('date', '>=', datetime_from), + ('date', '<=', datetime_to)], fields=['team_id', 'price_subtotal'], groupby=['team_id'], ) diff --git a/addons/website_sale/views/sale_order_views.xml b/addons/website_sale/views/sale_order_views.xml index b0b88f5a960..36f9e2267b8 100644 --- a/addons/website_sale/views/sale_order_views.xml +++ b/addons/website_sale/views/sale_order_views.xml @@ -77,6 +77,7 @@ + Unpaid Orders sale.order @@ -115,6 +116,7 @@ + Orders To Invoice sale.order diff --git a/addons/website_sale/views/sale_report_views.xml b/addons/website_sale/views/sale_report_views.xml index d17325b9fa4..27d3b72410c 100644 --- a/addons/website_sale/views/sale_report_views.xml +++ b/addons/website_sale/views/sale_report_views.xml @@ -23,6 +23,10 @@ + + + +