From 63c5b7c9c5ce5a0555a78bfedc254bcac1232b60 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Wed, 21 Jun 2017 10:24:02 +0200 Subject: [PATCH] [FIX] sale_coupon: Don't update automatic rewards on the fly Purpose ======= Currently we are updating the coupon rewards on the fly when creating/modifying/deleting a sales order line. To avoid multiple searches on res_partners and product to know whether the customer/product is valid on the sale coupon program, we store the applicable customers and products on the program according to the domain defined on it. This brings 2 issues: - The customers/products stored on the program are not updated (Was the original spec) - The checks are numerous and maybe overkill for the given results Specification ============= - Don't recompute the reward lines on SO modifications. Add a button to compute the line by hand and make an automatic compute on the SO validation or on the page shop/payment. - When recomputing the reward lines, make a search on the res_partners and products instead. Now that the action is not triggered so often we can afford to make a search. - Don't use the fields rule_partners_domain and rule_products_domain. This should be removed in master. - The field is_public_included is useless now. And we decided to make the coupon available for all the partners if they fit the domain on the program. --- controllers/main.py | 6 ++++++ models/__init__.py | 1 - models/sale_coupon_program.py | 13 ------------- models/sale_coupon_rule.py | 19 ++++++------------- views/sale_coupon_program_views.xml | 11 ----------- 5 files changed, 12 insertions(+), 38 deletions(-) delete mode 100644 models/sale_coupon_program.py diff --git a/controllers/main.py b/controllers/main.py index 2fdfe53d5ed..3a589ac2979 100644 --- a/controllers/main.py +++ b/controllers/main.py @@ -13,3 +13,9 @@ class WebsiteSale(WebsiteSale): if coupon_status.get('error', False): return super(WebsiteSale, self).pricelist(promo, **post) return request.redirect(post.get('r', '/shop/cart')) + + @http.route(['/shop/payment'], type='http', auth="public", website=True) + def payment(self, **post): + order = request.website.sale_get_order() + order.recompute_coupon_lines() + return super(WebsiteSale, self).payment(**post) diff --git a/models/__init__.py b/models/__init__.py index 74697dcd6c0..bdc919f5eec 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -2,5 +2,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. import sale_coupon_rule -import sale_coupon_program import sale_order \ No newline at end of file diff --git a/models/sale_coupon_program.py b/models/sale_coupon_program.py deleted file mode 100644 index 9ffe1a57d6b..00000000000 --- a/models/sale_coupon_program.py +++ /dev/null @@ -1,13 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo import models - -class SaleCouponProgram(models.Model): - _inherit = 'sale.coupon.program' - - def _filter_programs_on_partners(self, order): - return self.filtered(lambda program: - program.with_context(active_test=False).rule_partner_ids and - order.partner_id.id in program.with_context(active_test=False).rule_partner_ids.ids or - not program.with_context(active_test=False).rule_partner_ids) diff --git a/models/sale_coupon_rule.py b/models/sale_coupon_rule.py index 523cc6e5d35..00103f883ea 100644 --- a/models/sale_coupon_rule.py +++ b/models/sale_coupon_rule.py @@ -1,18 +1,11 @@ # -*- coding: utf-8 -*- -from odoo import models, fields, api -from odoo.tools.safe_eval import safe_eval + +from odoo import models, fields + class SaleCouponRule(models.Model): _inherit = "sale.coupon.rule" - is_public_included = fields.Boolean(string="Include Public User", help="Is the public user included into the set of autorized customers", default=True) - - @api.depends('is_public_included') - def _compute_rule_partner_ids(self): - for applicability in self.filtered(lambda x: x.rule_partners_domain): - domain = safe_eval(applicability.rule_partners_domain) - applicability.rule_partner_ids = domain and self.env['res.partner'].search(domain) - if self.is_public_included: - public_users = self.sudo().env.ref('base.group_public').with_context(active_test=False).users - public_partners = public_users.mapped('partner_id') - applicability.rule_partner_ids += public_partners + # TODO Remove in master, useless now + is_public_included = fields.Boolean(string="Include Public User", + help="Is the public user included into the set of autorized customers", default=True, deprecated=True) diff --git a/views/sale_coupon_program_views.xml b/views/sale_coupon_program_views.xml index 7021081fa83..1ad9ac5b61e 100644 --- a/views/sale_coupon_program_views.xml +++ b/views/sale_coupon_program_views.xml @@ -1,17 +1,6 @@ - - sale.coupon.program.view.form - sale.coupon.program - - - - - - - -