diff options
| author | Dhawal Limbuwala <dli@odoo.com> | 2017-12-05 09:56:47 +0100 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2017-12-05 13:13:22 +0100 |
| commit | 930b682b1dfb7cd0b31c6a6a4dd137a8f660c0a7 (patch) | |
| tree | 71aead910fccbcb2edb2b5b5ec4a04f60ac0842a /addons | |
| parent | 3821eb218e0417fdea475d3cb9b503a8803f69f8 (diff) | |
[IMP] website_sale: Fetch confirmed orders grouped by product templates
Purpose
=======
Sales graph should be based on confirmation_date of sales orders, not the date_order.
Date should be aggregated by product templates, not variants
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/website_sale/controllers/backend.py | 25 | ||||
| -rw-r--r-- | addons/website_sale/static/src/js/website_sale_backend.js | 6 |
2 files changed, 15 insertions, 16 deletions
diff --git a/addons/website_sale/controllers/backend.py b/addons/website_sale/controllers/backend.py index 303d5d3e3e8..646a1575c9b 100644 --- a/addons/website_sale/controllers/backend.py +++ b/addons/website_sale/controllers/backend.py @@ -40,18 +40,17 @@ class WebsiteSaleBackend(WebsiteBackend): # Product-based computation report_product_lines = request.env['sale.report'].read_group( domain=[ - ('product_id.website_published', '=', True), ('team_id.team_type', '=', 'website'), ('state', 'in', ['sale', 'done']), - ('date', '>=', date_from), - ('date', '<=', date_to)], - fields=['product_id', 'product_uom_qty', 'price_subtotal'], - groupby='product_id', orderby='product_uom_qty desc', limit=5) + ('confirmation_date', '>=', date_from), + ('confirmation_date', '<=', fields.Datetime.now())], + fields=['product_tmpl_id', 'product_uom_qty', 'price_subtotal'], + groupby='product_tmpl_id', orderby='product_uom_qty desc', limit=5) for product_line in report_product_lines: - product_id = request.env['product.product'].browse(product_line['product_id'][0]) + product_tmpl_id = request.env['product.template'].browse(product_line['product_tmpl_id'][0]) sales_values['best_sellers'].append({ - 'id': product_id.id, - 'name': product_id.name, + 'id': product_tmpl_id.id, + 'name': product_tmpl_id.name, 'qty': product_line['product_uom_qty'], 'sales': product_line['price_subtotal'], }) @@ -113,8 +112,8 @@ class WebsiteSaleBackend(WebsiteBackend): sales_domain = [ ('team_id.team_type', '=', 'website'), ('state', 'in', ['sale', 'done']), - ('date', '>=', date_from), - ('date', '<=', date_to) + ('confirmation_date', '>=', date_from), + ('confirmation_date', '<=', fields.Datetime.now()) ] sales_values['graph'] += [{ 'values': self._compute_sale_graph(date_date_from, date_date_to, sales_domain), @@ -133,10 +132,10 @@ class WebsiteSaleBackend(WebsiteBackend): daily_sales = request.env['sale.report'].read_group( domain=sales_domain, - fields=['date', 'price_subtotal'], - groupby='date:day') + fields=['confirmation_date', 'price_subtotal'], + groupby='confirmation_date:day') - daily_sales_dict = {p['date:day']: p['price_subtotal'] for p in daily_sales} + daily_sales_dict = {p['confirmation_date:day']: p['price_subtotal'] for p in daily_sales} sales_graph = [{ '0': fields.Date.to_string(d) if not previous else fields.Date.to_string(d + timedelta(days=days_between)), diff --git a/addons/website_sale/static/src/js/website_sale_backend.js b/addons/website_sale/static/src/js/website_sale_backend.js index 677219c5ef5..2fa7e06dbfa 100644 --- a/addons/website_sale/static/src/js/website_sale_backend.js +++ b/addons/website_sale/static/src/js/website_sale_backend.js @@ -18,11 +18,11 @@ WebsiteBackend.include({ on_product_template: function (ev) { ev.preventDefault(); - var product_id = $(ev.currentTarget).data('productId'); + var product_tmpl_id = $(ev.currentTarget).data('productId'); this.do_action({ type: 'ir.actions.act_window', - res_model: 'product.product', - res_id: product_id, + res_model: 'product.template', + res_id: product_tmpl_id, views: [[false, 'form']], target: 'current', }, { |
