From fc2aba9498fe7c81b00d2f4ecfd84fbf380b8d99 Mon Sep 17 00:00:00 2001 From: Telmo Santos Date: Wed, 18 Sep 2024 07:31:53 +0200 Subject: [PATCH] Add pos_product_pricelist_alternative --- pos_product_pricelist_alternative/README.rst | 58 +++ pos_product_pricelist_alternative/__init__.py | 1 + .../__manifest__.py | 22 + .../models/__init__.py | 1 + .../models/pos_session.py | 18 + .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 2 + .../static/description/index.html | 415 ++++++++++++++++++ .../static/src/models.js | 52 +++ .../addons/pos_product_pricelist_alternative | 1 + .../setup.py | 6 + 11 files changed, 577 insertions(+) create mode 100644 pos_product_pricelist_alternative/README.rst create mode 100644 pos_product_pricelist_alternative/__init__.py create mode 100644 pos_product_pricelist_alternative/__manifest__.py create mode 100644 pos_product_pricelist_alternative/models/__init__.py create mode 100644 pos_product_pricelist_alternative/models/pos_session.py create mode 100644 pos_product_pricelist_alternative/readme/CONTRIBUTORS.rst create mode 100644 pos_product_pricelist_alternative/readme/DESCRIPTION.rst create mode 100644 pos_product_pricelist_alternative/static/description/index.html create mode 100644 pos_product_pricelist_alternative/static/src/models.js create mode 120000 setup/pos_product_pricelist_alternative/odoo/addons/pos_product_pricelist_alternative create mode 100644 setup/pos_product_pricelist_alternative/setup.py diff --git a/pos_product_pricelist_alternative/README.rst b/pos_product_pricelist_alternative/README.rst new file mode 100644 index 0000000000..47c0d09179 --- /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..b7df7b8320 --- /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": [ + "product_pricelist_alternative", + "point_of_sale", + ], + "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..efe7bd7d0c --- /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..bfb4466092 --- /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: <https://github.com/OCA/product-attribute/tree/16.0/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..50f024fc48 --- /dev/null +++ b/pos_product_pricelist_alternative/static/src/models.js @@ -0,0 +1,52 @@ +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 ( + 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, +)