diff --git a/loyalty_margin_computation/README.rst b/loyalty_margin_computation/README.rst new file mode 100644 index 00000000..691a5fc3 --- /dev/null +++ b/loyalty_margin_computation/README.rst @@ -0,0 +1,81 @@ +========================== +Loyalty Margin Computation +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:99ca6b7832e6b29fbbc6489547855ed99bb1650c68af1eb284981177f7e6c422 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmargin--analysis-lightgray.png?logo=github + :target: https://github.com/OCA/margin-analysis/tree/18.0/loyalty_margin_computation + :alt: OCA/margin-analysis +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/margin-analysis-18-0/margin-analysis-18-0-loyalty_margin_computation + :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/margin-analysis&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to configure a formula (Python code to use in sales, +pos). It's a technical base to be extended with top level functionality +(see *sale_loyalty_margin_computation*). + +**Table of contents** + +.. contents:: + :local: + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__: + + - Pedro M. Baeza + - Andrii Kompaniiets + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/margin-analysis `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/loyalty_margin_computation/__init__.py b/loyalty_margin_computation/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/loyalty_margin_computation/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/loyalty_margin_computation/__manifest__.py b/loyalty_margin_computation/__manifest__.py new file mode 100644 index 00000000..a61886b8 --- /dev/null +++ b/loyalty_margin_computation/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2026 Tecnativa - Andrii Kompaniiets +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Loyalty Margin Computation", + "summary": "Allows setting a formula to calculate the margin", + "version": "18.0.1.0.0", + "category": "Sale", + "website": "https://github.com/OCA/margin-analysis", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["loyalty"], + "data": ["views/loyalty_reward_views.xml"], +} diff --git a/loyalty_margin_computation/i18n/es.po b/loyalty_margin_computation/i18n/es.po new file mode 100644 index 00000000..5aded47e --- /dev/null +++ b/loyalty_margin_computation/i18n/es.po @@ -0,0 +1,63 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * loyalty_margin_computation +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-04-30 14:11+0000\n" +"PO-Revision-Date: 2026-04-30 16:14+0200\n" +"Last-Translator: Andrii Kompaniiets \n" +"Language-Team: \n" +"Language: es_ES\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 3.9\n" + +#. module: loyalty_margin_computation +#: model_terms:ir.ui.view,arch_db:loyalty_margin_computation.margin_product_loyalty_reward_form_view +msgid "env: The Sale Order Line environment" +msgstr "env: El entorno de la línea de pedido de venta" + +#. module: loyalty_margin_computation +#: model_terms:ir.ui.view,arch_db:loyalty_margin_computation.margin_product_loyalty_reward_form_view +msgid "reward: The reward record" +msgstr "reward: El registro de recompensas" + +#. module: loyalty_margin_computation +#: model_terms:ir.ui.view,arch_db:loyalty_margin_computation.margin_product_loyalty_reward_form_view +msgid "Example of Python code:" +msgstr "Ejemplo de código en Python:" + +#. module: loyalty_margin_computation +#: model:ir.model,name:loyalty_margin_computation.model_loyalty_reward +msgid "Loyalty Reward" +msgstr "Recompensa" + +#. module: loyalty_margin_computation +#: model:ir.model.fields,field_description:loyalty_margin_computation.field_loyalty_reward__margin_price_formula +msgid "Margin Price Formula" +msgstr "Fórmula del precio de margen" + +#. module: loyalty_margin_computation +#: model_terms:ir.ui.view,arch_db:loyalty_margin_computation.margin_product_loyalty_reward_form_view +msgid "Margin's Formulas" +msgstr "Fórmulas de margen" + +#. module: loyalty_margin_computation +#: model_terms:ir.ui.view,arch_db:loyalty_margin_computation.margin_product_loyalty_reward_form_view +msgid "The following variables can be used:" +msgstr "Se pueden utilizar las siguientes variables:" + +#. module: loyalty_margin_computation +#: model:ir.model.fields,help:loyalty_margin_computation.field_loyalty_reward__margin_price_formula +msgid "This formula is used to calculate the margin" +msgstr "Esta fórmula se utiliza para calcular el margen" + +#. module: loyalty_margin_computation +#: model_terms:ir.ui.view,arch_db:loyalty_margin_computation.margin_product_loyalty_reward_form_view +msgid "result = 10 if list_price > 100 else 5" +msgstr "" diff --git a/loyalty_margin_computation/i18n/loyalty_margin_computation.pot b/loyalty_margin_computation/i18n/loyalty_margin_computation.pot new file mode 100644 index 00000000..569736e5 --- /dev/null +++ b/loyalty_margin_computation/i18n/loyalty_margin_computation.pot @@ -0,0 +1,61 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * loyalty_margin_computation +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-04-30 14:11+0000\n" +"PO-Revision-Date: 2026-04-30 14:11+0000\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_margin_computation +#: model_terms:ir.ui.view,arch_db:loyalty_margin_computation.margin_product_loyalty_reward_form_view +msgid "env: The Sale Order Line environment" +msgstr "" + +#. module: loyalty_margin_computation +#: model_terms:ir.ui.view,arch_db:loyalty_margin_computation.margin_product_loyalty_reward_form_view +msgid "reward: The reward record" +msgstr "" + +#. module: loyalty_margin_computation +#: model_terms:ir.ui.view,arch_db:loyalty_margin_computation.margin_product_loyalty_reward_form_view +msgid "Example of Python code:" +msgstr "" + +#. module: loyalty_margin_computation +#: model:ir.model,name:loyalty_margin_computation.model_loyalty_reward +msgid "Loyalty Reward" +msgstr "" + +#. module: loyalty_margin_computation +#: model:ir.model.fields,field_description:loyalty_margin_computation.field_loyalty_reward__margin_price_formula +msgid "Margin Price Formula" +msgstr "" + +#. module: loyalty_margin_computation +#: model_terms:ir.ui.view,arch_db:loyalty_margin_computation.margin_product_loyalty_reward_form_view +msgid "Margin's Formulas" +msgstr "" + +#. module: loyalty_margin_computation +#: model_terms:ir.ui.view,arch_db:loyalty_margin_computation.margin_product_loyalty_reward_form_view +msgid "The following variables can be used:" +msgstr "" + +#. module: loyalty_margin_computation +#: model:ir.model.fields,help:loyalty_margin_computation.field_loyalty_reward__margin_price_formula +msgid "This formula is used to calculate the margin" +msgstr "" + +#. module: loyalty_margin_computation +#: model_terms:ir.ui.view,arch_db:loyalty_margin_computation.margin_product_loyalty_reward_form_view +msgid "result = 10 if list_price > 100 else 5" +msgstr "" diff --git a/loyalty_margin_computation/models/__init__.py b/loyalty_margin_computation/models/__init__.py new file mode 100644 index 00000000..d47c146f --- /dev/null +++ b/loyalty_margin_computation/models/__init__.py @@ -0,0 +1 @@ +from . import loyalty_reward diff --git a/loyalty_margin_computation/models/loyalty_reward.py b/loyalty_margin_computation/models/loyalty_reward.py new file mode 100644 index 00000000..ba2277a6 --- /dev/null +++ b/loyalty_margin_computation/models/loyalty_reward.py @@ -0,0 +1,25 @@ +# Copyright 2026 Tecnativa - Andrii Kompaniiets +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import api, fields, models +from odoo.exceptions import ValidationError + + +class LoyaltyReward(models.Model): + _inherit = "loyalty.reward" + + sale_margin_formula = fields.Text( + help="This formula is used to calculate the margin" + ) + + @api.constrains("sale_margin_formula") + def _check_sale_margin_formula(self): + # To be extended by other modules + for reward in self: + if not reward.sale_margin_formula: + continue + try: + compile( + str(reward.sale_margin_formula).strip(), "", mode="exec" + ) + except SyntaxError as e: + raise ValidationError(f"Syntax error {e.lineno}: {e.msg}") from e diff --git a/loyalty_margin_computation/pyproject.toml b/loyalty_margin_computation/pyproject.toml new file mode 100644 index 00000000..4231d0cc --- /dev/null +++ b/loyalty_margin_computation/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/loyalty_margin_computation/readme/CONTRIBUTORS.md b/loyalty_margin_computation/readme/CONTRIBUTORS.md new file mode 100644 index 00000000..71701213 --- /dev/null +++ b/loyalty_margin_computation/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [Tecnativa](https://www.tecnativa.com): + - Pedro M. Baeza + - Andrii Kompaniiets diff --git a/loyalty_margin_computation/readme/DESCRIPTION.md b/loyalty_margin_computation/readme/DESCRIPTION.md new file mode 100644 index 00000000..f0fbd98b --- /dev/null +++ b/loyalty_margin_computation/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module allows to configure a formula (Python code to use in sales, pos). +It's a technical base to be extended with top level functionality +(see *sale_loyalty_margin_computation*). \ No newline at end of file diff --git a/loyalty_margin_computation/static/description/icon.png b/loyalty_margin_computation/static/description/icon.png new file mode 100644 index 00000000..a8aac47e Binary files /dev/null and b/loyalty_margin_computation/static/description/icon.png differ diff --git a/loyalty_margin_computation/static/description/index.html b/loyalty_margin_computation/static/description/index.html new file mode 100644 index 00000000..91195f20 --- /dev/null +++ b/loyalty_margin_computation/static/description/index.html @@ -0,0 +1,429 @@ + + + + + +Loyalty Margin Computation + + + +
+

Loyalty Margin Computation

+ + +

Beta License: AGPL-3 OCA/margin-analysis Translate me on Weblate Try me on Runboat

+

This module allows to configure a formula (Python code to use in sales, +pos). It’s a technical base to be extended with top level functionality +(see sale_loyalty_margin_computation).

+

Table of contents

+ +
+

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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Pedro M. Baeza
    • +
    • Andrii Kompaniiets
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/margin-analysis project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/loyalty_margin_computation/views/loyalty_reward_views.xml b/loyalty_margin_computation/views/loyalty_reward_views.xml new file mode 100644 index 00000000..e8618433 --- /dev/null +++ b/loyalty_margin_computation/views/loyalty_reward_views.xml @@ -0,0 +1,40 @@ + + + + loyalty.reward + + + + + + + + + + + + + + +