[FIX] sale_coupon: Allow the public users to use the coupon mechanism
This commit is contained in:
@@ -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,
|
||||
}
|
||||
|
||||
+3
-1
@@ -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
|
||||
@@ -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)
|
||||
@@ -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
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user