From 75ffb2e3cdd8906dfce3b37f5ea0aadd56356b09 Mon Sep 17 00:00:00 2001 From: Telmo Santos Date: Wed, 25 Sep 2024 07:21:38 +0200 Subject: [PATCH] [ADD]pos_partner_pricelist_load_background --- .../static/src/js/PartnerMapEdit.esm.js | 1 - .../README.rst | 66 +++ .../__init__.py | 1 + .../__manifest__.py | 19 + .../models/__init__.py | 1 + .../models/pos_session.py | 30 ++ .../readme/CONTRIBUTORS.rst | 2 + .../readme/DESCRIPTION.rst | 9 + .../static/description/index.html | 421 ++++++++++++++++++ .../static/src/js/PosGlobalState.js | 51 +++ .../static/src/js/ProductScreen.js | 29 ++ .../pos_partner_pricelist_load_background | 1 + .../setup.py | 6 + 13 files changed, 636 insertions(+), 1 deletion(-) create mode 100644 pos_partner_pricelist_load_background/README.rst create mode 100644 pos_partner_pricelist_load_background/__init__.py create mode 100644 pos_partner_pricelist_load_background/__manifest__.py create mode 100644 pos_partner_pricelist_load_background/models/__init__.py create mode 100644 pos_partner_pricelist_load_background/models/pos_session.py create mode 100644 pos_partner_pricelist_load_background/readme/CONTRIBUTORS.rst create mode 100644 pos_partner_pricelist_load_background/readme/DESCRIPTION.rst create mode 100644 pos_partner_pricelist_load_background/static/description/index.html create mode 100644 pos_partner_pricelist_load_background/static/src/js/PosGlobalState.js create mode 100644 pos_partner_pricelist_load_background/static/src/js/ProductScreen.js create mode 120000 setup/pos_partner_pricelist_load_background/odoo/addons/pos_partner_pricelist_load_background create mode 100644 setup/pos_partner_pricelist_load_background/setup.py diff --git a/pos_partner_location_abstract/static/src/js/PartnerMapEdit.esm.js b/pos_partner_location_abstract/static/src/js/PartnerMapEdit.esm.js index 921784c384..a1712ffad5 100644 --- a/pos_partner_location_abstract/static/src/js/PartnerMapEdit.esm.js +++ b/pos_partner_location_abstract/static/src/js/PartnerMapEdit.esm.js @@ -1,5 +1,4 @@ /** @odoo-module alias=pos_partner_location_abstract.PartnerMapEdit **/ - import AbstractAwaitablePopup from "point_of_sale.AbstractAwaitablePopup"; import Registries from "point_of_sale.Registries"; import {useRef} from "@odoo/owl"; diff --git a/pos_partner_pricelist_load_background/README.rst b/pos_partner_pricelist_load_background/README.rst new file mode 100644 index 0000000000..5e4190922a --- /dev/null +++ b/pos_partner_pricelist_load_background/README.rst @@ -0,0 +1,66 @@ +==================================== +POS Partner Pricelist Lod 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..a110c5db6c --- /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 Lod Background", + "summary": "", + "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..9176852c08 --- /dev/null +++ b/pos_partner_pricelist_load_background/models/pos_session.py @@ -0,0 +1,30 @@ +# 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): + product_ids = ( + self.env["product.pricelist.item"] + .search([("pricelist_id", "=", pricelist_id)]) + .mapped("product_id") + .ids + ) + + return self.get_pos_ui_product_product_by_params( + {"domain": [["id", "in", product_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..b366c38c9b --- /dev/null +++ b/pos_partner_pricelist_load_background/static/description/index.html @@ -0,0 +1,421 @@ + + + + + + +POS Partner Pricelist Lod Background + + + +
+

POS Partner Pricelist Lod 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..742cab30d5 --- /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"; + + var {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, +)