diff --git a/pos_product_pricelist_alternative/README.rst b/pos_product_pricelist_alternative/README.rst new file mode 100644 index 0000000000..9257b99d6d --- /dev/null +++ b/pos_product_pricelist_alternative/README.rst @@ -0,0 +1,58 @@ +================================= +POS Product Pricelist Alternative +================================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-camptocamp%2Fpos-lightgray.png?logo=github + :target: https://github.com/camptocamp/pos/tree/16.0/pos_product_pricelist_alternative + :alt: camptocamp/pos + +|badge1| |badge2| |badge3| + +POS product pricelist allternative is based on the same logic of `OCA/product_pricelist_alternative: `_ which allows you to define alternative price lists to a reference price list. +As a general rule, the price of a given product is obtained from the minimum between its reference price list and the alternative price lists. + +**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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Camptocamp + +Contributors +~~~~~~~~~~~~ + +* Telmo Santos + +Maintainers +~~~~~~~~~~~ + +This module is part of the `camptocamp/pos `_ project on GitHub. + +You are welcome to contribute. diff --git a/pos_product_pricelist_alternative/__init__.py b/pos_product_pricelist_alternative/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/pos_product_pricelist_alternative/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_product_pricelist_alternative/__manifest__.py b/pos_product_pricelist_alternative/__manifest__.py new file mode 100644 index 0000000000..61c50bc156 --- /dev/null +++ b/pos_product_pricelist_alternative/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "POS Product Pricelist Alternative", + "summary": "Calculate POS product price based on alternative pricelists", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "category": "Point of Sale", + "author": "Camptocamp, Odoo Community Association (OCA)", + "depends": [ + "point_of_sale", + "product_pricelist_alternative", + ], + "assets": { + "point_of_sale.assets": [ + "pos_product_pricelist_alternative/static/src/**/*.js", + ], + }, + "website": "https://github.com/OCA/pos", + "installable": True, + "auto_install": False, +} diff --git a/pos_product_pricelist_alternative/models/__init__.py b/pos_product_pricelist_alternative/models/__init__.py new file mode 100644 index 0000000000..f7116e3d45 --- /dev/null +++ b/pos_product_pricelist_alternative/models/__init__.py @@ -0,0 +1 @@ +from . import pos_session diff --git a/pos_product_pricelist_alternative/models/pos_session.py b/pos_product_pricelist_alternative/models/pos_session.py new file mode 100644 index 0000000000..23cc1518a2 --- /dev/null +++ b/pos_product_pricelist_alternative/models/pos_session.py @@ -0,0 +1,18 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class PosSession(models.Model): + _inherit = "pos.session" + + def _loader_params_product_pricelist(self): + result = super()._loader_params_product_pricelist() + result["search_params"]["fields"].extend(["alternative_pricelist_ids"]) + return result + + def _product_pricelist_item_fields(self): + result = super()._product_pricelist_item_fields() + result.extend(["alternative_pricelist_policy"]) + return result diff --git a/pos_product_pricelist_alternative/readme/CONTRIBUTORS.rst b/pos_product_pricelist_alternative/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..8ed3aebaca --- /dev/null +++ b/pos_product_pricelist_alternative/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Telmo Santos diff --git a/pos_product_pricelist_alternative/readme/DESCRIPTION.rst b/pos_product_pricelist_alternative/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..842e6409f2 --- /dev/null +++ b/pos_product_pricelist_alternative/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +POS product pricelist allternative is based on the same logic of `OCA/product_pricelist_alternative: `_ which allows you to define alternative price lists to a reference price list. +As a general rule, the price of a given product is obtained from the minimum between its reference price list and the alternative price lists. diff --git a/pos_product_pricelist_alternative/static/description/index.html b/pos_product_pricelist_alternative/static/description/index.html new file mode 100644 index 0000000000..5475f24798 --- /dev/null +++ b/pos_product_pricelist_alternative/static/description/index.html @@ -0,0 +1,415 @@ + + + + + + +POS Product Pricelist Alternative + + + +
+

POS Product Pricelist Alternative

+ + +

Beta License: AGPL-3 camptocamp/pos

+

POS product pricelist allternative is based on the same logic of OCA/product_pricelist_alternative: which allows you to define alternative price lists to a reference price list. +As a general rule, the price of a given product is obtained from the minimum between its reference price list and the alternative price lists.

+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+ +
+

Maintainers

+

This module is part of the camptocamp/pos project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/pos_product_pricelist_alternative/static/src/models.js b/pos_product_pricelist_alternative/static/src/models.js new file mode 100644 index 0000000000..510cf9533b --- /dev/null +++ b/pos_product_pricelist_alternative/static/src/models.js @@ -0,0 +1,54 @@ +odoo.define("pos_product_pricelist_alternative.models", function (require) { + "use strict"; + + const {Product} = require("point_of_sale.models"); + const Registries = require("point_of_sale.Registries"); + + const ProductPatch = (Product) => + class ProductPatch extends Product { + /** @override **/ + get_price(pricelist, quantity, price_extra, get_pricelist_rule = false) { + const {price, pricelist_item} = super.get_price( + pricelist, + quantity, + price_extra, + true + ); + var best_price = price; + var best_price_item = pricelist_item; + if (this.display_name.includes("ttt")) { + if ( + pricelist_item.alternative_pricelist_policy === + "use_lower_price" + ) { + for (const alternative_pricelist_id of pricelist.alternative_pricelist_ids) { + var alternative_pricelist = _.find( + this.pos.pricelists, + function (pricelist) { + return pricelist.id === alternative_pricelist_id; + } + ); + if (!alternative_pricelist) { + continue; + } + var alternative_price_rule = this.get_price( + alternative_pricelist, + quantity, + price_extra, + true + ); + // Take the lower price + if (alternative_price_rule.price < best_price) { + best_price = alternative_price_rule.price; + best_price_item = alternative_price_rule.pricelist_item; + } + } + } + } + return get_pricelist_rule + ? {price: best_price, pricelist_item: best_price_item} + : best_price; + } + }; + Registries.Model.extend(Product, ProductPatch); +}); diff --git a/setup/pos_product_pricelist_alternative/odoo/addons/pos_product_pricelist_alternative b/setup/pos_product_pricelist_alternative/odoo/addons/pos_product_pricelist_alternative new file mode 120000 index 0000000000..69f6369a7a --- /dev/null +++ b/setup/pos_product_pricelist_alternative/odoo/addons/pos_product_pricelist_alternative @@ -0,0 +1 @@ +../../../../pos_product_pricelist_alternative \ No newline at end of file diff --git a/setup/pos_product_pricelist_alternative/setup.py b/setup/pos_product_pricelist_alternative/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/pos_product_pricelist_alternative/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)