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,13 +1,26 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
from odoo import fields, models, api
class LoyaltyCard(models.Model):
_inherit = 'loyalty.card'
_name = 'loyalty.card'
_inherit = ['loyalty.card', 'pos.load.mixin']
source_pos_order_id = fields.Many2one('pos.order', "PoS Order Reference",
help="PoS order where this coupon was generated.")
source_pos_order_partner_id = fields.Many2one(
'res.partner', "PoS Order Customer",
related="source_pos_order_id.partner_id")
@api.model
def _load_pos_data_domain(self, data, config):
return False
@api.model
def _load_pos_data_fields(self, config):
return ['partner_id', 'code', 'points', 'points_display', 'program_id', 'expiration_date', 'write_date']
def _has_source_order(self):
return super()._has_source_order() or bool(self.source_pos_order_id)
@ -18,8 +31,8 @@ class LoyaltyCard(models.Model):
return self.env.ref('pos_loyalty.mail_coupon_template', False)
return super()._get_default_template()
def _get_mail_partner(self):
return super()._get_mail_partner() or self.sudo().source_pos_order_id.partner_id
def _mail_get_partner_fields(self, introspect_fields=False):
return super()._mail_get_partner_fields(introspect_fields=introspect_fields) + ['source_pos_order_partner_id']
def _get_signature(self):
return self.source_pos_order_id.user_id.signature or super()._get_signature()
@ -27,7 +40,28 @@ class LoyaltyCard(models.Model):
def _compute_use_count(self):
super()._compute_use_count()
read_group_res = self.env['pos.order.line']._read_group(
[('coupon_id', 'in', self.ids)], ['id'], ['coupon_id'])
count_per_coupon = {r['coupon_id'][0]: r['coupon_id_count'] for r in read_group_res}
[('coupon_id', 'in', self.ids)], ['coupon_id'], ['__count'])
count_per_coupon = {coupon.id: count for coupon, count in read_group_res}
for card in self:
card.use_count += count_per_coupon.get(card.id, 0)
@api.model
def get_gift_card_status(self, gift_code, config_id):
card = self.search([('code', '=', gift_code)], limit=1)
is_valid = card.exists() and (not card.expiration_date or card.expiration_date > fields.Date.today()) and card.points > 0
is_valid = is_valid and (card.program_id.program_type == 'gift_card') and not card.partner_id
is_valid = is_valid and len([id for id in card.history_ids.mapped('order_id') if id != 0]) == 0
card_fields = self._load_pos_data_fields(config_id)
return {
'status': bool(is_valid) or not card.exists(),
'data': {
'loyalty.card': card.read(card_fields, load=False),
}
}
@api.model
def get_loyalty_card_partner_by_code(self, code):
return self.env['loyalty.card'].search([
('code', '=', code),
('program_type', '=', 'loyalty'),
], limit=1).partner_id or False