Skip to content

Commit

Permalink
[IMP-FIX] loyalty_multi_gift: Continue migration to v16
Browse files Browse the repository at this point in the history
- Added migration script
- Adapt test
- Adapt methods and views

TT44321
  • Loading branch information
pilarvargas-tecnativa committed Feb 2, 2024
1 parent 0ee1ad2 commit 5cd0bbd
Show file tree
Hide file tree
Showing 13 changed files with 334 additions and 120 deletions.
39 changes: 29 additions & 10 deletions loyalty_multi_gift/README.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
==================
Coupons multi gift
Loyalty multi gift
==================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:55e1550e878f90717902833da0b3bcedb492be8f33b0211ee608ecb32f85968b
!! source digest: sha256:f3338dddec7e1ca070ed8a53fe498a1ebbdd1be1578d88d2bd3b72be437188f8
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand All @@ -17,13 +17,13 @@ Coupons multi gift
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--promotion-lightgray.png?logo=github
:target: https://github.com/OCA/sale-promotion/tree/15.0/coupon_multi_gift
:target: https://github.com/OCA/sale-promotion/tree/16.0/loyalty_multi_gift
:alt: OCA/sale-promotion
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-promotion-15-0/sale-promotion-15-0-coupon_multi_gift
:target: https://translation.odoo-community.org/projects/sale-promotion-16-0/sale-promotion-16-0-loyalty_multi_gift
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-promotion&target_branch=15.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-promotion&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -35,15 +35,33 @@ This module allows to define multiple reward products on promotions.
.. contents::
:local:

Use Cases / Context
===================

For the 'buy_x_get_y' type promotion, the 'Reward_type' field is restricted to the 'Product'
option only and the possibility to select 'Multigift' is disabled. This restriction is implemented
because, in this scenario, the 'reward_type' field becomes 'readonly'.

It is crucial to note that modifying the values displayed in this field to set different
values according to the type of promotion may generate conflicts with other modules that
contribute to the configuration of this same field. Therefore, it is recommended not to
alter these values directly, as this may affect the consistency and functionality of other
components of the system.

To configure similar promotions, it is suggested to modify another type of promotion by
adapting its rules and rewards according to specific needs. This provides a more secure
and consistent way to manage custom configurations without compromising the integrity of
the system.

Configuration
=============

To configure multiple product rewards:

#. Go to *Sales > Catalog > Coupon Programs* and select or create a new one.
#. Go to *Sales > Products > Discount & Loyalty* and select or create a new one.
#. Choose the criteria of appliance you want to use and the minimum quantities, that
will be used to calculate the times the rewards can be applied.
#. On the *Reward Type* field choose *Multi Gift*.
#. On the *Program Type* field choose *Multi Gift*.
#. You'll see a now the *Gift list* on which you can add the products you want to give
away and the quantities for each of them.

Expand All @@ -58,7 +76,7 @@ An example:

With a minimum quantity of 3, for every 3 units of products that fulfill the domain
we'd get 3 units of A and 2 of B. So if the valid products quantities are 11, we'd
get 9 of product A and 6 of product B.
get 3 of product A and 2 of product B.

Usage
=====
Expand All @@ -72,7 +90,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-promotion/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/sale-promotion/issues/new?body=module:%20coupon_multi_gift%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/sale-promotion/issues/new?body=module:%20loyalty_multi_gift%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -90,6 +108,7 @@ Contributors
* `Tecnativa <https://www.tecnativa.com>`_:

* David Vidal
* Pilar Vargas

* `Domatix <https://www.domatix.com>`_:

Expand All @@ -116,6 +135,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-chienandalu|

This module is part of the `OCA/sale-promotion <https://github.com/OCA/sale-promotion/tree/15.0/coupon_multi_gift>`_ project on GitHub.
This module is part of the `OCA/sale-promotion <https://github.com/OCA/sale-promotion/tree/16.0/loyalty_multi_gift>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion loyalty_multi_gift/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"maintainers": ["chienandalu"],
"license": "AGPL-3",
"depends": ["loyalty"],
"data": ["views/loyalty_program_views.xml", "security/ir.model.access.csv"],
"data": ["views/loyalty_reward_views.xml", "security/ir.model.access.csv"],
}
23 changes: 23 additions & 0 deletions loyalty_multi_gift/migrations/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2023 Tecnativa - Pilar Vargas
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade

_renamed_fields = [
(
"loyalty.reward",
"loyalty_reward",
"coupon_multi_gift_ids",
"loyalty_multi_gift_ids",
),
]


@openupgrade.migrate()
def migrate(env, version):
openupgrade.rename_fields(env, _renamed_fields)
openupgrade.rename_models(
env.cr, [("coupon.reward.product_line", "loyalty.reward.product_line")]
)
openupgrade.rename_tables(
env.cr, [("coupon_reward_product_line", "loyalty_reward_product_line")]
)
41 changes: 25 additions & 16 deletions loyalty_multi_gift/models/loyalty_reward.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,37 @@ class LoyaltyReward(models.Model):
inverse_name="reward_id",
string="Gift list",
)
multi_gift = fields.Boolean(compute="_compute_multi_gift")
reward_type = fields.Selection(
selection_add=[("multi_gift", "Multi Gift")],
ondelete={"multi_gift": "set default"},
)

def name_get(self):
"""Add complete description for the multi gift reward type."""
res = super().name_get()
for reward in self.filtered(lambda x: x.program_type == "multi_gift"):
reward_string = _("Free Products - %(name)s") % {
"name": ", ".join(
f"{reward.reward_product_quantity}x "
f"{fields.first(reward.reward_product_ids).name}"
for reward in reward.loyalty_multi_gift_ids
@api.depends("reward_type", "loyalty_multi_gift_ids.reward_product_ids")
def _compute_multi_gift(self):
for reward in self:
reward.multi_gift = (
reward.reward_type == "multi_gift"
and len(reward.loyalty_multi_gift_ids) > 0
)

@api.depends("loyalty_multi_gift_ids.reward_product_ids")
def _compute_description(self):
res = super()._compute_description()
for reward in self:
if reward.reward_type == "multi_gift":
reward_string = ""
products = self.env["product.product"].browse(
reward.loyalty_multi_gift_ids.reward_default_product_id.ids
)
}
res.append((reward.id, reward_string))
product_names = products.with_context(
display_default_code=False
).mapped("display_name")
if len(products) == 0:
reward_string = _("Multi Gift")
else:
reward_string = _("Multi Gift - [%s]") % ", ".join(product_names)
reward.description = reward_string
return res


Expand All @@ -43,7 +57,6 @@ class LoyaltyGift(models.Model):
reward_default_product_id = fields.Many2one(
comodel_name="product.product",
compute="_compute_reward_default_product_id",
inverse="_inverse_reward_default_product_id",
readonly=False,
)
reward_product_ids = fields.Many2many(
Expand All @@ -60,10 +73,6 @@ def _compute_reward_default_product_id(self):
for line in self:
line.reward_default_product_id = fields.first(line.reward_product_ids)

def _inverse_reward_default_product_id(self):
for line in self.filtered("reward_default_product_id"):
line.reward_product_ids = line.reward_default_product_id

@api.onchange("reward_product_ids")
def onchange_reward_product_ids(self):
self.reward_default_product_id = fields.first(self.reward_product_ids)._origin
2 changes: 1 addition & 1 deletion loyalty_multi_gift/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ An example:

With a minimum quantity of 3, for every 3 units of products that fulfill the domain
we'd get 3 units of A and 2 of B. So if the valid products quantities are 11, we'd
get 9 of product A and 6 of product B.
get 3 of product A and 2 of product B.
14 changes: 14 additions & 0 deletions loyalty_multi_gift/readme/CONTEXT.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
For the 'buy_x_get_y' type promotion, the 'Reward_type' field is restricted to the 'Product'
option only and the possibility to select 'Multigift' is disabled. This restriction is implemented
because, in this scenario, the 'reward_type' field becomes 'readonly'.

It is crucial to note that modifying the values displayed in this field to set different
values according to the type of promotion may generate conflicts with other modules that
contribute to the configuration of this same field. Therefore, it is recommended not to
alter these values directly, as this may affect the consistency and functionality of other
components of the system.

To configure similar promotions, it is suggested to modify another type of promotion by
adapting its rules and rewards according to specific needs. This provides a more secure
and consistent way to manage custom configurations without compromising the integrity of
the system.
1 change: 1 addition & 0 deletions loyalty_multi_gift/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
* `Tecnativa <https://www.tecnativa.com>`_:

* David Vidal
* Pilar Vargas

* `Domatix <https://www.domatix.com>`_:

Expand Down
Loading

0 comments on commit 5cd0bbd

Please sign in to comment.