diff --git a/loyalty_limit/README.rst b/loyalty_limit/README.rst index 49f8a4e1e..5a00aeb83 100644 --- a/loyalty_limit/README.rst +++ b/loyalty_limit/README.rst @@ -1,13 +1,13 @@ -============ -Coupon Limit -============ +============= +Loyalty Limit +============= .. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:3397b280713cd1ead33c29fac4f11cb62d90da8af4408c3f8ffb73ba2ced3e8e + !! source digest: sha256:c1badaa74b82a3331c9b943affe0cd31f7fffd24e1815aea5cacb0db04390fcf !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png @@ -17,13 +17,13 @@ Coupon Limit :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_limit + :target: https://github.com/OCA/sale-promotion/tree/16.0/loyalty_limit :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_limit + :target: https://translation.odoo-community.org/projects/sale-promotion-16-0/sale-promotion-16-0-loyalty_limit :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| @@ -42,7 +42,7 @@ Bug Tracker Bugs are tracked on `GitHub 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -61,6 +61,7 @@ Contributors * Pedro M. Baeza * David Vidal + * Pilar Vargas * `Akretion `_: @@ -87,6 +88,6 @@ Current `maintainer `__: |maintainer-chienandalu| -This module is part of the `OCA/sale-promotion `_ project on GitHub. +This module is part of the `OCA/sale-promotion `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/loyalty_limit/__manifest__.py b/loyalty_limit/__manifest__.py index da24626bc..0a12ebc5d 100644 --- a/loyalty_limit/__manifest__.py +++ b/loyalty_limit/__manifest__.py @@ -1,15 +1,15 @@ # Copyright 2021 Tecnativa - David Vidal # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { - "name": "Coupon Limit", + "name": "Loyalty Limit", "summary": "Restrict number of promotions per customer or salesman", - "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"], - "data": ["views/coupon_program_views.xml", "security/ir.model.access.csv"], + "depends": ["loyalty"], + "data": ["views/loyalty_program_views.xml", "security/ir.model.access.csv"], } diff --git a/loyalty_limit/i18n/coupon_limit.pot b/loyalty_limit/i18n/coupon_limit.pot deleted file mode 100644 index b743b24f2..000000000 --- a/loyalty_limit/i18n/coupon_limit.pot +++ /dev/null @@ -1,170 +0,0 @@ -# Translation of Odoo Server. -# This file contains the translation of the following modules: -# * coupon_limit -# -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_limit -#: model:ir.model,name:coupon_limit.model_coupon_rule -msgid "Coupon Rule" -msgstr "" - -#. module: coupon_limit -#: model:ir.model,name:coupon_limit.model_coupon_rule_salesmen_limit -msgid "Coupon Rule Salesmen limits" -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_rule_salesmen_limit__create_uid -msgid "Created by" -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_rule_salesmen_limit__create_date -msgid "Created on" -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_rule_salesmen_limit__display_name -msgid "Display Name" -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_rule_salesmen_limit__id -msgid "ID" -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,help:coupon_limit.field_coupon_program__rule_salesmen_strict_limit -#: model:ir.model.fields,help:coupon_limit.field_coupon_rule__rule_salesmen_strict_limit -msgid "" -"If marked, promotion will only be allowed for the list of salesmen with " -"their quantities" -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_rule_salesmen_limit____last_update -msgid "Last Modified on" -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_rule_salesmen_limit__write_uid -msgid "Last Updated by" -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_rule_salesmen_limit__write_date -msgid "Last Updated on" -msgstr "" - -#. module: coupon_limit -#: model_terms:ir.ui.view,arch_db:coupon_limit.sale_coupon_program_view_form_common -msgid "Max" -msgstr "" - -#. module: coupon_limit -#: model_terms:ir.ui.view,arch_db:coupon_limit.sale_coupon_program_view_form_common -msgid "Max. Customer Applications" -msgstr "" - -#. module: coupon_limit -#: model_terms:ir.ui.view,arch_db:coupon_limit.sale_coupon_program_view_form_common -msgid "Max. Salesmen Applications" -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_program__rule_max_customer_application -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_rule__rule_max_customer_application -msgid "Maximum Customer Applications" -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_rule_salesmen_limit__rule_max_salesman_application -msgid "Maximum Salesman Applications" -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,help:coupon_limit.field_coupon_rule_salesmen_limit__rule_max_salesman_application -msgid "Maximum times a salesman can apply a program. 0 for no limit." -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,help:coupon_limit.field_coupon_program__rule_salesmen_limit_ids -#: model:ir.model.fields,help:coupon_limit.field_coupon_rule__rule_salesmen_limit_ids -msgid "Maximum times salesmen can apply a program. Empty for no limit." -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,help:coupon_limit.field_coupon_program__rule_max_customer_application -#: model:ir.model.fields,help:coupon_limit.field_coupon_rule__rule_max_customer_application -msgid "" -"Maximum times that a program can be applied to a customer. 0 for no limit." -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_rule_salesmen_limit__rule_id -msgid "Rule" -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_rule_salesmen_limit__rule_user_id -msgid "Salesman" -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_program__rule_salesmen_limit_ids -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_rule__rule_salesmen_limit_ids -msgid "Salesmen Limits" -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_program__rule_salesmen_limit_count -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_rule__rule_salesmen_limit_count -msgid "Salesmen maximum promotions" -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_program__rule_salesmen_limit_used_count -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_rule__rule_salesmen_limit_used_count -msgid "Salesmen promotions used" -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_program__rule_salesmen_strict_limit -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_rule__rule_salesmen_strict_limit -msgid "Strict limit" -msgstr "" - -#. module: coupon_limit -#: model:ir.model.constraint,message:coupon_limit.constraint_coupon_rule_salesmen_limit_user_id_uniq -msgid "This salesman limit is already configured" -msgstr "" - -#. module: coupon_limit -#: model_terms:ir.ui.view,arch_db:coupon_limit.sale_coupon_program_view_form_common -msgid "Total limit" -msgstr "" - -#. module: coupon_limit -#: model_terms:ir.ui.view,arch_db:coupon_limit.sale_coupon_program_view_form_common -msgid "Total used" -msgstr "" - -#. module: coupon_limit -#: model:ir.model.fields,field_description:coupon_limit.field_coupon_rule_salesmen_limit__rule_times_used -msgid "Uses" -msgstr "" - -#. module: coupon_limit -#: model_terms:ir.ui.view,arch_db:coupon_limit.sale_coupon_program_view_form_common -msgid "used already)" -msgstr "" diff --git a/loyalty_limit/i18n/loyalty_limit.pot b/loyalty_limit/i18n/loyalty_limit.pot new file mode 100644 index 000000000..dc6761d19 --- /dev/null +++ b/loyalty_limit/i18n/loyalty_limit.pot @@ -0,0 +1,170 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * loyalty_limit +# +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_limit +#: model:ir.model,name:loyalty_limit.model_coupon_rule +msgid "Coupon Rule" +msgstr "" + +#. module: loyalty_limit +#: model:ir.model,name:loyalty_limit.model_coupon_rule_salesmen_limit +msgid "Coupon Rule Salesmen limits" +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_rule_salesmen_limit__create_uid +msgid "Created by" +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_rule_salesmen_limit__create_date +msgid "Created on" +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_rule_salesmen_limit__display_name +msgid "Display Name" +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_rule_salesmen_limit__id +msgid "ID" +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,help:loyalty_limit.field_coupon_program__rule_salesmen_strict_limit +#: model:ir.model.fields,help:loyalty_limit.field_coupon_rule__rule_salesmen_strict_limit +msgid "" +"If marked, promotion will only be allowed for the list of salesmen with " +"their quantities" +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_rule_salesmen_limit____last_update +msgid "Last Modified on" +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_rule_salesmen_limit__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_rule_salesmen_limit__write_date +msgid "Last Updated on" +msgstr "" + +#. module: loyalty_limit +#: model_terms:ir.ui.view,arch_db:loyalty_limit.sale_coupon_program_view_form_common +msgid "Max" +msgstr "" + +#. module: loyalty_limit +#: model_terms:ir.ui.view,arch_db:loyalty_limit.sale_coupon_program_view_form_common +msgid "Max. Customer Applications" +msgstr "" + +#. module: loyalty_limit +#: model_terms:ir.ui.view,arch_db:loyalty_limit.sale_coupon_program_view_form_common +msgid "Max. Salesmen Applications" +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_program__rule_max_customer_application +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_rule__rule_max_customer_application +msgid "Maximum Customer Applications" +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_rule_salesmen_limit__rule_max_salesman_application +msgid "Maximum Salesman Applications" +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,help:loyalty_limit.field_coupon_rule_salesmen_limit__rule_max_salesman_application +msgid "Maximum times a salesman can apply a program. 0 for no limit." +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,help:loyalty_limit.field_coupon_program__rule_salesmen_limit_ids +#: model:ir.model.fields,help:loyalty_limit.field_coupon_rule__rule_salesmen_limit_ids +msgid "Maximum times salesmen can apply a program. Empty for no limit." +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,help:loyalty_limit.field_coupon_program__rule_max_customer_application +#: model:ir.model.fields,help:loyalty_limit.field_coupon_rule__rule_max_customer_application +msgid "" +"Maximum times that a program can be applied to a customer. 0 for no limit." +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_rule_salesmen_limit__rule_id +msgid "Rule" +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_rule_salesmen_limit__rule_user_id +msgid "Salesman" +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_program__rule_salesmen_limit_ids +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_rule__rule_salesmen_limit_ids +msgid "Salesmen Limits" +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_program__rule_salesmen_limit_count +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_rule__rule_salesmen_limit_count +msgid "Salesmen maximum promotions" +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_program__rule_salesmen_limit_used_count +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_rule__rule_salesmen_limit_used_count +msgid "Salesmen promotions used" +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_program__rule_salesmen_strict_limit +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_rule__rule_salesmen_strict_limit +msgid "Strict limit" +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.constraint,message:loyalty_limit.constraint_coupon_rule_salesmen_limit_user_id_uniq +msgid "This salesman limit is already configured" +msgstr "" + +#. module: loyalty_limit +#: model_terms:ir.ui.view,arch_db:loyalty_limit.sale_coupon_program_view_form_common +msgid "Total limit" +msgstr "" + +#. module: loyalty_limit +#: model_terms:ir.ui.view,arch_db:loyalty_limit.sale_coupon_program_view_form_common +msgid "Total used" +msgstr "" + +#. module: loyalty_limit +#: model:ir.model.fields,field_description:loyalty_limit.field_coupon_rule_salesmen_limit__rule_times_used +msgid "Uses" +msgstr "" + +#. module: loyalty_limit +#: model_terms:ir.ui.view,arch_db:loyalty_limit.sale_coupon_program_view_form_common +msgid "used already)" +msgstr "" diff --git a/loyalty_limit/migrations/15.0.1.0.0/pre-migration.py b/loyalty_limit/migrations/15.0.1.0.0/pre-migration.py deleted file mode 100644 index 09b4680a0..000000000 --- a/loyalty_limit/migrations/15.0.1.0.0/pre-migration.py +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2023 Tecnativa - David Vidal -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from openupgradelib import openupgrade - -_model_renames = [ - ("sale.coupon.rule.salesmen.limit", "coupon.rule.salesmen.limit"), -] -_table_renames = [("sale_coupon_rule_salesmen_limit", "coupon_rule_salesmen_limit")] - - -@openupgrade.migrate() -def migrate(env, version): - openupgrade.rename_models(env.cr, _model_renames) - openupgrade.rename_tables(env.cr, _table_renames) diff --git a/loyalty_limit/migrations/16.0.1.0.0/pre-migration.py b/loyalty_limit/migrations/16.0.1.0.0/pre-migration.py new file mode 100644 index 000000000..1ee7cf2c8 --- /dev/null +++ b/loyalty_limit/migrations/16.0.1.0.0/pre-migration.py @@ -0,0 +1,82 @@ +# Copyright 2023 Tecnativa - Pilar Vargas +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openupgradelib import openupgrade + +_field_renames = [ + ("loyalty.salesmen.limit", "loyalty_salesmen_limit", "rule_user_id", "user_id"), + ( + "loyalty.salesmen.limit", + "loyalty_salesmen_limit", + "rule_max_salesman_application", + "max_salesman_application", + ), +] + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.rename_models( + env.cr, [("coupon.rule.salesmen.limit", "loyalty.salesmen.limit")] + ) + openupgrade.rename_tables( + env.cr, [("coupon_rule_salesmen_limit", "loyalty_salesmen_limit")] + ) + openupgrade.rename_fields(env.cr, _field_renames) + # Create the 'program_id' field if it does not exist in the 'loyalty_salesmen_limit' + # table and fill the 'program_id' field with values from 'loyalty_rule.program_id' + # where 'loyalty_rule.id' is equal to old field 'loyalty_salesmen_limit.rule_id' + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE loyalty_salesmen_limit + ADD COLUMN IF NOT EXISTS program_id INT + """, + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE loyalty_salesmen_limit + SET program_id = loyalty_rule.program_id + FROM loyalty_rule + WHERE loyalty_salesmen_limit.rule_id = loyalty_rule.id + """, + ) + # Delete constraints to recreate it + openupgrade.delete_sql_constraint_safely( + env, "loyalty_limit", "loyalty_salesmen_limit", "user_id_uniq" + ) + # Move fields 'max_customer_application', 'salesmen_limit_ids' and 'salesmen_strict_limit' + # from loyalty_rule to loyalty_program table + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE loyalty_program + ADD COLUMN IF NOT EXISTS max_customer_application INT + """, + ) + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE loyalty_program + ADD COLUMN IF NOT EXISTS salesmen_limit_ids INT + """, + ) + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE loyalty_program + ADD COLUMN IF NOT EXISTS salesmen_strict_limit BOOLEAN + """, + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE loyalty_program AS lp + SET + max_customer_application = lr.rule_max_customer_application, + salesmen_limit_ids = lr.rule_salesmen_limit_ids, + salesmen_strict_limit = lr.rule_salesmen_strict_limit + FROM loyalty_rule AS lr + WHERE lp.id = lr.program_id + """, + ) diff --git a/loyalty_limit/models/__init__.py b/loyalty_limit/models/__init__.py index b6fc8de3e..9afd49560 100644 --- a/loyalty_limit/models/__init__.py +++ b/loyalty_limit/models/__init__.py @@ -1 +1 @@ -from . import coupon_rule +from . import loyalty_program diff --git a/loyalty_limit/models/coupon_rule.py b/loyalty_limit/models/loyalty_program.py similarity index 50% rename from loyalty_limit/models/coupon_rule.py rename to loyalty_limit/models/loyalty_program.py index e47d9f97a..7b0ca43b5 100644 --- a/loyalty_limit/models/coupon_rule.py +++ b/loyalty_limit/models/loyalty_program.py @@ -3,81 +3,81 @@ from odoo import api, fields, models -class CouponRule(models.Model): - _inherit = "coupon.rule" +class LoyaltyProgram(models.Model): + _inherit = "loyalty.program" - rule_max_customer_application = fields.Integer( + max_customer_application = fields.Integer( string="Maximum Customer Applications", default=0, help="Maximum times that a program can be applied to a customer. " "0 for no limit.", ) - rule_salesmen_limit_ids = fields.One2many( + salesmen_limit_ids = fields.One2many( string="Salesmen Limits", - comodel_name="coupon.rule.salesmen.limit", - inverse_name="rule_id", + comodel_name="loyalty.salesmen.limit", + inverse_name="program_id", help="Maximum times salesmen can apply a program. Empty for no limit.", ) - rule_salesmen_strict_limit = fields.Boolean( + salesmen_strict_limit = fields.Boolean( default=False, string="Strict limit", help="If marked, promotion will only be allowed for the list of salesmen with " "their quantities", ) - rule_salesmen_limit_count = fields.Integer( + salesmen_limit_count = fields.Integer( string="Salesmen maximum promotions", - compute="_compute_rule_salesmen_limit_count", + compute="_compute_salesmen_limit_count", ) - rule_salesmen_limit_used_count = fields.Integer( + salesmen_limit_used_count = fields.Integer( string="Salesmen promotions used", - compute="_compute_rule_salesmen_limit_count", + compute="_compute_salesmen_limit_count", ) @api.depends( - "rule_salesmen_limit_ids.rule_max_salesman_application", - "rule_salesmen_limit_ids.rule_times_used", + "salesmen_limit_ids.max_salesman_application", + "salesmen_limit_ids.times_used", ) - def _compute_rule_salesmen_limit_count(self): + def _compute_salesmen_limit_count(self): """To be overriden""" - self.rule_salesmen_limit_count = 0 - self.rule_salesmen_limit_used_count = 0 + self.salesmen_limit_count = 0 + self.salesmen_limit_used_count = 0 -class CouponRuleSalesmenLimit(models.Model): - _name = "coupon.rule.salesmen.limit" - _description = "Coupon Rule Salesmen limits" +class LoyaltySalesmenLimit(models.Model): + _name = "loyalty.salesmen.limit" + _description = "Loyalty Salesmen limits" - rule_id = fields.Many2one( - comodel_name="coupon.rule", + program_id = fields.Many2one( + comodel_name="loyalty.program", auto_join=True, required=True, ondelete="cascade", ) - rule_user_id = fields.Many2one( + user_id = fields.Many2one( comodel_name="res.users", string="Salesman", required=True, ondelete="cascade", ) - rule_max_salesman_application = fields.Integer( + max_salesman_application = fields.Integer( string="Maximum Salesman Applications", default=0, help="Maximum times a salesman can apply a program. 0 for no limit.", ) - rule_times_used = fields.Integer( + times_used = fields.Integer( string="Uses", - compute="_compute_rule_times_used", + compute="_compute_times_used", ) _sql_constraints = [ ( "user_id_uniq", - "unique(rule_id, rule_user_id)", + "unique(program_id, user_id)", "This salesman limit is already configured", ), ] - @api.depends("rule_user_id", "rule_max_salesman_application") - def _compute_rule_times_used(self): + @api.depends("user_id", "max_salesman_application") + def _compute_times_used(self): """To be overriden""" - self.rule_times_used = 0 + self.times_used = 0 diff --git a/loyalty_limit/readme/CONTRIBUTORS.rst b/loyalty_limit/readme/CONTRIBUTORS.rst index a4f45715c..7d6f8b1ad 100644 --- a/loyalty_limit/readme/CONTRIBUTORS.rst +++ b/loyalty_limit/readme/CONTRIBUTORS.rst @@ -2,6 +2,7 @@ * Pedro M. Baeza * David Vidal + * Pilar Vargas * `Akretion `_: diff --git a/loyalty_limit/security/ir.model.access.csv b/loyalty_limit/security/ir.model.access.csv index 27f4ab888..30895d182 100644 --- a/loyalty_limit/security/ir.model.access.csv +++ b/loyalty_limit/security/ir.model.access.csv @@ -1,2 +1,2 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_salesmen_limit_manager,salesmen_limit manager,model_coupon_rule_salesmen_limit,base.group_system,1,1,1,1 +access_salesmen_limit_manager,salesmen_limit manager,model_loyalty_salesmen_limit,base.group_system,1,1,1,1 diff --git a/loyalty_limit/static/description/icon.svg b/loyalty_limit/static/description/icon.svg index 2f5df826c..e6b472ccf 100644 --- a/loyalty_limit/static/description/icon.svg +++ b/loyalty_limit/static/description/icon.svg @@ -11,7 +11,7 @@ version="1.1" id="svg33" sodipodi:docname="icon.svg" - inkscape:export-filename="/home/david/odoo/oca13/odoo/custom/src/sale-promotion/coupon_limit/static/description/icon.png" + inkscape:export-filename="/home/david/odoo/oca13/odoo/custom/src/sale-promotion/loyalty_limit/static/description/icon.png" inkscape:export-xdpi="192" inkscape:export-ydpi="192" inkscape:version="1.1-dev (1:1.0+devel+202007152027+7044d6c)"> diff --git a/loyalty_limit/static/description/index.html b/loyalty_limit/static/description/index.html index ba0d10eb0..851307479 100644 --- a/loyalty_limit/static/description/index.html +++ b/loyalty_limit/static/description/index.html @@ -4,7 +4,7 @@ -Coupon Limit +Loyalty Limit -
-

Coupon Limit

+
+

Loyalty Limit

-

Production/Stable License: AGPL-3 OCA/sale-promotion Translate me on Weblate Try me on Runboat

+

Production/Stable License: AGPL-3 OCA/sale-promotion Translate me on Weblate Try me on Runboat

This module allows to configure a limit on the times a promotion can be applied. It’s a technical base to be extended with top level functionality (sales, pos).

Table of contents

@@ -389,7 +389,7 @@

Bug Tracker

Bugs are tracked on GitHub 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.

+feedback.

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

@@ -406,6 +406,7 @@

Contributors

  • Tecnativa:
    • Pedro M. Baeza
    • David Vidal
    • +
    • Pilar Vargas
  • Akretion:
  • diff --git a/loyalty_limit/tests/__init__.py b/loyalty_limit/tests/__init__.py index 6566525d0..22da88f20 100644 --- a/loyalty_limit/tests/__init__.py +++ b/loyalty_limit/tests/__init__.py @@ -1 +1 @@ -from . import test_coupon_limit +from . import test_loyalty_limit diff --git a/loyalty_limit/tests/test_coupon_limit.py b/loyalty_limit/tests/test_coupon_limit.py deleted file mode 100644 index 8453bf723..000000000 --- a/loyalty_limit/tests/test_coupon_limit.py +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright 2021 Tecnativa - David Vidal -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo.tests import Form, TransactionCase - - -class CouponLimitCase(TransactionCase): - @classmethod - def setUpClass(cls): - super().setUpClass() - product_obj = cls.env["product.product"] - cls.pricelist = cls.env["product.pricelist"].create( - { - "name": "Test pricelist", - "item_ids": [ - ( - 0, - 0, - { - "applied_on": "3_global", - "compute_price": "formula", - "base": "list_price", - }, - ) - ], - } - ) - cls.partner_1 = cls.env["res.partner"].create( - {"name": "Mr. Odoo", "property_product_pricelist": cls.pricelist.id} - ) - cls.partner_2 = cls.env["res.partner"].create( - {"name": "Mrs. Odoo", "property_product_pricelist": cls.pricelist.id} - ) - cls.salesman_1 = cls.env["res.users"].create( - {"name": "Salesman 1", "login": "test_salesman_1"} - ) - cls.salesman_2 = cls.env["res.users"].create( - {"name": "Salesman 2", "login": "test_salesman_2"} - ) - cls.product_a = product_obj.create({"name": "Product A", "list_price": 50}) - coupon_program_form = Form( - cls.env["coupon.program"], - view="sale_coupon.sale_coupon_program_view_promo_program_form", - ) - coupon_program_form.name = "Test Coupon Limit" - # We don't want demo programs spoiling our tests - coupon_program_form.rule_products_domain = "[('id', '=', %s)]" % ( - cls.product_a.id - ) - 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 - # Customer limits preceed salesmen limits - coupon_program_form.rule_max_customer_application = 2 - with coupon_program_form.rule_salesmen_limit_ids.new() as salesman_limit: - salesman_limit.rule_user_id = cls.salesman_1 - salesman_limit.rule_max_salesman_application = 2 - with coupon_program_form.rule_salesmen_limit_ids.new() as salesman_limit: - salesman_limit.rule_user_id = cls.salesman_2 - salesman_limit.rule_max_salesman_application = 2 - # With any other salesman, the limits won't apply - coupon_program_form.rule_salesmen_strict_limit = False - cls.coupon_program = coupon_program_form.save() diff --git a/loyalty_limit/tests/test_loyalty_limit.py b/loyalty_limit/tests/test_loyalty_limit.py new file mode 100644 index 000000000..bb0f037e9 --- /dev/null +++ b/loyalty_limit/tests/test_loyalty_limit.py @@ -0,0 +1,285 @@ +# Copyright 2021 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.tests import TransactionCase + + +class LoyaltyLimitCase(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + product_obj = cls.env["product.product"] + cls.pricelist = cls.env["product.pricelist"].create( + { + "name": "Test pricelist", + "item_ids": [ + ( + 0, + 0, + { + "applied_on": "3_global", + "compute_price": "formula", + "base": "list_price", + }, + ) + ], + } + ) + cls.partner_1 = cls.env["res.partner"].create( + {"name": "Mr. Odoo", "property_product_pricelist": cls.pricelist.id} + ) + cls.partner_2 = cls.env["res.partner"].create( + {"name": "Mrs. Odoo", "property_product_pricelist": cls.pricelist.id} + ) + cls.salesman_1 = cls.env["res.users"].create( + {"name": "Salesman 1", "login": "test_salesman_1"} + ) + cls.salesman_2 = cls.env["res.users"].create( + {"name": "Salesman 2", "login": "test_salesman_2"} + ) + cls.product_a = product_obj.create({"name": "Product A", "list_price": 50}) + cls.promotion_with_customer_limit = cls.env["loyalty.program"].create( + { + "name": "Test Loyalty Limit Promotion With Customer Limit", + "program_type": "promotion", + "trigger": "auto", + "applies_on": "current", + "max_customer_application": 2, + "rule_ids": [ + ( + 0, + 0, + { + "reward_point_mode": "order", + "minimum_qty": 1, + }, + ), + ], + "reward_ids": [ + ( + 0, + 0, + { + "reward_type": "discount", + "required_points": 1, + "discount": 10, + "discount_mode": "percent", + "discount_applicability": "order", + }, + ) + ], + } + ) + cls.promotion_with_salesman_limit = cls.env["loyalty.program"].create( + { + "name": "Test Loyalty Limit Promotion With Salesman Limit", + "program_type": "promotion", + "trigger": "auto", + "applies_on": "current", + "salesmen_limit_ids": [ + ( + 0, + 0, + { + "user_id": cls.salesman_1.id, + "max_salesman_application": 2, + }, + ), + ( + 0, + 0, + { + "user_id": cls.salesman_2.id, + "max_salesman_application": 2, + }, + ), + ], + "salesmen_strict_limit": False, + "rule_ids": [ + ( + 0, + 0, + { + "reward_point_mode": "order", + "minimum_qty": 1, + }, + ), + ], + "reward_ids": [ + ( + 0, + 0, + { + "reward_type": "discount", + "required_points": 1, + "discount": 10, + "discount_mode": "percent", + "discount_applicability": "order", + }, + ) + ], + } + ) + cls.coupon_program_with_customer_limit = cls.env["loyalty.program"].create( + { + "name": "Test Loyalty Limit Coupon With Customer Limit", + "trigger": "with_code", + "program_type": "coupons", + "applies_on": "current", + "max_customer_application": 2, + "rule_ids": [ + ( + 0, + 0, + { + "reward_point_mode": "order", + "minimum_qty": 1, + }, + ), + ], + "reward_ids": [ + ( + 0, + 0, + { + "reward_type": "discount", + "required_points": 1, + "discount": 10, + "discount_mode": "percent", + "discount_applicability": "order", + }, + ) + ], + } + ) + cls.coupon_program_with_salesman_limit = cls.env["loyalty.program"].create( + { + "name": "Test Loyalty Limit Coupon With Salesman Limit", + "trigger": "with_code", + "program_type": "coupons", + "applies_on": "current", + "salesmen_limit_ids": [ + ( + 0, + 0, + { + "user_id": cls.salesman_1.id, + "max_salesman_application": 2, + }, + ), + ( + 0, + 0, + { + "user_id": cls.salesman_2.id, + "max_salesman_application": 2, + }, + ), + ], + "rule_ids": [ + ( + 0, + 0, + { + "reward_point_mode": "order", + "minimum_qty": 1, + }, + ), + ], + "reward_ids": [ + ( + 0, + 0, + { + "reward_type": "discount", + "required_points": 1, + "discount": 10, + "discount_mode": "percent", + "discount_applicability": "order", + }, + ) + ], + } + ) + cls.next_order_coupon_with_customer_limit = cls.env["loyalty.program"].create( + { + "name": "Test Loyalty Limit Next Order Coupons With Customer Limit", + "program_type": "next_order_coupons", + "trigger": "auto", + "applies_on": "future", + "max_customer_application": 2, + "rule_ids": [ + ( + 0, + 0, + { + "reward_point_mode": "order", + "minimum_qty": 1, + "minimum_amount": 20, + }, + ) + ], + "reward_ids": [ + ( + 0, + 0, + { + "reward_type": "discount", + "required_points": 1, + "discount": 10, + "discount_mode": "percent", + "discount_applicability": "order", + }, + ) + ], + } + ) + cls.next_order_coupon_with_salesman_limit = cls.env["loyalty.program"].create( + { + "name": "Test Loyalty Limit Next Order Coupons With Salesman Limit", + "program_type": "next_order_coupons", + "trigger": "auto", + "applies_on": "future", + "salesmen_limit_ids": [ + ( + 0, + 0, + { + "user_id": cls.salesman_1.id, + "max_salesman_application": 2, + }, + ), + ( + 0, + 0, + { + "user_id": cls.salesman_2.id, + "max_salesman_application": 2, + }, + ), + ], + "rule_ids": [ + ( + 0, + 0, + { + "reward_point_mode": "order", + "minimum_qty": 1, + "minimum_amount": 20, + }, + ) + ], + "reward_ids": [ + ( + 0, + 0, + { + "reward_type": "discount", + "required_points": 1, + "discount": 10, + "discount_mode": "percent", + "discount_applicability": "order", + }, + ) + ], + } + ) diff --git a/loyalty_limit/views/coupon_program_views.xml b/loyalty_limit/views/coupon_program_views.xml deleted file mode 100644 index 2e54256e0..000000000 --- a/loyalty_limit/views/coupon_program_views.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - coupon.program - - - - - - diff --git a/loyalty_limit/views/loyalty_program_views.xml b/loyalty_limit/views/loyalty_program_views.xml new file mode 100644 index 000000000..07e19b0fa --- /dev/null +++ b/loyalty_limit/views/loyalty_program_views.xml @@ -0,0 +1,41 @@ + + + + + loyalty.program + + + + + + diff --git a/setup/coupon_limit/odoo/addons/coupon_limit b/setup/coupon_limit/odoo/addons/coupon_limit deleted file mode 120000 index 28653a123..000000000 --- a/setup/coupon_limit/odoo/addons/coupon_limit +++ /dev/null @@ -1 +0,0 @@ -../../../../coupon_limit \ No newline at end of file diff --git a/setup/loyalty_limit/odoo/addons/loyalty_limit b/setup/loyalty_limit/odoo/addons/loyalty_limit new file mode 120000 index 000000000..51fefbcd2 --- /dev/null +++ b/setup/loyalty_limit/odoo/addons/loyalty_limit @@ -0,0 +1 @@ +../../../../loyalty_limit \ No newline at end of file diff --git a/setup/coupon_limit/setup.py b/setup/loyalty_limit/setup.py similarity index 100% rename from setup/coupon_limit/setup.py rename to setup/loyalty_limit/setup.py