[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) <trj@odoo.com>
This commit is contained in:
Pierrick Brun
2023-03-28 14:50:51 +02:00
committed by Jacky (trj)
parent a99aa4a868
commit fbcd337a95
+17 -5
View File
@@ -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);
}
);
}