Skip to content

Commit

Permalink
Assign pricelist items based on categories
Browse files Browse the repository at this point in the history
  • Loading branch information
santostelmo committed Jan 21, 2025
1 parent ee52209 commit d813f16
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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):
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"] = []

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", "=", False),
("product_tmpl_id", "in", templates.ids),
"|",
("product_id", "=", False),
("product_id", "in", products.ids),
]
breakpoint()
for item in self.env["product.pricelist.item"].search_read(
pricelist_item_domain, self._product_pricelist_item_fields()
):
pricelist["items"].append(item)

alternative_pricelists = []
for alt_pricelist_rec in pricelist_rec.alternative_pricelist_ids:
alternative_pricelists += self.get_pos_ui_partner_pricelist_background(
alt_pricelist_rec.id, product_ids
)
if alternative_pricelists:
return [pricelist] + alternative_pricelists
return [pricelist]
2 changes: 2 additions & 0 deletions pos_partner_pricelist_load_background/models/pos_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def get_pos_ui_partner_pricelist_background(self, pricelist_id, product_ids):
| pricelist_rec.item_ids.product_id
)
templates = products.product_tmpl_id | pricelist_rec.item_ids.product_tmpl_id

Check warning on line 20 in pos_partner_pricelist_load_background/models/pos_session.py

View check run for this annotation

Codecov / codecov/patch

pos_partner_pricelist_load_background/models/pos_session.py#L20

Added line #L20 was not covered by tests
# TODO add also items with with products.categories
pricelist_item_domain = [

Check warning on line 22 in pos_partner_pricelist_load_background/models/pos_session.py

View check run for this annotation

Codecov / codecov/patch

pos_partner_pricelist_load_background/models/pos_session.py#L22

Added line #L22 was not covered by tests
("pricelist_id", "=", pricelist_id),
"|",
Expand All @@ -27,6 +28,7 @@ def get_pos_ui_partner_pricelist_background(self, pricelist_id, product_ids):
("product_id", "=", False),
("product_id", "in", products.ids),
]

for item in self.env["product.pricelist.item"].search_read(
pricelist_item_domain, self._product_pricelist_item_fields()
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@ const PosPartnerPricelistLoadBackgroundSPosGlobalState = (PosGlobalState) =>
pricelistItem
);
}
if (pricelistItem.product_tmpl_id) {
else if (pricelistItem.product_tmpl_id) {
for (const product of Object.values(this.db.product_by_id).filter(
(x) => x.product_tmpl_id === pricelistItem.product_tmpl_id[0]
)) {
this._assignApplicableItems(pricelist, product, pricelistItem);
}
} else {
for (const correspondingProduct of Object.values(this.db.product_by_id).filter(
(x) => x.categ_id
)) {
this._assignApplicableItems(pricelist, correspondingProduct, pricelistItem);
}
}

}
}

Expand Down

0 comments on commit d813f16

Please sign in to comment.