mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-27 01:12:00 +02:00
Initial commit: Sale packages
This commit is contained in:
commit
14e3d26998
6469 changed files with 2479670 additions and 0 deletions
|
|
@ -0,0 +1,23 @@
|
|||
# -*- 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'].sudo()._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
|
||||
Loading…
Add table
Add a link
Reference in a new issue