From e5ea41c8352e7a53aaf72e8d035ac6bce67ca15c Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Tue, 31 Jan 2017 10:31:37 +0100 Subject: [PATCH] [FIX] sale_coupon: Allow the public users to use the coupon mechanism --- __manifest__.py | 1 + models/__init__.py | 4 +++- models/sale_coupon_program.py | 13 +++++++++++++ models/sale_coupon_rule.py | 18 ++++++++++++++++++ views/sale_coupon_program_views.xml | 14 ++++++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 models/sale_coupon_program.py create mode 100644 models/sale_coupon_rule.py create mode 100644 views/sale_coupon_program_views.xml diff --git a/__manifest__.py b/__manifest__.py index bb1ed136ded..ee8f13073ad 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -10,6 +10,7 @@ 'data': [ 'views/website_sale_templates.xml', 'views/website_config_settings_views.xml', + 'views/sale_coupon_program_views.xml', ], 'auto_install': True, } diff --git a/models/__init__.py b/models/__init__.py index 76bcb3512a1..74697dcd6c0 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -import sale_order +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 new file mode 100644 index 00000000000..9ffe1a57d6b --- /dev/null +++ b/models/sale_coupon_program.py @@ -0,0 +1,13 @@ +# -*- 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 new file mode 100644 index 00000000000..523cc6e5d35 --- /dev/null +++ b/models/sale_coupon_rule.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from odoo import models, fields, api +from odoo.tools.safe_eval import safe_eval + +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 diff --git a/views/sale_coupon_program_views.xml b/views/sale_coupon_program_views.xml new file mode 100644 index 00000000000..562143deeac --- /dev/null +++ b/views/sale_coupon_program_views.xml @@ -0,0 +1,14 @@ + + + + + sale.coupon.program.view.form + sale.coupon.program + + + + + + + + \ No newline at end of file