From fd34e7cb2c4c5ca76c61da8abd228f7b3b16e1b1 Mon Sep 17 00:00:00 2001 From: Naresh Choksy Date: Thu, 28 May 2009 18:41:45 +0530 Subject: [PATCH] Improved stock reports bzr revid: nch@tinyerp.com-20090528131145-27y7z2y5q9xv43ti --- addons/stock/report/lot_location.py | 30 +---- addons/stock/report/lot_location.rml | 73 ++++++------ addons/stock/report/lot_overview.py | 54 +++------ addons/stock/report/lot_overview.rml | 143 ++++++++++++----------- addons/stock/report/lot_overview_all.py | 54 +++------ addons/stock/report/lot_overview_all.rml | 94 ++++++++++++--- addons/stock/stock.py | 17 ++- 7 files changed, 230 insertions(+), 235 deletions(-) diff --git a/addons/stock/report/lot_location.py b/addons/stock/report/lot_location.py index 11d44c09abe..e20f89bb81f 100644 --- a/addons/stock/report/lot_location.py +++ b/addons/stock/report/lot_location.py @@ -26,8 +26,7 @@ from report import report_sxw class lot_location(report_sxw.rml_parse): def __init__(self, cr, uid, name, context): super(lot_location, self).__init__(cr, uid, name, context) - self.quantity_total=0.0 - self.grand_total=0.0 + self.grand_total = 0.0 self.localcontext.update({ 'time': time, @@ -36,30 +35,11 @@ class lot_location(report_sxw.rml_parse): }) def process(self,location_id): - res = {} location_obj = pooler.get_pool(self.cr.dbname).get('stock.location') - product_obj = pooler.get_pool(self.cr.dbname).get('product.product') - self.quantity_total=0.0 - res['location_name'] = pooler.get_pool(self.cr.dbname).get('stock.location').read(self.cr, self.uid, [location_id],['name'])[0]['name'] - - prod_info = location_obj._product_get(self.cr, self.uid, location_id) - - res['product'] = [] - for prod in product_obj.browse(self.cr, self.uid, prod_info.keys()): - if prod_info[prod.id]: - res['product'].append({'prod_name': prod.name, 'prod_qty': str(prod_info[prod.id])}) - self.quantity_total+=prod_info[prod.id] - self.grand_total+=prod_info[prod.id] - if not res['product']: - res['product'].append({'prod_name': '', 'prod_qty': ''}) - location_child = location_obj.read(self.cr, self.uid, [location_id], ['child_ids']) - res['total'] = self.quantity_total - list=[] - list.append(res) - - for child_id in location_child[0]['child_ids']: - list.extend(self.process(child_id)) - return list + data = location_obj._product_get_report(self.cr,self.uid, [location_id]) + data['location_name'] = location_obj.read(self.cr, self.uid, [location_id],['name'])[0]['name'] + self.grand_total += data['total'] + return [data] def _qty_total(self): return str( self.grand_total) diff --git a/addons/stock/report/lot_location.rml b/addons/stock/report/lot_location.rml index cbecbfe6ddf..ef7be095740 100644 --- a/addons/stock/report/lot_location.rml +++ b/addons/stock/report/lot_location.rml @@ -20,21 +20,18 @@ - + - - - + - - - + + @@ -42,6 +39,7 @@ + @@ -49,6 +47,7 @@ + @@ -61,58 +60,60 @@ - [[ repeatIn(objects,'o') ]] -
- - Location - - - Product - - - Quantity - + Location + Product + Quantity - [[ repeatIn(process(o.id),'ob') ]] - + [[ repeatIn(objects,'o') ]] +
+ [[ repeatIn(process(o.id),'ob') ]] + [[ ob['location_name'] ]] + [[ repeatIn(ob['product'], 'p') ]] - [[ p['prod_name'] or 'There is no product in this location' ]] - [[ p['prod_qty'] or 0.00 ]] + [[ p['prod_name'] ]] + [[ p['prod_qty'] ]] + [[ p['uom'] ]] - - - + - - Total : [[ formatLang(ob['total']) ]] + Total : + [[ ob['total'] ]] + Units - - - + + + + + + + + + +
-
- +
+ - - - Grand Total: [[ qty_total() ]] + Grand Total: + + [[ qty_total() ]] + Units -
diff --git a/addons/stock/report/lot_overview.py b/addons/stock/report/lot_overview.py index 135c8cfd5a3..3ecd26476df 100644 --- a/addons/stock/report/lot_overview.py +++ b/addons/stock/report/lot_overview.py @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- ############################################################################## # -# OpenERP, Open Source Management Solution +# OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved # $Id$ # @@ -27,56 +27,28 @@ class lot_overview(report_sxw.rml_parse): def __init__(self, cr, uid, name, context): super(lot_overview, self).__init__(cr, uid, name, context) self.price_total = 0.0 + self.grand_total = 0.0 self.localcontext.update({ 'time': time, 'process':self.process, 'price_total': self._price_total, + 'grand_total_price':self._grand_total, }) def process(self,location_id): - res = {} location_obj = pooler.get_pool(self.cr.dbname).get('stock.location') - product_obj = pooler.get_pool(self.cr.dbname).get('product.product') - - product_ids = product_obj.search(self.cr, self.uid, []) + data = location_obj._product_get_report(self.cr,self.uid, [location_id]) + data['location_name'] = location_obj.read(self.cr, self.uid, [location_id],['name'])[0]['name'] + self.price_total = 0.0 + self.price_total += data['total_price'] + self.grand_total += data['total_price'] + return [data] - products = product_obj.browse(self.cr,self.uid, product_ids) - products_by_uom = {} - products_by_id = {} - for product in products: - products_by_uom.setdefault(product.uom_id.id, []) - products_by_uom[product.uom_id.id].append(product) - products_by_id.setdefault(product.id, []) - products_by_id[product.id] = product - - result = [] -# res['prod'] = [] - for id in self.ids: - for uom_id in products_by_uom.keys(): - fnc = location_obj._product_get - qty = fnc(self.cr, self.uid, id, [x.id for x in products_by_uom[uom_id]]) - for product_id in qty.keys(): - if not qty[product_id]: - continue - product = products_by_id[product_id] - value=(product.standard_price)*(qty[product_id]) - self.price_total += value - result.append({ - - 'name': product.name, - 'variants': product.variants or '', - 'code': product.default_code, - 'amount': str(qty[product_id]), - 'uom': product.uom_id.name, - 'price': str(product.standard_price), - 'value':str(value), - }) - - - return result - def _price_total(self): - return str( self.price_total) + return str( self.price_total) + + def _grand_total(self): + return str( self.grand_total) report_sxw.report_sxw('report.lot.stock.overview', 'stock.location', 'addons/stock/report/lot_overview.rml', parser=lot_overview) diff --git a/addons/stock/report/lot_overview.rml b/addons/stock/report/lot_overview.rml index a2bef2dbd21..6820d1c497a 100644 --- a/addons/stock/report/lot_overview.rml +++ b/addons/stock/report/lot_overview.rml @@ -13,24 +13,29 @@ - - - - - - + - + + + + + + + - - - + + + + + + + @@ -39,12 +44,17 @@ + - + + + + + @@ -58,78 +68,69 @@ - - -
- + - - Product - - - Variants - - - Quantity - - - UoM - - - Unit Price - - - Value - + Location + Product + Variants + Quantity + UoM + Unit Price + Value [[ repeatIn(objects,'o') ]]
- - - - [[ repeatIn(process(o.id),'ob') ]][[ ob['name'] ]] - - - [[ ob['variants'] ]] - - - [[ ob['amount'] ]] - - - [[ ob['uom'] ]] - - - [[ ob['price'] ]] - - - [[ ob['value'] ]] - + [[ repeatIn(process(o.id),'ob') ]] + + + + [[ ob['location_name'] ]] + + + + + + + + + [[ repeatIn(ob['product'],'p') ]] + [[ p['prod_name'] ]] + [[ p['variants'] ]] + [[ p['prod_qty'] ]] + [[ p['uom'] ]] + [[ p['price'] ]] + [[ p['price_value'] ]] - - - - + - - - - - - - Total: - - - [[ price_total() ]] - + + Total: + + + + + [[ price_total() ]] - - - + + + +
+ + + Grand Total: + + + + + + [[ grand_total_price() ]] + +
diff --git a/addons/stock/report/lot_overview_all.py b/addons/stock/report/lot_overview_all.py index 7c08f014ee4..2f349d9bd93 100644 --- a/addons/stock/report/lot_overview_all.py +++ b/addons/stock/report/lot_overview_all.py @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- ############################################################################## # -# OpenERP, Open Source Management Solution +# OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved # $Id$ # @@ -27,56 +27,28 @@ class lot_overview_all(report_sxw.rml_parse): def __init__(self, cr, uid, name, context): super(lot_overview_all, self).__init__(cr, uid, name, context) self.price_total = 0.0 + self.grand_total = 0.0 self.localcontext.update({ 'time': time, 'process':self.process, 'price_total': self._price_total, + 'grand_total_price':self._grand_total, }) def process(self,location_id): - res = {} location_obj = pooler.get_pool(self.cr.dbname).get('stock.location') - product_obj = pooler.get_pool(self.cr.dbname).get('product.product') - - product_ids = product_obj.search(self.cr, self.uid, []) + data = location_obj._product_get_all_report(self.cr,self.uid, [location_id]) + data['location_name'] = location_obj.read(self.cr, self.uid, [location_id],['name'])[0]['name'] + self.price_total = 0.0 + self.price_total += data['total_price'] + self.grand_total += data['total_price'] + return [data] - products = product_obj.browse(self.cr,self.uid, product_ids) - products_by_uom = {} - products_by_id = {} - for product in products: - products_by_uom.setdefault(product.uom_id.id, []) - products_by_uom[product.uom_id.id].append(product) - products_by_id.setdefault(product.id, []) - products_by_id[product.id] = product - - result = [] -# res['prod'] = [] - for id in self.ids: - for uom_id in products_by_uom.keys(): - fnc = location_obj._product_get - qty = fnc(self.cr, self.uid, id, [x.id for x in products_by_uom[uom_id]]) - for product_id in qty.keys(): - if not qty[product_id]: - continue - product = products_by_id[product_id] - value=(product.standard_price)*(qty[product_id]) - self.price_total += value - result.append({ - - 'name': product.name, - 'variants': product.variants or '', - 'code': product.default_code, - 'amount': str(qty[product_id]), - 'uom': product.uom_id.name, - 'price': str(product.standard_price), - 'value':str(value), - }) - - - return result - def _price_total(self): - return str( self.price_total) + return str( self.price_total) + + def _grand_total(self): + return str( self.grand_total) report_sxw.report_sxw('report.lot.stock.overview_all', 'stock.location', 'addons/stock/report/lot_overview_all.rml', parser=lot_overview_all) diff --git a/addons/stock/report/lot_overview_all.rml b/addons/stock/report/lot_overview_all.rml index ca137d619de..2f1f30564d6 100644 --- a/addons/stock/report/lot_overview_all.rml +++ b/addons/stock/report/lot_overview_all.rml @@ -21,6 +21,13 @@ + + + + + + + @@ -46,6 +53,8 @@ + + @@ -66,27 +75,59 @@
- Code - Product - Variants - Amount - UoM - Unit Price - Value + + Code + + + Product + + + Variants + + + Amount + + + UoM + + + Unit Price + + + Value + [[repeatIn(objects,'o')]]
+ [[ repeatIn(process(o.id),'ob') ]] + Location :[[ ob['location_name'] ]] - [[ repeatIn(process(o.id),'ob') ]] - [[ ob['code'] ]] - [[ ob['name'] ]] - [[ ob['variants'] ]] - [[ ob['amount'] ]] - [[ ob['uom'] ]] - [[ ob['price'] ]] - [[ ob['value'] ]] + + [[ repeatIn(ob['product'],'p') ]] + + + [[ p['code'] ]] + + + [[ p['prod_name'] ]] + + + [[ p['variants'] ]] + + + [[ p['prod_qty'] ]] + + + [[ p['uom'] ]] + + + [[ p['price'] ]] + + + [[ p['price_value'] ]] + @@ -99,8 +140,12 @@ - Total : - [[ price_total() ]] + + Total: + + + [[ price_total() ]] + @@ -108,5 +153,20 @@
+ + + + + + + + + Grand Total: + + + [[ grand_total_price() ]] + + + diff --git a/addons/stock/stock.py b/addons/stock/stock.py index b8acb06e73f..dd5f0a89fc9 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -205,8 +205,11 @@ class stock_location(osv.osv): products_by_id.setdefault(product.id, []) products_by_id[product.id] = product - result = [] + result = {} + result['product'] = [] for id in ids: + quantity_total = 0.0 + total_price = 0.0 for uom_id in products_by_uom.keys(): fnc = self._product_get if recursive: @@ -219,14 +222,20 @@ class stock_location(osv.osv): if not qty[product_id]: continue product = products_by_id[product_id] - result.append({ + quantity_total += qty[product_id] + price = qty[product_id] * product.standard_price + total_price += price + result['product'].append({ 'price': product.standard_price, - 'name': product.name, + 'prod_name': product.name, 'code': product.default_code, # used by lot_overview_all report! 'variants': product.variants or '', 'uom': product.uom_id.name, - 'amount': qty[product_id], + 'prod_qty': qty[product_id], + 'price_value':price, }) + result['total'] = quantity_total + result['total_price'] = total_price return result def _product_get_multi_location(self, cr, uid, ids, product_ids=False, context={}, states=['done'], what=('in', 'out')):