diff options
| author | Yannick Tivisse <yti@odoo.com> | 2017-01-31 10:31:37 +0100 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2017-01-31 10:31:37 +0100 |
| commit | e5ea41c8352e7a53aaf72e8d035ac6bce67ca15c (patch) | |
| tree | 1623ccf4e53c190404e244a7b5f1b69e906ac288 | |
| parent | 78f6c56d221168d0663b1bf298c20c0ed8f9a8e8 (diff) | |
[FIX] sale_coupon: Allow the public users to use the coupon mechanism
| -rw-r--r-- | __manifest__.py | 1 | ||||
| -rw-r--r-- | models/__init__.py | 4 | ||||
| -rw-r--r-- | models/sale_coupon_program.py | 13 | ||||
| -rw-r--r-- | models/sale_coupon_rule.py | 18 | ||||
| -rw-r--r-- | views/sale_coupon_program_views.xml | 14 |
5 files changed, 49 insertions, 1 deletions
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 @@ +<?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> +</odoo>
\ No newline at end of file |
