From 6febd30f81ccdef9e85fbf14f828d092656ace80 Mon Sep 17 00:00:00 2001 From: wilson gomez Date: Wed, 12 Jan 2022 09:35:56 -0500 Subject: [PATCH] minor fix --- stock.py | 76 +++++++++++++++++---------- view/warehouse_report_start_form.xml | 5 +- warehouse.fods | Bin 18902 -> 19362 bytes 3 files changed, 52 insertions(+), 29 deletions(-) diff --git a/stock.py b/stock.py index d8bf424..a447963 100644 --- a/stock.py +++ b/stock.py @@ -291,8 +291,12 @@ class WarehouseStockStart(ModelView): to_date = fields.Date('To Date', required=True) only_minimal_level = fields.Boolean('Only Minimal Level') group_by_location = fields.Boolean('Group By Location') + group_by_supplier = fields.Boolean('Group By Supplier') category = fields.Many2One('product.category', 'Category') - supplier = fields.Many2One('party.party', 'Supplier') + suppliers = fields.Many2Many('party.party', None, None, "Suppliers", + domain=[ + ('active', '=', True) + ]) zero_quantity = fields.Boolean('Zero Quantity') @staticmethod @@ -317,21 +321,19 @@ class WarehouseStock(Wizard): def do_print_(self, action): category_id = None - supplier_id = None if self.start.category: category_id = self.start.category.id - if self.start.supplier: - supplier_id = self.start.supplier.id data = { 'company': self.start.company.id, 'locations': [l.id for l in self.start.locations], 'location_names': ', '.join([l.name for l in self.start.locations]), 'only_minimal_level': self.start.only_minimal_level, 'group_by_location': self.start.group_by_location, + 'group_by_supplier': self.start.group_by_supplier, 'zero_quantity': self.start.zero_quantity, 'to_date': self.start.to_date, 'category': category_id, - 'supplier': supplier_id, + 'suppliers': [l.id for l in self.start.suppliers], } return action, data @@ -348,7 +350,7 @@ class WarehouseReport(Report): Product = pool.get('product.product') OrderPoint = pool.get('stock.order_point') Location = pool.get('stock.location') - ProductsSupplier = pool.get('purchase.product_supplier') + # ProductsSupplier = pool.get('purchase.product_supplier') ids_location = data['locations'] locations = Location.browse(data['locations']) dom_products = [ @@ -384,15 +386,8 @@ class WarehouseReport(Report): products_ids = min_quantities.keys() dom_products.append(('id', 'in', products_ids)) - - supplier = None - if data['supplier']: - products_supplier = ProductsSupplier.search([ - ('party', '=', data['supplier']), - ]) - supplier = products_supplier[0].party.name - products_ids = [ps.product.id for ps in products_supplier] - dom_products.append(('template', 'in', products_ids)) + if data['suppliers']: + dom_products.append([('template.product_suppliers', 'in', data['suppliers'])]) total_amount = 0 values = {} @@ -402,27 +397,55 @@ class WarehouseReport(Report): stock_context['locations'] = [l.id] with Transaction().set_context(stock_context): prdts = Product.search(dom_products, order=[('code', 'ASC')]) - p = [p.id for p in prdts] - products_supplier = ProductsSupplier.search([ - ('product', 'in', p)]) - prod_sup = dict((p.product.id, p.party.name) for p in products_supplier) + # p = [p.template.id for p in prdts] + # products_supplier = ProductsSupplier.search([ + # ('template', 'in', p)]) + suppliers = {} + if data['group_by_supplier']: + for p in prdts: + if not p.template.product_suppliers: + continue + sup = p.template.product_suppliers[0].party + sup_id = sup.id + try: + suppliers[sup_id]['products'].append(p) + suppliers[sup_id]['total_amount'].append(p.cost_value) + except: + suppliers[sup_id] = {} + suppliers[sup_id]['products'] = [p] + suppliers[sup_id]['party'] = sup + suppliers[sup_id]['total_amount'] = [p.cost_value] total_amount = sum([p.cost_value for p in prdts if p.cost_value]) values[l.id] = { 'name': l.name, 'products': prdts, + 'suppliers': suppliers.values(), 'total_amount': total_amount } products = values.values() else: with Transaction().set_context(stock_context): products = Product.search(dom_products, order=[('code', 'ASC')]) - p = [p.id for p in products] + + if data['only_minimal_level']: + products = [p for p in products if p.quantity <= min_quantities[p.id]] total_amount = sum([p.cost_value for p in products if p.cost_value]) - products_supplier = ProductsSupplier.search([ - ('product', 'in', p)]) - prod_sup = dict((p.product.id, p.party.name) for p in products_supplier) - if data['only_minimal_level']: - products = [p for p in products if p.quantity <= min_quantities[p.id]] + suppliers = {} + if data['group_by_supplier']: + for p in products: + if not p.template.product_suppliers: + continue + sup = p.template.product_suppliers[0].party + sup_id = sup.id + try: + suppliers[sup_id]['products'].append(p) + suppliers[sup_id]['total_amount'].append(p.cost_value) + except: + suppliers[sup_id] = {} + suppliers[sup_id]['products'] = [p] + suppliers[sup_id]['party'] = sup + suppliers[sup_id]['total_amount'] = [p.cost_value] + products = suppliers.values() cursor = Transaction().connection.cursor() query = "select distinct on(p.id) p.id, t.name, p.code, s.effective_date from product_product as p right join stock_move as s on p.id=s.product join product_template as t on p.template=t.id where s.shipment ilike 'stock.shipment.in,%' and state='done' order by p.id, s.effective_date DESC;" @@ -438,10 +461,9 @@ class WarehouseReport(Report): last_purchase[row[0]] = row_dict report_context['group_by_location'] = data['group_by_location'] + report_context['group_by_supplier'] = data['group_by_supplier'] report_context['records'] = products - report_context['prod_sup'] = prod_sup report_context['total_amount'] = total_amount - report_context['supplier'] = supplier report_context['last_purchase'] = last_purchase report_context['location'] = data['location_names'] report_context['stock_date_end'] = data['to_date'] diff --git a/view/warehouse_report_start_form.xml b/view/warehouse_report_start_form.xml index 087f703..a744abd 100644 --- a/view/warehouse_report_start_form.xml +++ b/view/warehouse_report_start_form.xml @@ -8,15 +8,16 @@ this repository contains the full copyright notices and license terms. -->