From a4dbcda52700b4d060547af6491c10a3f25ac041 Mon Sep 17 00:00:00 2001 From: Benjamin Willig Date: Mon, 1 Jul 2024 15:58:45 +0200 Subject: [PATCH 1/2] [ADD] point_of_sale: add hook to get product supplier data --- addons/point_of_sale/models/product.py | 27 +++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/addons/point_of_sale/models/product.py b/addons/point_of_sale/models/product.py index 2ab5f86742409..449fbe7d560b6 100644 --- a/addons/point_of_sale/models/product.py +++ b/addons/point_of_sale/models/product.py @@ -78,17 +78,7 @@ def get_product_info_pos(self, price, quantity, pos_config_id): for w in self.env['stock.warehouse'].search([])] # Suppliers - key = itemgetter('partner_id') - supplier_list = [] - for key, group in groupby(sorted(self.seller_ids, key=key), key=key): - for s in list(group): - if not((s.date_start and s.date_start > date.today()) or (s.date_end and s.date_end < date.today()) or (s.min_qty > quantity)): - supplier_list.append({ - 'name': s.partner_id.name, - 'delay': s.delay, - 'price': s.price - }) - break + supplier_list = self._get_product_info_pos_seller(price, quantity, pos_config_id) # Variants variant_list = [{'name': attribute_line.attribute_id.name, @@ -103,6 +93,21 @@ def get_product_info_pos(self, price, quantity, pos_config_id): 'variants': variant_list } + def _get_product_info_pos_seller(self, price, quantity, pos_config_id): + key = itemgetter('partner_id') + supplier_list = [] + for key, group in groupby(sorted(self.seller_ids, key=key), key=key): + for s in list(group): + if not ((s.date_start and s.date_start > date.today()) or ( + s.date_end and s.date_end < date.today()) or (s.min_qty > quantity)): + supplier_list.append({ + 'name': s.partner_id.name, + 'delay': s.delay, + 'price': s.price + }) + break + return supplier_list + class UomCateg(models.Model): _inherit = 'uom.category' From f4817bf16e428ba54be321e33be430aeb521a5c6 Mon Sep 17 00:00:00 2001 From: Benjamin Willig Date: Mon, 1 Jul 2024 16:26:49 +0200 Subject: [PATCH 2/2] [ADD] point_of_sale: add hook to get product warehouse data --- addons/point_of_sale/models/product.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/addons/point_of_sale/models/product.py b/addons/point_of_sale/models/product.py index 449fbe7d560b6..48b2e8a49e95f 100644 --- a/addons/point_of_sale/models/product.py +++ b/addons/point_of_sale/models/product.py @@ -70,12 +70,7 @@ def get_product_info_pos(self, price, quantity, pos_config_id): pricelist_list = [{'name': pl.name, 'price': price_per_pricelist_id[pl.id]} for pl in pricelists] # Warehouses - warehouse_list = [ - {'name': w.name, - 'available_quantity': self.with_context({'warehouse': w.id}).qty_available, - 'forecasted_quantity': self.with_context({'warehouse': w.id}).virtual_available, - 'uom': self.uom_name} - for w in self.env['stock.warehouse'].search([])] + warehouse_list = self._get_product_info_pos_warehouse_list(price, quantity, pos_config_id) # Suppliers supplier_list = self._get_product_info_pos_seller(price, quantity, pos_config_id) @@ -93,6 +88,18 @@ def get_product_info_pos(self, price, quantity, pos_config_id): 'variants': variant_list } + def _get_product_info_pos_warehouse_list(self, price, quantity, pos_config_id): + return [ + {'name': w.name, + 'available_quantity': self.with_context({'warehouse': w.id}).qty_available, + 'forecasted_quantity': self.with_context({'warehouse': w.id}).virtual_available, + 'uom': self.uom_name} + for w in self._get_product_info_pos_warehouses(price, quantity, pos_config_id) + ] + + def _get_product_info_pos_warehouses(self, price, quantity, pos_config_id): + return self.env['stock.warehouse'].search([]) + def _get_product_info_pos_seller(self, price, quantity, pos_config_id): key = itemgetter('partner_id') supplier_list = []