Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD][16.0] point_of_sale: add hook to get product data #97

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
Open
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
46 changes: 29 additions & 17 deletions addons/point_of_sale/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,10 @@ 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
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,
Expand All @@ -103,6 +88,33 @@ 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 = []
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'
Expand Down