Skip to content

Commit

Permalink
[MIG] sale_coupon_criteria_multi_product: Migration to 16.0 and renam…
Browse files Browse the repository at this point in the history
…e to sale_loyalty_criteria_multi_product
  • Loading branch information
ernesto-garcia-tecnativa committed Oct 16, 2023
1 parent c71d3cc commit b5ee08e
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 96 deletions.
16 changes: 8 additions & 8 deletions sale_loyalty_criteria_multi_product/README.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
======================================
Coupons multi product criteria in sale
Loyalty multi product criteria in sale
======================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5608f6887448744476c7634f8c9ea1bbe696e6fb56c02e60ebaad6680f5d5e98
!! source digest: sha256:60ab5d35e66cdbb4502d15ae37cbc061c3f9e9f571ef60d08c78e9d98b0154ad
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
Expand All @@ -17,18 +17,18 @@ Coupons multi product criteria in sale
: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/sale_coupon_criteria_multi_product
:target: https://github.com/OCA/sale-promotion/tree/16.0-mig-sale_coupon_criteria_multi_product/sale_loyalty_criteria_multi_product
: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-sale_coupon_criteria_multi_product
:target: https://translation.odoo-community.org/projects/sale-promotion-16-0-mig-sale_coupon_criteria_multi_product/sale-promotion-16-0-mig-sale_coupon_criteria_multi_product-sale_loyalty_criteria_multi_product
: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-mig-sale_coupon_criteria_multi_product
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Module that extends from *coupon_criteria_multi_product* and allows to
Module that extends from *loyalty_criteria_multi_product* and allows to
use it's configuration in sale orders.

**Table of contents**
Expand All @@ -52,7 +52,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:%20sale_coupon_criteria_multi_product%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:%20sale_loyalty_criteria_multi_product%0Aversion:%2016.0-mig-sale_coupon_criteria_multi_product%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 Down Expand Up @@ -99,6 +99,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/sale_coupon_criteria_multi_product>`_ project on GitHub.
This module is part of the `OCA/sale-promotion <https://github.com/OCA/sale-promotion/tree/16.0-mig-sale_coupon_criteria_multi_product/sale_loyalty_criteria_multi_product>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
6 changes: 3 additions & 3 deletions sale_loyalty_criteria_multi_product/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright 2021 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Coupons multi product criteria in sale",
"name": "Loyalty multi product criteria in sale",
"summary": "Allows to set as promotion criteria multi-product conditions",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"development_status": "Production/Stable",
"category": "Sale",
"website": "https://github.com/OCA/sale-promotion",
"author": "Tecnativa, Odoo Community Association (OCA)",
"maintainers": ["chienandalu"],
"license": "AGPL-3",
"depends": ["coupon_criteria_multi_product", "sale_coupon"],
"depends": ["loyalty_criteria_multi_product", "sale_loyalty"],
}
6 changes: 3 additions & 3 deletions sale_loyalty_criteria_multi_product/i18n/es.po
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_coupon_criteria_multi_product
# * sale_loyalty_criteria_multi_product
#
msgid ""
msgstr ""
Expand All @@ -17,8 +17,8 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 3.2.2\n"

#. module: sale_coupon_criteria_multi_product
#: model:ir.model,name:sale_coupon_criteria_multi_product.model_coupon_program
#. module: sale_loyalty_criteria_multi_product
#: model:ir.model,name:sale_loyalty_criteria_multi_product.model_coupon_program
msgid "Coupon display on a website"
msgstr ""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_coupon_criteria_multi_product
# * sale_loyalty_criteria_multi_product
#
msgid ""
msgstr ""
Expand All @@ -13,7 +13,7 @@ msgstr ""
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: sale_coupon_criteria_multi_product
#: model:ir.model,name:sale_coupon_criteria_multi_product.model_coupon_program
#. module: sale_loyalty_criteria_multi_product
#: model:ir.model,name:sale_loyalty_criteria_multi_product.model_coupon_program
msgid "Coupon display on a website"
msgstr ""
3 changes: 2 additions & 1 deletion sale_loyalty_criteria_multi_product/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import coupon_program
from . import loyalty_program
from . import sale_order
60 changes: 0 additions & 60 deletions sale_loyalty_criteria_multi_product/models/coupon_program.py

This file was deleted.

16 changes: 16 additions & 0 deletions sale_loyalty_criteria_multi_product/models/loyalty_program.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2021 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models


class LoyaltyProgram(models.Model):
_inherit = "loyalty.program"

def _get_valid_products_multi_product(self, products, rule):
"""Return valid products depending on the rule repeat product setting. Then
the main method will check if the minimum quantities are acomplished."""
if rule.repeat_product:
return products.browse([x.id for x in rule.product_ids if x in products])
if not all([x in products for x in rule.product_ids]):
return self.env["product.product"]
return rule.product_ids
61 changes: 61 additions & 0 deletions sale_loyalty_criteria_multi_product/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2021 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models


class SaleOrder(models.Model):
_inherit = "sale.order"

def _program_check_compute_points(self, programs):
"""
Updates applied programs's given points with the current state of the order.
Checks automatic programs for applicability.
Updates applied rewards using the new points and the current state of the order
(for example with % discounts).
"""
self.ensure_one()
domain_programs = programs.filtered(lambda x: x.loyalty_criteria == "domain")
multi_product_programs = (programs - domain_programs).filtered(
"loyalty_criteria_ids"
)
# We'll return them altogether
valid_domain_criteria_programs = super()._program_check_compute_points(
domain_programs
)
order_lines = self.order_line.filtered(
lambda line: line.product_id
) - self.order_line.filtered("is_reward_line")
products = order_lines.mapped("product_id")
products_qties = dict.fromkeys(products, 0)
for line in order_lines:
products_qties[line.product_id] += line.product_uom_qty
valid_multi_product_criteria_programs = dict.fromkeys(
multi_product_programs, dict()
)

for program in multi_product_programs:
criterias_are_valid = True
for criteria in program.loyalty_criteria_ids:
valid_products = program._get_valid_products_multi_product(
products, criteria
)
if not valid_products:
criterias_are_valid = False
ordered_rule_products_qty = sum(
products_qties[p] for p in valid_products
)
if ordered_rule_products_qty < criteria.criterian_min_quantity:
criterias_are_valid = False
if not criterias_are_valid:
valid_multi_product_criteria_programs[program] = {
"error": "You don't have the required "
"product quantities on your sales order."
}
else:
# bypass: forced the points of program
# because the original function takes this from rules
valid_multi_product_criteria_programs[program] = {"points": [1]}
return {
**valid_domain_criteria_programs,
**valid_multi_product_criteria_programs,
}
2 changes: 1 addition & 1 deletion sale_loyalty_criteria_multi_product/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Module that extends from *coupon_criteria_multi_product* and allows to
Module that extends from *loyalty_criteria_multi_product* and allows to
use it's configuration in sale orders.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>Coupons multi product criteria in sale</title>
<title>Loyalty multi product criteria in sale</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,17 +360,17 @@
</style>
</head>
<body>
<div class="document" id="coupons-multi-product-criteria-in-sale">
<h1 class="title">Coupons multi product criteria in sale</h1>
<div class="document" id="loyalty-multi-product-criteria-in-sale">
<h1 class="title">Loyalty multi product criteria in sale</h1>

<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5608f6887448744476c7634f8c9ea1bbe696e6fb56c02e60ebaad6680f5d5e98
!! source digest: sha256:60ab5d35e66cdbb4502d15ae37cbc061c3f9e9f571ef60d08c78e9d98b0154ad
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/sale-promotion/tree/15.0/sale_coupon_criteria_multi_product"><img alt="OCA/sale-promotion" src="https://img.shields.io/badge/github-OCA%2Fsale--promotion-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sale-promotion-15-0/sale-promotion-15-0-sale_coupon_criteria_multi_product"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/sale-promotion&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Module that extends from <em>coupon_criteria_multi_product</em> and allows to
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/sale-promotion/tree/16.0-mig-sale_coupon_criteria_multi_product/sale_loyalty_criteria_multi_product"><img alt="OCA/sale-promotion" src="https://img.shields.io/badge/github-OCA%2Fsale--promotion-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sale-promotion-16-0-mig-sale_coupon_criteria_multi_product/sale-promotion-16-0-mig-sale_coupon_criteria_multi_product-sale_loyalty_criteria_multi_product"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/sale-promotion&amp;target_branch=16.0-mig-sale_coupon_criteria_multi_product"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Module that extends from <em>loyalty_criteria_multi_product</em> and allows to
use it’s configuration in sale orders.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
Expand Down Expand Up @@ -399,7 +399,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/sale-promotion/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/sale-promotion/issues/new?body=module:%20sale_coupon_criteria_multi_product%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/sale-promotion/issues/new?body=module:%20sale_loyalty_criteria_multi_product%0Aversion:%2016.0-mig-sale_coupon_criteria_multi_product%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -435,7 +435,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/chienandalu"><img alt="chienandalu" src="https://github.com/chienandalu.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/sale-promotion/tree/15.0/sale_coupon_criteria_multi_product">OCA/sale-promotion</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/sale-promotion/tree/16.0-mig-sale_coupon_criteria_multi_product/sale_loyalty_criteria_multi_product">OCA/sale-promotion</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion sale_loyalty_criteria_multi_product/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import test_sale_coupon_criteria_multi_product
from . import test_sale_loyalty_criteria_multi_product
Loading

0 comments on commit b5ee08e

Please sign in to comment.