Skip to content
Snippets Groups Projects
Commit 1f6d84e3 authored by Ivan Yelizariev's avatar Ivan Yelizariev
Browse files

[FIX] coupon: fix onchange method for domain field


Field `has_partner_email` depends on `partners_domain` field, which uses domain
widget. The domain widget may generate broken value.
This commit fixes it by checking that value in the onchange method.

STEPS:

1) go to coupon programs
2) click generate coupon
3) select <Number of Selected Customers>
4) click on domain field, and click the arrow back (nothing is in the domain)
5) if you click on the scrollbar, error appears (the same for any other click
that triggers onchange)

Alternative solution could be fixing the domain widget. But this looks as an
overkill for v14 for few reasons. First, the js client was heavily updated in v15+.
Second, the problem is quite specific for this module and v16 has not such usage
examples in standard modules.

opw-3062969

closes odoo/odoo#107325

Signed-off-by: default avatarWilliam Braeckman (wbr) <wbr@odoo.com>
parent 5bbe62f8
Branches
Tags
No related merge requests found
......@@ -44,5 +44,12 @@ class CouponGenerate(models.TransientModel):
@api.depends('partners_domain')
def _compute_has_partner_email(self):
for record in self:
domain = expression.AND([ast.literal_eval(record.partners_domain), [('email', '=', False)]])
partners_domain = ast.literal_eval(record.partners_domain)
if partners_domain == [['', '=', 1]]:
# The field name is not clear. It actually means "all partners have email".
# If domain is not set, we don't want to show the warning "there is a partner without email".
# So, we explicitly set value to True
record.has_partner_email = True
continue
domain = expression.AND([partners_domain, [('email', '=', False)]])
record.has_partner_email = self.env['res.partner'].search_count(domain) == 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment