19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:29:53 +01:00
parent 6e54c1af6c
commit 3ca647e428
1087 changed files with 132065 additions and 108499 deletions

View file

@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
from odoo.osv import expression
from odoo.tools import ustr
from odoo.fields import Domain
class LoyaltyRule(models.Model):
_inherit = 'loyalty.rule'
_name = 'loyalty.rule'
_inherit = ['loyalty.rule', 'pos.load.mixin']
valid_product_ids = fields.Many2many(
'product.product', "Valid Products", compute='_compute_valid_product_ids',
@ -19,25 +19,31 @@ class LoyaltyRule(models.Model):
"This is automatically generated when the promo code is changed."
)
@api.depends('product_ids', 'product_category_id', 'product_tag_id') #TODO later: product tags
@api.model
def _load_pos_data_domain(self, data, config):
return [('program_id', 'in', config._get_program_ids().ids)]
@api.model
def _load_pos_data_fields(self, config):
return ['program_id', 'valid_product_ids', 'any_product', 'currency_id',
'reward_point_amount', 'reward_point_split', 'reward_point_mode',
'minimum_qty', 'minimum_amount', 'minimum_amount_tax_mode', 'mode', 'code']
@api.depends('product_ids', 'product_category_id', 'product_tag_id', 'product_domain') # TODO later: product tags
def _compute_valid_product_ids(self):
domain_products = {}
for rule in self:
if rule.product_ids or\
rule.product_category_id or\
rule.product_tag_id or\
rule.product_domain not in ('[]', "[['sale_ok', '=', True]]"):
domain = rule._get_valid_product_domain()
domain = expression.AND([[('available_in_pos', '=', True)], domain])
product_ids = domain_products.get(ustr(domain))
if product_ids is None:
product_ids = self.env['product.product'].search(domain, order="id")
domain_products[ustr(domain)] = product_ids
rule.valid_product_ids = product_ids
rule.any_product = False
for key, rules in self.grouped(lambda rule: (
tuple(rule.product_ids.ids),
rule.product_category_id.id,
rule.product_tag_id.id,
'' if rule.product_domain in ('[]', "[['sale_ok', '=', True]]") else rule.product_domain,
)).items():
if any(key):
domain = Domain.AND([[('available_in_pos', '=', True)], rules[:1]._get_valid_product_domain()])
rules.valid_product_ids = self.env['product.product'].search(domain, order="id")
rules.any_product = False
else:
rule.any_product = True
rule.valid_product_ids = self.env['product.product']
rules.valid_product_ids = self.env['product.product']
rules.any_product = True
@api.depends('code')
def _compute_promo_barcode(self):