From fbcd337a95d682e3e4c5a6ead98cb7393f9ebfec Mon Sep 17 00:00:00 2001 From: Pierrick Brun Date: Mon, 6 Mar 2023 15:49:55 +0000 Subject: [PATCH] [REF] point_of_sale: help inherit pricelist items in get_price This commit makes the pricelist item selection in the get_price function inheritable Description of the issue/feature this PR addresses: Help inherit the pricelist item selection in the pos get_price function Current behavior before PR: pricelist item in the pos get_price selection is not easily inheritable Desired behavior after PR is merged: pricelist item in the pos get_price selection is easily inheritable closes odoo/odoo#116614 X-original-commit: d2d690a80e5265e55b52e15cc52d01a96174e6fa Signed-off-by: Trinh Jacky (trj) --- addons/point_of_sale/static/src/js/models.js | 22 +++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index a3e817a2399..99caed40dfe 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -1661,6 +1661,15 @@ export function register_payment_method(use_payment_terminal, ImplementedPayment } export class Product extends PosModel { + constructor(obj) { + super(obj); + this.parent_category_ids = []; + let category = this.categ.parent; + while (category) { + this.parent_category_ids.push(category.id); + category = category.parent; + } + } isAllowOnlyOneLot() { const productUnit = this.get_unit(); return this.tracking === "lot" || !productUnit || !productUnit.is_pos_groupable; @@ -1773,6 +1782,13 @@ export class Product extends PosModel { return { draftPackLotLines, quantity: weight, description, price_extra }; } + isPricelistItemUsable(item, date) { + return ( + (!item.categ_id || _.contains(this.parent_category_ids.concat(this.categ.id), item.categ_id[0])) && + (!item.date_start || moment.utc(item.date_start).isSameOrBefore(date)) && + (!item.date_end || moment.utc(item.date_end).isSameOrAfter(date)) + ); + } // Port of _get_product_price on product.pricelist. // // Anything related to UOM can be ignored, the POS will always use @@ -1813,11 +1829,7 @@ export class Product extends PosModel { pricelist_items = _.filter( self.applicablePricelistItems[pricelist.id], function (item) { - return ( - (!item.categ_id || _.contains(category_ids, item.categ_id[0])) && - (!item.date_start || moment.utc(item.date_start).isSameOrBefore(date)) && - (!item.date_end || moment.utc(item.date_end).isSameOrAfter(date)) - ); + return self.isPricelistItemUsable(item, date); } ); }