[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.
This commit is contained in:
Yannick Tivisse
2017-06-21 15:55:27 +02:00
parent 28eee52c78
commit 63c5b7c9c5
5 changed files with 12 additions and 38 deletions
+6
View File
@@ -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)
-1
View File
@@ -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
-13
View File
@@ -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)
+6 -13
View File
@@ -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)
-11
View File
@@ -1,17 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="sale_coupon_program_view_form" model="ir.ui.view">
<field name="name">sale.coupon.program.view.form</field>
<field name="model">sale.coupon.program</field>
<field name="inherit_id" ref="sale_coupon.sale_coupon_program_view_promo_program_form"/>
<field name="arch" type="xml">
<field name="rule_partners_domain" position="before">
<field name="is_public_included"/>
</field>
</field>
</record>
<menuitem action="sale_coupon.sale_coupon_program_action_promo_program" id="menu_promotion_type_config" parent="website_sale.menu_catalog" groups="sales_team.group_sale_manager" sequence="50"/>
<menuitem id="menu_coupon_type_config" action="sale_coupon.sale_coupon_program_action_coupon_program" parent="website_sale.menu_catalog" groups="sales_team.group_sale_manager" sequence="51"/>