diff --git a/loyalty_criteria_multi_product/__manifest__.py b/loyalty_criteria_multi_product/__manifest__.py index a80da0b2..e83830db 100644 --- a/loyalty_criteria_multi_product/__manifest__.py +++ b/loyalty_criteria_multi_product/__manifest__.py @@ -1,7 +1,7 @@ # Copyright 2021 Tecnativa - David Vidal # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { - "name": "Coupons multi product criteria", + "name": "Loyalty multi product criteria", "summary": "Allows to set as promotion criteria multi-product conditions", "version": "16.0.1.0.0", "development_status": "Production/Stable", @@ -10,6 +10,6 @@ "author": "Tecnativa, Odoo Community Association (OCA)", "maintainers": ["chienandalu"], "license": "AGPL-3", - "depends": ["loyalty"], - "data": ["views/loyalty_rule_views.xml", "security/ir.model.access.csv"], + "depends": ["loyalty", "sales_team"], + "data": ["views/loyalty_rule_views.xml"], } diff --git a/loyalty_criteria_multi_product/i18n/coupon_criteria_multi_product.pot b/loyalty_criteria_multi_product/i18n/coupon_criteria_multi_product.pot deleted file mode 100644 index 8c0cea5a..00000000 --- a/loyalty_criteria_multi_product/i18n/coupon_criteria_multi_product.pot +++ /dev/null @@ -1,129 +0,0 @@ -# Translation of Odoo Server. -# This file contains the translation of the following modules: -# * coupon_criteria_multi_product -# -msgid "" -msgstr "" -"Project-Id-Version: Odoo Server 15.0\n" -"Report-Msgid-Bugs-To: \n" -"Last-Translator: \n" -"Language-Team: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: \n" -"Plural-Forms: \n" - -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,help:coupon_criteria_multi_product.field_coupon_program__coupon_criteria -msgid "" -"- Domain: Standard behavior. The products are evaluated by domain.\n" -"- Multi product: different rules can be applied to different products and all of the have to be fulfilled" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,help:coupon_criteria_multi_product.field_coupon_criteria__repeat_product -msgid "Can product quantities count multiple times or not" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model:ir.model,name:coupon_criteria_multi_product.model_coupon_criteria -msgid "Coupon Multi Product Criteria" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_program__coupon_criteria -msgid "Coupon criteria" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model:ir.model,name:coupon_criteria_multi_product.model_coupon_program -msgid "Coupon display on a website" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__create_uid -msgid "Created by" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__create_date -msgid "Created on" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__display_name -msgid "Display Name" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model:ir.model.fields.selection,name:coupon_criteria_multi_product.selection__coupon_program__coupon_criteria__domain -msgid "Domain" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__id -msgid "ID" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria____last_update -msgid "Last Modified on" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__write_uid -msgid "Last Updated by" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__write_date -msgid "Last Updated on" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__rule_min_quantity -msgid "Min. Quantity" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,help:coupon_criteria_multi_product.field_coupon_criteria__rule_min_quantity -msgid "Minimum required product quantity to get the reward" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model:ir.model.fields.selection,name:coupon_criteria_multi_product.selection__coupon_program__coupon_criteria__multi_product -msgid "Multi Product" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_program__coupon_criteria_ids -msgid "Multi Product Criterias" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__product_ids -msgid "Product" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__program_id -msgid "Program" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model_terms:ir.ui.view,arch_db:coupon_criteria_multi_product.coupon_program_view_form_common -msgid "Qty" -msgstr "" - -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__repeat_product -msgid "Repeat" -msgstr "" - -#. module: coupon_criteria_multi_product -#: code:addons/coupon_criteria_multi_product/models/coupon_criteria.py:0 -#, python-format -msgid "" -"The minimum quantity can't be different from the number of products. Set the" -" rule as repeatable to avoid this constraint." -msgstr "" diff --git a/loyalty_criteria_multi_product/i18n/es.po b/loyalty_criteria_multi_product/i18n/es.po index 5fb60cdc..c53be7b3 100644 --- a/loyalty_criteria_multi_product/i18n/es.po +++ b/loyalty_criteria_multi_product/i18n/es.po @@ -1,6 +1,6 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * coupon_criteria_multi_product +# * loyalty_criteria_multi_product # msgid "" msgstr "" @@ -17,8 +17,8 @@ msgstr "" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "X-Generator: Poedit 3.2.2\n" -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,help:coupon_criteria_multi_product.field_coupon_program__coupon_criteria +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,help:loyalty_criteria_multi_product.field_coupon_program__coupon_criteria msgid "" "- Domain: Standard behavior. The products are evaluated by domain.\n" "- Multi product: different rules can be applied to different products and " @@ -28,108 +28,108 @@ msgstr "" "- Multiproducto: pueden aplicarse distintas normas a distintos productos y " "todas ellas deben cumplirse" -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,help:coupon_criteria_multi_product.field_coupon_criteria__repeat_product +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,help:loyalty_criteria_multi_product.field_coupon_criteria__repeat_product msgid "Can product quantities count multiple times or not" msgstr "Las cantidades de productos pueden contarse varias veces o no" -#. module: coupon_criteria_multi_product -#: model:ir.model,name:coupon_criteria_multi_product.model_coupon_criteria +#. module: loyalty_criteria_multi_product +#: model:ir.model,name:loyalty_criteria_multi_product.model_coupon_criteria msgid "Coupon Multi Product Criteria" msgstr "Criterios de cupones multiproducto" -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_program__coupon_criteria +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_program__coupon_criteria msgid "Coupon criteria" msgstr "Criterios del cupón" -#. module: coupon_criteria_multi_product -#: model:ir.model,name:coupon_criteria_multi_product.model_coupon_program +#. module: loyalty_criteria_multi_product +#: model:ir.model,name:loyalty_criteria_multi_product.model_coupon_program msgid "Coupon display on a website" msgstr "" -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__create_uid +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__create_uid msgid "Created by" msgstr "Creado por" -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__create_date +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__create_date msgid "Created on" msgstr "Creado el" -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__display_name +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__display_name msgid "Display Name" msgstr "Nombre mostrado" -#. module: coupon_criteria_multi_product -#: model:ir.model.fields.selection,name:coupon_criteria_multi_product.selection__coupon_program__coupon_criteria__domain +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields.selection,name:loyalty_criteria_multi_product.selection__coupon_program__coupon_criteria__domain msgid "Domain" msgstr "Aplicar en el dominio de los productos" -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__id +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__id msgid "ID" msgstr "ID" -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria____last_update +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria____last_update msgid "Last Modified on" msgstr "Última modificación el" -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__write_uid +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__write_uid msgid "Last Updated by" msgstr "Última actualización por" -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__write_date +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__write_date msgid "Last Updated on" msgstr "Última actualización en" -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__rule_min_quantity +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__rule_min_quantity msgid "Min. Quantity" msgstr "Cantidad mínima" -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,help:coupon_criteria_multi_product.field_coupon_criteria__rule_min_quantity +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,help:loyalty_criteria_multi_product.field_coupon_criteria__rule_min_quantity msgid "Minimum required product quantity to get the reward" msgstr "Cantidad mínima de producto requerida para obtener la recompensa" -#. module: coupon_criteria_multi_product -#: model:ir.model.fields.selection,name:coupon_criteria_multi_product.selection__coupon_program__coupon_criteria__multi_product +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields.selection,name:loyalty_criteria_multi_product.selection__coupon_program__coupon_criteria__multi_product msgid "Multi Product" msgstr "Multiproducto" -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_program__coupon_criteria_ids +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_program__coupon_criteria_ids msgid "Multi Product Criterias" msgstr "Criterios de multiproducto" -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__product_ids +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__product_ids msgid "Product" msgstr "" -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__program_id +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__program_id msgid "Program" msgstr "Programa" -#. module: coupon_criteria_multi_product -#: model_terms:ir.ui.view,arch_db:coupon_criteria_multi_product.coupon_program_view_form_common +#. module: loyalty_criteria_multi_product +#: model_terms:ir.ui.view,arch_db:loyalty_criteria_multi_product.coupon_program_view_form_common msgid "Qty" msgstr "Cantidad" -#. module: coupon_criteria_multi_product -#: model:ir.model.fields,field_description:coupon_criteria_multi_product.field_coupon_criteria__repeat_product +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__repeat_product msgid "Repeat" msgstr "Repetir" -#. module: coupon_criteria_multi_product -#: code:addons/coupon_criteria_multi_product/models/coupon_criteria.py:0 +#. module: loyalty_criteria_multi_product +#: code:addons/loyalty_criteria_multi_product/models/coupon_criteria.py:0 #, python-format msgid "" "The minimum quantity can't be different from the number of products. Set the " diff --git a/loyalty_criteria_multi_product/i18n/loyalty_criteria_multi_product.pot b/loyalty_criteria_multi_product/i18n/loyalty_criteria_multi_product.pot new file mode 100644 index 00000000..a92e4ccd --- /dev/null +++ b/loyalty_criteria_multi_product/i18n/loyalty_criteria_multi_product.pot @@ -0,0 +1,129 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * loyalty_criteria_multi_product +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,help:loyalty_criteria_multi_product.field_coupon_program__coupon_criteria +msgid "" +"- Domain: Standard behavior. The products are evaluated by domain.\n" +"- Multi product: different rules can be applied to different products and all of the have to be fulfilled" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,help:loyalty_criteria_multi_product.field_coupon_criteria__repeat_product +msgid "Can product quantities count multiple times or not" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model:ir.model,name:loyalty_criteria_multi_product.model_coupon_criteria +msgid "Coupon Multi Product Criteria" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_program__coupon_criteria +msgid "Coupon criteria" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model:ir.model,name:loyalty_criteria_multi_product.model_coupon_program +msgid "Coupon display on a website" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__create_uid +msgid "Created by" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__create_date +msgid "Created on" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__display_name +msgid "Display Name" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields.selection,name:loyalty_criteria_multi_product.selection__coupon_program__coupon_criteria__domain +msgid "Domain" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__id +msgid "ID" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria____last_update +msgid "Last Modified on" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__write_date +msgid "Last Updated on" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__rule_min_quantity +msgid "Min. Quantity" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,help:loyalty_criteria_multi_product.field_coupon_criteria__rule_min_quantity +msgid "Minimum required product quantity to get the reward" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields.selection,name:loyalty_criteria_multi_product.selection__coupon_program__coupon_criteria__multi_product +msgid "Multi Product" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_program__coupon_criteria_ids +msgid "Multi Product Criterias" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__product_ids +msgid "Product" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__program_id +msgid "Program" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model_terms:ir.ui.view,arch_db:loyalty_criteria_multi_product.coupon_program_view_form_common +msgid "Qty" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: model:ir.model.fields,field_description:loyalty_criteria_multi_product.field_coupon_criteria__repeat_product +msgid "Repeat" +msgstr "" + +#. module: loyalty_criteria_multi_product +#: code:addons/loyalty_criteria_multi_product/models/coupon_criteria.py:0 +#, python-format +msgid "" +"The minimum quantity can't be different from the number of products. Set the" +" rule as repeatable to avoid this constraint." +msgstr "" diff --git a/loyalty_criteria_multi_product/migrations/15.0.1.0.0/pre-migration.py b/loyalty_criteria_multi_product/migrations/15.0.1.0.0/pre-migration.py deleted file mode 100644 index cac374fd..00000000 --- a/loyalty_criteria_multi_product/migrations/15.0.1.0.0/pre-migration.py +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2023 Tecnativa - Stefan Ungureanu -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from openupgradelib import openupgrade - -_model_renames = [ - ("sale.coupon.criteria", "coupon.criteria"), -] -_table_renames = [("sale_coupon_criteria", "coupon_criteria")] - - -@openupgrade.migrate() -def migrate(env, version): - openupgrade.rename_models(env.cr, _model_renames) - openupgrade.rename_tables(env.cr, _table_renames) diff --git a/loyalty_criteria_multi_product/models/__init__.py b/loyalty_criteria_multi_product/models/__init__.py index 95a819fc..a1128c3a 100644 --- a/loyalty_criteria_multi_product/models/__init__.py +++ b/loyalty_criteria_multi_product/models/__init__.py @@ -1,3 +1 @@ -from . import rule_criteria from . import loyalty_rule -from . import loyalty_program diff --git a/loyalty_criteria_multi_product/models/loyalty_program.py b/loyalty_criteria_multi_product/models/loyalty_program.py deleted file mode 100644 index 8a978884..00000000 --- a/loyalty_criteria_multi_product/models/loyalty_program.py +++ /dev/null @@ -1,19 +0,0 @@ -# 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(self, products): - """ - Returns a dict containing the products that match per rule of the program - """ - rule_products = super()._get_valid_products(products) - for rule in self.rule_ids: - if rule.rule_criteria_ids and rule.rule_criteria_ids[0].repeat_product: - rule_products[rule] = products - if not all([x in products for x in rule.rule_criteria_ids.product_ids]): - rule_products[rule] = self.env["product.product"] - return rule_products diff --git a/loyalty_criteria_multi_product/models/loyalty_rule.py b/loyalty_criteria_multi_product/models/loyalty_rule.py index a7aca339..4ce514eb 100644 --- a/loyalty_criteria_multi_product/models/loyalty_rule.py +++ b/loyalty_criteria_multi_product/models/loyalty_rule.py @@ -1,47 +1,31 @@ # Copyright 2021 Tecnativa - David Vidal # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import api, fields, models +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError class LoyaltyRule(models.Model): _inherit = "loyalty.rule" - rule_criteria = fields.Selection( - selection=[("domain", "Domain"), ("multi_product", "Multi Product")], - string="Rule criteria", - help="- Domain: Standard behavior. The products are evaluated by domain.\n" - "- Multi product: different rules can be applied to different products " - "and all of the have to be fulfilled", - default="domain", + repeat_product = fields.Boolean( + string="Repeat", + help="Can product quantities count multiple times or not", ) - rule_criteria_ids = fields.One2many( - string="Multi Product Criterias", - comodel_name="rule.criteria", - inverse_name="rule_id", - ) - - @api.onchange("coupon_criteria") - def _onchange_coupon_criteria(self): - """Clear domain so we clear some other fields from the view""" - if self.coupon_criteria == "multi_product": - self.rule_products_domain = False - - def _get_valid_products_multi_product(self, products, criteria): - """Return valid products depending on the criteria repeat product setting. Then - the main method will check if the minimum quantities are acomplished.""" - if criteria.repeat_product: - return products.browse( - [x.id for x in criteria.product_ids if x in products] - ) - if not all([x in products for x in criteria.product_ids]): - return self.env["product.product"] - return criteria.product_ids - def _get_valid_product_domain(self): - self.ensure_one() - if self.rule_criteria == "multi_product": - result_domain = [("id", "in", self.rule_criteria_ids.product_ids.ids)] - else: - result_domain = super()._get_valid_product_domain() + @api.onchange("product_ids", "repeat_product") + def _onchange_rule_min_quantity(self): + """Set the minimum quantity automatically to prevent errors when the rule + isn't set to no repeat""" + for rule in self.filtered(lambda x: x.product_ids and not x.repeat_product): + rule.minimum_qty = len(rule.product_ids) - return result_domain + @api.constrains("minimum_qty") + def _check_minimum_qty(self): + for rule in self.filtered(lambda x: x.product_ids and not x.repeat_product): + if len(rule.product_ids) != rule.minimum_qty: + raise ValidationError( + _( + "The minimum quantity can't be different from the number of " + "products. Set the rule as repeatable to avoid this constraint." + ) + ) diff --git a/loyalty_criteria_multi_product/models/rule_criteria.py b/loyalty_criteria_multi_product/models/rule_criteria.py deleted file mode 100644 index aa0d0107..00000000 --- a/loyalty_criteria_multi_product/models/rule_criteria.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright 2021 Tecnativa - David Vidal -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import _, api, fields, models -from odoo.exceptions import ValidationError - - -class RuleCriteria(models.Model): - _name = "rule.criteria" - _description = "Coupon Multi Product Criteria" - - rule_id = fields.Many2one( - comodel_name="loyalty.rule", - ) - rule_min_quantity = fields.Integer( - string="Min. Quantity", - compute="_compute_rule_min_quantity", - store=True, - readonly=False, - help="Minimum required product quantity to get the reward", - ) - product_ids = fields.Many2many( - comodel_name="product.product", - required=True, - ) - repeat_product = fields.Boolean( - string="Repeat", - help="Can product quantities count multiple times or not", - ) - - @api.depends("product_ids", "repeat_product") - def _compute_rule_min_quantity(self): - """Set the minimum quantity automatically to prevent errors when the rule - isn't set to no repeat""" - for criteria in self.filtered(lambda x: x.product_ids and not x.repeat_product): - criteria.rule_min_quantity = len(criteria.product_ids) - - @api.constrains("rule_min_quantity") - def _check_rule_min_qty(self): - for criteria in self.filtered(lambda x: x.product_ids and not x.repeat_product): - if len(criteria.product_ids) != criteria.rule_min_quantity: - raise ValidationError( - _( - "The minimum quantity can't be different from the number of " - "products. Set the rule as repeatable to avoid this constraint." - ) - ) diff --git a/loyalty_criteria_multi_product/security/ir.model.access.csv b/loyalty_criteria_multi_product/security/ir.model.access.csv deleted file mode 100644 index fca58083..00000000 --- a/loyalty_criteria_multi_product/security/ir.model.access.csv +++ /dev/null @@ -1,3 +0,0 @@ -id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink -access_criteria_salesman,salesman,model_rule_criteria,sales_team.group_sale_salesman,1,0,0,0 -access_criteria_manager,criteria manager,model_rule_criteria,sales_team.group_sale_manager,1,1,1,1 diff --git a/loyalty_criteria_multi_product/tests/__init__.py b/loyalty_criteria_multi_product/tests/__init__.py index 9409e332..f82cd92c 100644 --- a/loyalty_criteria_multi_product/tests/__init__.py +++ b/loyalty_criteria_multi_product/tests/__init__.py @@ -1,2 +1,2 @@ -from . import test_sale_coupon_criteria_multi_product -from .test_sale_coupon_criteria_multi_product import TestCouponCriteriaMultiProduct +from . import test_loyalty_criteria_multi_product +from .test_loyalty_criteria_multi_product import TestLoyaltyCriteriaMultiProduct diff --git a/loyalty_criteria_multi_product/tests/test_sale_coupon_criteria_multi_product.py b/loyalty_criteria_multi_product/tests/test_loyalty_criteria_multi_product.py similarity index 57% rename from loyalty_criteria_multi_product/tests/test_sale_coupon_criteria_multi_product.py rename to loyalty_criteria_multi_product/tests/test_loyalty_criteria_multi_product.py index 3bbac957..e327c33c 100644 --- a/loyalty_criteria_multi_product/tests/test_sale_coupon_criteria_multi_product.py +++ b/loyalty_criteria_multi_product/tests/test_loyalty_criteria_multi_product.py @@ -3,7 +3,7 @@ from odoo.tests import Form, common -class TestCouponCriteriaMultiProduct(common.TransactionCase): +class TestLoyaltyCriteriaMultiProduct(common.TransactionCase): @classmethod def setUpClass(cls): super().setUpClass() @@ -33,17 +33,12 @@ def setUpClass(cls): cls.product_d = product_obj.create({"name": "Product A", "list_price": 80}) cls.product_e = product_obj.create({"name": "Product E", "list_price": 70}) cls.product_f = product_obj.create({"name": "Product F", "list_price": 60}) - coupon_program_form = Form( - cls.env["coupon.program"], - view="sale_coupon.sale_coupon_program_view_promo_program_form", + loyalty_program_form = Form( + cls.env["loyalty.program"], + view="loyalty.loyalty_program_view_form", ) - coupon_program_form.name = "Test Criteria Multi Product Program" - coupon_program_form.promo_code_usage = "no_code_needed" - coupon_program_form.reward_type = "discount" - coupon_program_form.discount_apply_on = "on_order" - coupon_program_form.discount_type = "percentage" - coupon_program_form.discount_percentage = 10 - coupon_program_form.coupon_criteria = "multi_product" + loyalty_program_form.name = "Test Criteria Multi Product Program" + loyalty_program_form.program_type = "promotion" # This is the set of criterias that the order must fulfill for the program to # be applied. # Qty | Products | Repeat @@ -51,14 +46,14 @@ def setUpClass(cls): # 1 | Prod A | # 2 | Prod B, Prod C | # 3 | Prod D, Prod E | Yes - with coupon_program_form.coupon_criteria_ids.new() as criteria: - criteria.product_ids.add(cls.product_a) - with coupon_program_form.coupon_criteria_ids.new() as criteria: - criteria.product_ids.add(cls.product_b) - criteria.product_ids.add(cls.product_c) - with coupon_program_form.coupon_criteria_ids.new() as criteria: - criteria.repeat_product = True - criteria.product_ids.add(cls.product_d) - criteria.product_ids.add(cls.product_e) - criteria.rule_min_quantity = 3 - cls.coupon_program = coupon_program_form.save() + with loyalty_program_form.rule_ids.new() as rule: + rule.product_ids.add(cls.product_a) + with loyalty_program_form.rule_ids.new() as rule: + rule.product_ids.add(cls.product_b) + rule.product_ids.add(cls.product_c) + with loyalty_program_form.rule_ids.new() as rule: + rule.repeat_product = True + rule.product_ids.add(cls.product_d) + rule.product_ids.add(cls.product_e) + rule.minimum_qty = 3 + cls.coupon_program = loyalty_program_form.save() diff --git a/loyalty_criteria_multi_product/views/loyalty_rule_views.xml b/loyalty_criteria_multi_product/views/loyalty_rule_views.xml index 7bf0a534..dc16d727 100644 --- a/loyalty_criteria_multi_product/views/loyalty_rule_views.xml +++ b/loyalty_criteria_multi_product/views/loyalty_rule_views.xml @@ -4,28 +4,8 @@ loyalty.rule - - - - - - - - - - - - {'invisible': [('rule_criteria', '!=', 'domain')]} - - - {'invisible': [('rule_criteria', '!=', 'domain')]} + +