36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from odoo import api, fields, models
|
|
|
|
class LoyaltyReward(models.Model):
|
|
_inherit = 'loyalty.reward'
|
|
|
|
def _get_discount_product_values(self):
|
|
res = super()._get_discount_product_values()
|
|
|
|
# Search for the dedicated category "OT / Saleable / PoS / Discounts"
|
|
category = self.env['product.category'].sudo().search([
|
|
('complete_name', '=', 'OT / Saleable / PoS / Discounts')
|
|
], limit=1)
|
|
if not category:
|
|
# Fallback to any category named "Discounts" if not found
|
|
category = self.env['product.category'].sudo().search([
|
|
('name', '=', 'Discounts')
|
|
], limit=1)
|
|
|
|
for reward, vals in zip(self, res):
|
|
if category:
|
|
vals['categ_id'] = category.id
|
|
|
|
# Search for account "412201" matching the company of the reward
|
|
company = reward.company_id or self.env.company
|
|
account = self.env['account.account'].sudo().search([
|
|
('code', '=', '412201'),
|
|
('company_ids', '=', company.id)
|
|
], limit=1)
|
|
if account:
|
|
vals['property_account_income_id'] = account.id
|
|
vals['property_account_expense_id'] = account.id
|
|
|
|
return res
|