From a6f8d1554f89d33f132993f37ff28006af024605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nshimiyimana=20S=C3=A9na?= Date: Tue, 29 Aug 2023 14:27:37 +0200 Subject: [PATCH] [FIX] loyalty: add link to discout products in loyalty.program form view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A customer has a gift card product linked to a specific income account. When sold, the income account associated with the gift card product is credited correctly. The issue arises when the gift card is consumed within a sales order. An order line is added using a "dummy product" to indicate the gift card's usage (one dummy product is created for each loyalty program). Due to this, when an account move is created from the sale order, the income account defined on the dummy product is used instead of the one on the gift card product. This leads to the wrong income account being debited, causing unbalanced accounting entries. There's currently no way to link back to the original gift card product from a `loyalty.card` record. Because of this, the system cannot identify the correct income account to debit. Fixing this would require adding a new field, which we can't do in stable. A potential workaround is to find the dummy product and set the income account to the same as the gift card product. However, with one dummy product for each `loyalty.program`, all named "Gift Card", finding the right dummy product is difficult. This commit aims to simplify the workaround by adding a link to the associated dummy product on the `loyalty.program` form view. This change should ease the process of finding and modifying the correct dummy product, thus mitigating the issue in the current stable version. opw-3239720 opw-3373287 closes odoo/odoo#133461 X-original-commit: 767eccb122055cd9a474ce5110cb7296eb9ef4c2 Signed-off-by: Séna Serge Nshimiyimana (sesn) --- addons/loyalty/i18n/loyalty.pot | 5 +++++ addons/loyalty/models/loyalty_program.py | 16 ++++++++++++++++ addons/loyalty/views/loyalty_program_views.xml | 1 + addons/loyalty/views/loyalty_reward_views.xml | 1 + 4 files changed, 23 insertions(+) diff --git a/addons/loyalty/i18n/loyalty.pot b/addons/loyalty/i18n/loyalty.pot index 392e925514d..f98eee2aa69 100644 --- a/addons/loyalty/i18n/loyalty.pot +++ b/addons/loyalty/i18n/loyalty.pot @@ -1419,6 +1419,11 @@ msgstr "" msgid "Product Variant" msgstr "" +#. module: loyalty +#: model:ir.model.fields,help:loyalty.field_loyalty_program__discount_product_id +msgid "Product used in the sales order to apply the discount." +msgstr "" + #. module: loyalty #: model:ir.model.fields,help:loyalty.field_loyalty_reward__discount_line_product_id msgid "" diff --git a/addons/loyalty/models/loyalty_program.py b/addons/loyalty/models/loyalty_program.py index a15aa627788..b8d7302199a 100644 --- a/addons/loyalty/models/loyalty_program.py +++ b/addons/loyalty/models/loyalty_program.py @@ -91,6 +91,14 @@ class LoyaltyProgram(models.Model): is_nominative = fields.Boolean(compute='_compute_is_nominative') is_payment_program = fields.Boolean(compute='_compute_is_payment_program') + payment_program_discount_product_id = fields.Many2one( + 'product.product', + string='Discount Product', + compute='_compute_payment_program_discount_product_id', + readonly=True, + help="Product used in the sales order to apply the discount." + ) + # Technical field used for a label available_on = fields.Boolean("Available On", store=False, help=""" @@ -183,6 +191,14 @@ class LoyaltyProgram(models.Model): for program in self: program.is_payment_program = program.program_type in ('gift_card', 'ewallet') + @api.depends('reward_ids.discount_line_product_id') + def _compute_payment_program_discount_product_id(self): + for program in self: + if program.is_payment_program: + program.payment_program_discount_product_id = program.reward_ids[0].discount_line_product_id + else: + program.payment_program_discount_product_id = False + @api.model def _program_items_name(self): return { diff --git a/addons/loyalty/views/loyalty_program_views.xml b/addons/loyalty/views/loyalty_program_views.xml index 4a3267a3cd5..04e30d0ebed 100644 --- a/addons/loyalty/views/loyalty_program_views.xml +++ b/addons/loyalty/views/loyalty_program_views.xml @@ -82,6 +82,7 @@ + diff --git a/addons/loyalty/views/loyalty_reward_views.xml b/addons/loyalty/views/loyalty_reward_views.xml index e9fa7028472..f43dfb314e3 100644 --- a/addons/loyalty/views/loyalty_reward_views.xml +++ b/addons/loyalty/views/loyalty_reward_views.xml @@ -55,6 +55,7 @@ +