Files
odoo_source/addons/sale_loyalty/models/loyalty_program.py
T
eres-odooandWilliam Braeckman 6927dcda9f [IMP] loyalty*: misc loyalty improvements
This commit improves some messages and usability for loyalty and its
submodules:
 - Coupons should not be restricted to the partner assigned to them
   anymore
 - Merged "I have a promo code" and "Use a gift card" into a single
   toggle
 - Boolean fields have been added to each app to disable them where we
   don't want them.
 - Reduced the size of coupon codes
   This means that we increase the risk of collision which should be
   handled by the model as well now.
   Creating a coupon with an existing code will retry the creation (up
   to 10 times) until the coupon is indeed created.
 - Make it clearer in the coupon generation wizard that an email will be
   sent to the customer.
 - Reintroduce coupon/gift card details on sale order lines in eCommerce
   which was wrongfully removed.
 - Remove the "on product with taxes: " message on order lines when
   the amount is not split between taxes or if the tax message would be
   empty.
 - Make it possible for some error messages to be displayed as warning
   instead of errors
 - Split program types in two menuitems, one for promotions discount
   loyalty etc and one for gift cards and ewallet, the latter has
   simplified views.
 - Views overall have been reviewed to make it easier to understand how
   to programs work. New program types have also been added.

TaskId-2951413

Part-of: odoo/odoo#99023
Co-authored-by: William Braeckman <wbr@odoo.com>
2022-09-02 20:10:59 +02:00

24 lines
1009 B
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class LoyaltyProgram(models.Model):
_inherit = 'loyalty.program'
order_count = fields.Integer(compute='_compute_order_count')
sale_ok = fields.Boolean("Sales", default=True)
def _compute_order_count(self):
# An order should count only once PER program but may appear in multiple programs
read_group_res = self.env['sale.order.line']._read_group(
[('reward_id', 'in', self.reward_ids.ids)], ['reward_id:array_agg'], ['order_id'])
for program in self:
program_reward_ids = program.reward_ids.ids
program.order_count = sum(1 if any(id in group['reward_id'] for id in program_reward_ids) else 0 for group in read_group_res)
def _compute_total_order_count(self):
super()._compute_total_order_count()
for program in self:
program.total_order_count += program.order_count