Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions pos_partner_pricelist_load_background/README.rst
Original file line number Diff line number Diff line change
@@ -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.

**With 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 <https://github.com/camptocamp/pos/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 <https://github.com/camptocamp/pos/issues/new?body=module:%20pos_partner_pricelist_load_background%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* Camptocamp

Contributors
~~~~~~~~~~~~

* Telmo Santos <telmo.santos@camptocamp.com>
* Iván Todorovich <ivan.todorovich@camptocamp.com>

Maintainers
~~~~~~~~~~~

This module is part of the `camptocamp/pos <https://github.com/camptocamp/pos/tree/16.0/pos_partner_pricelist_load_background>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions pos_partner_pricelist_load_background/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions pos_partner_pricelist_load_background/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
],
},
}
1 change: 1 addition & 0 deletions pos_partner_pricelist_load_background/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import pos_session
75 changes: 75 additions & 0 deletions pos_partner_pricelist_load_background/models/pos_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 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_background(self, pricelist_id, product_ids):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to see a docstring and a test for this

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added doc string and unit test.

"""
Retrieve the pricelist details for the POS UI in the background.
This method fetches the pricelist information for a given pricelist ID and a
list of product IDs. It constructs the pricelist data including its items and
handles base pricelists if applicable.
Args:
pricelist_id (int): The ID of the pricelist to retrieve.
product_ids (list): A list of product IDs to include in the pricelist.
Returns:
list: A list containing the pricelist details and any base pricelists.
"""

if pricelist_id in self.env.context.get("loaded_pricelist_ids", []):
return []
self = self.with_context(
loaded_pricelist_ids=self.env.context.get("loaded_pricelist_ids", [])
+ [pricelist_id]
)
params = self._loader_params_product_pricelist()
fnames = params["search_params"]["fields"]
pricelist_rec = self.env["product.pricelist"].browse(pricelist_id)
pricelist = pricelist_rec.read(fnames)[0]
pricelist["items"] = []
base_pricelists = []
base_pricelists_recs = self.env["product.pricelist"]
products = (
self.env["product.product"].browse(product_ids)
| pricelist_rec.item_ids.product_id
)
templates = products.product_tmpl_id | pricelist_rec.item_ids.product_tmpl_id

pricelist_item_domain = [
("pricelist_id", "=", pricelist_id),
"|",
"|",
"|",
("product_tmpl_id", "in", templates.ids),
("product_id", "in", products.ids),
("categ_id", "!=", False),
("applied_on", "=", "3_global"),
]
for item in self.env["product.pricelist.item"].search_read(
pricelist_item_domain, self._product_pricelist_item_fields()
):
# Collect base pricelist
if (
item.get("base") == "pricelist"
and item.get("base_pricelist_id")
and item.get("base_pricelist_id") not in base_pricelists
):
base_pricelists_recs |= self.env["product.pricelist"].browse(
item.get("base_pricelist_id")[0]
)
pricelist["items"].append(item)

# Load base pricelists
for base_pricelist_rec in base_pricelists_recs:
# For modules overriding get_pos_ui_partner_pricelist_background
# base_pricelist indicates that we are in the context of a base pricelist
base_pricelist_self = self.with_context(base_pricelist=True)
base_pricelists += (
base_pricelist_self.get_pos_ui_partner_pricelist_background(
base_pricelist_rec.id, product_ids
)
)
return [pricelist] + base_pricelists
2 changes: 2 additions & 0 deletions pos_partner_pricelist_load_background/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Telmo Santos <telmo.santos@camptocamp.com>
* Iván Todorovich <ivan.todorovich@camptocamp.com>
9 changes: 9 additions & 0 deletions pos_partner_pricelist_load_background/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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.

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