diff --git a/pos_partner_pricelist_load_background/README.rst b/pos_partner_pricelist_load_background/README.rst new file mode 100644 index 0000000000..a5c365b451 --- /dev/null +++ b/pos_partner_pricelist_load_background/README.rst @@ -0,0 +1,66 @@ +===================================== +POS Partner Pricelist Load Background +===================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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_partner_pricelist_load_background + :alt: camptocamp/pos + +|badge1| |badge2| |badge3| + +This module allow you to load a pricelist for a customer in the background. + +**Context** +In the POS, we can configure a list of available pricelists. These price lists are loaded during start-up and only these can be chosen for any order. +When a customer is selected, the POS will try to find the customer's pricelist (property_pricelist_id) among the available pricelists. +If it's found, the pricelist is selected otherwise a default one will be selected instead. + +**Whith this module** +When a customer is selected, his pricelist (property_pricelist_id) is loaded and available to be chosen. + +**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 +* Iván Todorovich + +Maintainers +~~~~~~~~~~~ + +This module is part of the `camptocamp/pos `_ project on GitHub. + +You are welcome to contribute. diff --git a/pos_partner_pricelist_load_background/__init__.py b/pos_partner_pricelist_load_background/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/pos_partner_pricelist_load_background/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_partner_pricelist_load_background/__manifest__.py b/pos_partner_pricelist_load_background/__manifest__.py new file mode 100644 index 0000000000..4d9dbf0233 --- /dev/null +++ b/pos_partner_pricelist_load_background/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2024 Camptocamp (https://www.camptocamp.com). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "POS Partner Pricelist Load Background", + "summary": "Pos ", + "version": "16.0.1.0.0", + "author": "Camptocamp, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/pos", + "license": "AGPL-3", + "category": "Point of Sale", + "depends": ["point_of_sale"], + "installable": True, + "assets": { + "point_of_sale.assets": [ + "pos_partner_pricelist_load_background/static/src/js/**/*.js", + ], + }, +} diff --git a/pos_partner_pricelist_load_background/models/__init__.py b/pos_partner_pricelist_load_background/models/__init__.py new file mode 100644 index 0000000000..f7116e3d45 --- /dev/null +++ b/pos_partner_pricelist_load_background/models/__init__.py @@ -0,0 +1 @@ +from . import pos_session diff --git a/pos_partner_pricelist_load_background/models/pos_session.py b/pos_partner_pricelist_load_background/models/pos_session.py new file mode 100644 index 0000000000..9ccbda34d6 --- /dev/null +++ b/pos_partner_pricelist_load_background/models/pos_session.py @@ -0,0 +1,29 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import models + + +class POSSession(models.Model): + _inherit = "pos.session" + + def get_pos_ui_partner_pricelist(self, partner_id): + pricelist = ( + self.env["res.partner"].browse(partner_id).property_product_pricelist + ) + return self.get_pos_ui_product_pricelist( + {"search_params": {"domain": [["id", "in", [pricelist.id]]]}} + ) + + def get_pos_ui_product_pricelist(self, params): + return self._get_pos_ui_product_pricelist(params) + + def get_pos_ui_pricelist_product_product(self, pricelist_id): + item_ids = self.env["product.pricelist.item"].search( + [("pricelist_id", "=", pricelist_id)] + ) + products = item_ids.mapped("product_id") | item_ids.mapped( + "product_tmpl_id.product_variant_ids" + ) + return self.get_pos_ui_product_product_by_params( + {"domain": [["id", "in", products.ids]]} + ) diff --git a/pos_partner_pricelist_load_background/readme/CONTRIBUTORS.rst b/pos_partner_pricelist_load_background/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..5c9f1e3d54 --- /dev/null +++ b/pos_partner_pricelist_load_background/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Telmo Santos +* Iván Todorovich diff --git a/pos_partner_pricelist_load_background/readme/DESCRIPTION.rst b/pos_partner_pricelist_load_background/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..de9599365b --- /dev/null +++ b/pos_partner_pricelist_load_background/readme/DESCRIPTION.rst @@ -0,0 +1,9 @@ +This module allow you to load a pricelist for a customer in the background. + +**Context** +In the POS, we can configure a list of available pricelists. These price lists are loaded during start-up and only these can be chosen for any order. +When a customer is selected, the POS will try to find the customer's pricelist (property_pricelist_id) among the available pricelists. +If it's found, the pricelist is selected otherwise a default one will be selected instead. + +**Whith this module** +When a customer is selected, his pricelist (property_pricelist_id) is loaded and available to be chosen. diff --git a/pos_partner_pricelist_load_background/static/description/index.html b/pos_partner_pricelist_load_background/static/description/index.html new file mode 100644 index 0000000000..a13418d764 --- /dev/null +++ b/pos_partner_pricelist_load_background/static/description/index.html @@ -0,0 +1,421 @@ + + + + + + +POS Partner Pricelist Load Background + + + +
+

POS Partner Pricelist Load Background

+ + +

Beta License: AGPL-3 camptocamp/pos

+

This module allow you to load a pricelist for a customer in the background.

+

Context +In the POS, we can configure a list of available pricelists. These price lists are loaded during start-up and only these can be chosen for any order. +When a customer is selected, the POS will try to find the customer’s pricelist (property_pricelist_id) among the available pricelists. +If it’s found, the pricelist is selected otherwise a default one will be selected instead.

+

Whith this module +When a customer is selected, his pricelist (property_pricelist_id) is loaded and available to be chosen.

+

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
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

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

+

You are welcome to contribute.

+
+
+
+ + diff --git a/pos_partner_pricelist_load_background/static/src/js/PosGlobalState.js b/pos_partner_pricelist_load_background/static/src/js/PosGlobalState.js new file mode 100644 index 0000000000..90226e403a --- /dev/null +++ b/pos_partner_pricelist_load_background/static/src/js/PosGlobalState.js @@ -0,0 +1,51 @@ +odoo.define("pos_partner_pricelist_load_background.PosGlobalState", function (require) { + "use strict"; + + const {PosGlobalState} = require("point_of_sale.models"); + const Registries = require("point_of_sale.Registries"); + + const PosPartnerPricelistLoadBackgroundSPosGlobalState = (PosGlobalState) => + class PosPartnerPricelistLoadBackgroundSPosGlobalState extends PosGlobalState { + async getPartnerPricelists(partnerId) { + return await this.env.services.rpc({ + model: "pos.session", + method: "get_pos_ui_partner_pricelist", + args: [this.pos_session_id, partnerId], + }); + } + async _loadPartnerPricelistBackground(partnerId) { + const partnerPricelists = await this.getPartnerPricelists(partnerId); + const availablePricelistIds = Object.values( + this.env.pos.config.available_pricelist_ids + ); + + const partnerAvailablePricelists = []; + for (const i in this.pricelists) { + if (availablePricelistIds.includes(this.pricelists[i].id)) { + partnerAvailablePricelists.push( + Object.assign({}, this.pricelists[i]) + ); + } + } + this.pricelists = this.pricelists.filter((p) => + availablePricelistIds.includes(p.id) + ); + for (const pricelist of partnerPricelists) { + if (!this.pricelists.find((p) => p.id === pricelist.id)) { + this.pricelists.push(pricelist); + const products = await this.env.services.rpc({ + model: "pos.session", + method: "get_pos_ui_pricelist_product_product", + args: [this.pos_session_id, pricelist.id], + }); + await this._loadMissingPricelistItems(products); + } + } + } + }; + + Registries.Model.extend( + PosGlobalState, + PosPartnerPricelistLoadBackgroundSPosGlobalState + ); +}); diff --git a/pos_partner_pricelist_load_background/static/src/js/ProductScreen.js b/pos_partner_pricelist_load_background/static/src/js/ProductScreen.js new file mode 100644 index 0000000000..e32f09c901 --- /dev/null +++ b/pos_partner_pricelist_load_background/static/src/js/ProductScreen.js @@ -0,0 +1,29 @@ +odoo.define("pos_partner_pricelist_load_background.ProductScreen", function (require) { + "use strict"; + + const ProductScreen = require("point_of_sale.ProductScreen"); + const Registries = require("point_of_sale.Registries"); + + const PosPartnerPricelistLoadBackgroundScreen = (ProductScreen) => + class extends ProductScreen { + async onClickPartner() { + await super.onClickPartner(); + if (this.partner && this.partner.property_product_pricelist) { + if (this.partner && this.partner.property_product_pricelist) { + // Block the UI while loading the partner pricelist + this.env.services.ui.block(); + try { + await this.env.pos._loadPartnerPricelistBackground( + this.partner.id + ); + } finally { + this.env.services.ui.unblock(); + } + } + } + } + }; + + Registries.Component.extend(ProductScreen, PosPartnerPricelistLoadBackgroundScreen); + return ProductScreen; +}); diff --git a/setup/pos_partner_pricelist_load_background/odoo/addons/pos_partner_pricelist_load_background b/setup/pos_partner_pricelist_load_background/odoo/addons/pos_partner_pricelist_load_background new file mode 120000 index 0000000000..3c89d4ee9b --- /dev/null +++ b/setup/pos_partner_pricelist_load_background/odoo/addons/pos_partner_pricelist_load_background @@ -0,0 +1 @@ +../../../../pos_partner_pricelist_load_background \ No newline at end of file diff --git a/setup/pos_partner_pricelist_load_background/setup.py b/setup/pos_partner_pricelist_load_background/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/pos_partner_pricelist_load_background/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)