From 0ddc4083e886ee8df514615876eb19551a3e6da5 Mon Sep 17 00:00:00 2001 From: Naresh Choksy Date: Wed, 27 May 2009 19:12:15 +0530 Subject: [PATCH 1/5] improved stock reports: continued..... bzr revid: nch@tinyerp.com-20090527134215-kz7nmyv4em9ydsby --- addons/stock/report/__init__.py | 2 + addons/stock/report/lot_location.py | 18 ++- addons/stock/report/lot_location.rml | 119 +++++++++++++++++++- addons/stock/report/lot_overview.py | 85 ++++++++++++++ addons/stock/report/lot_overview.rml | 135 +++++++++++++++++++++++ addons/stock/report/lot_overview.xml | 13 --- addons/stock/report/lot_overview.xsl | 71 ------------ addons/stock/report/lot_overview_all.py | 85 ++++++++++++++ addons/stock/report/lot_overview_all.rml | 112 +++++++++++++++++++ addons/stock/report/lot_overview_all.xml | 14 --- addons/stock/report/lot_overview_all.xsl | 70 ------------ addons/stock/report/picking.rml | 32 +++--- addons/stock/stock.py | 6 +- addons/stock/stock_report.xml | 4 +- 14 files changed, 572 insertions(+), 194 deletions(-) create mode 100644 addons/stock/report/lot_overview.py create mode 100644 addons/stock/report/lot_overview.rml delete mode 100644 addons/stock/report/lot_overview.xml delete mode 100644 addons/stock/report/lot_overview.xsl create mode 100644 addons/stock/report/lot_overview_all.py create mode 100644 addons/stock/report/lot_overview_all.rml delete mode 100644 addons/stock/report/lot_overview_all.xml delete mode 100644 addons/stock/report/lot_overview_all.xsl diff --git a/addons/stock/report/__init__.py b/addons/stock/report/__init__.py index 9bddb1854ff..f69fc033c45 100644 --- a/addons/stock/report/__init__.py +++ b/addons/stock/report/__init__.py @@ -25,6 +25,8 @@ import product_stock import lot_location import ups import picking +import lot_overview +import lot_overview_all # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/stock/report/lot_location.py b/addons/stock/report/lot_location.py index 931ddd909c9..11d44c09abe 100644 --- a/addons/stock/report/lot_location.py +++ b/addons/stock/report/lot_location.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$ # @@ -26,16 +26,20 @@ 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.localcontext.update({ 'time': time, 'process':self.process, + 'qty_total':self._qty_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') - + 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) @@ -43,17 +47,23 @@ class lot_location(report_sxw.rml_parse): 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': 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 + def _qty_total(self): + return str( self.grand_total) + report_sxw.report_sxw('report.lot.location', 'stock.location', 'addons/stock/report/lot_location.rml', parser=lot_location) diff --git a/addons/stock/report/lot_location.rml b/addons/stock/report/lot_location.rml index abf27ec97e6..cbecbfe6ddf 100644 --- a/addons/stock/report/lot_location.rml +++ b/addons/stock/report/lot_location.rml @@ -1,3 +1,118 @@ -
LocationProductQuantity[[ repeatIn(objects,'o') ]]
[[ repeatIn(process(o.id),'ob') ]][[ ob ['location_name'] ]] [[ repeatIn(ob['product'], 'p') ]][[ p['prod_name'] ]][[ p['prod_qty'] ]]
- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [[ repeatIn(objects,'o') ]] + +
+ + + + Location + + + Product + + + Quantity + + + + [[ 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 ]] + + + + + + + + + Total : [[ formatLang(ob['total']) ]] + + + + + + + +
+
+ + + + + Grand Total: [[ qty_total() ]] + + +
+
+
diff --git a/addons/stock/report/lot_overview.py b/addons/stock/report/lot_overview.py new file mode 100644 index 00000000000..135c8cfd5a3 --- /dev/null +++ b/addons/stock/report/lot_overview.py @@ -0,0 +1,85 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved +# $Id$ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################## +import pooler +import time +from report import report_sxw + +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.localcontext.update({ + 'time': time, + 'process':self.process, + 'price_total': self._price_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, []) + + 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) + +report_sxw.report_sxw('report.lot.stock.overview', 'stock.location', 'addons/stock/report/lot_overview.rml', parser=lot_overview) + + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/addons/stock/report/lot_overview.rml b/addons/stock/report/lot_overview.rml new file mode 100644 index 00000000000..a2bef2dbd21 --- /dev/null +++ b/addons/stock/report/lot_overview.rml @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + 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'] ]] + + + + + + + + + + + + + + + Total: + + + [[ price_total() ]] + + + + + + +
+
+
+
diff --git a/addons/stock/report/lot_overview.xml b/addons/stock/report/lot_overview.xml deleted file mode 100644 index 4fa56808938..00000000000 --- a/addons/stock/report/lot_overview.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/addons/stock/report/lot_overview.xsl b/addons/stock/report/lot_overview.xsl deleted file mode 100644 index 0244bcaa609..00000000000 --- a/addons/stock/report/lot_overview.xsl +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ProductVariantsAmountUoMUnit PriceValue - - - - - - - - - - - - - - - - - - - - - - diff --git a/addons/stock/report/lot_overview_all.py b/addons/stock/report/lot_overview_all.py new file mode 100644 index 00000000000..7c08f014ee4 --- /dev/null +++ b/addons/stock/report/lot_overview_all.py @@ -0,0 +1,85 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved +# $Id$ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################## +import pooler +import time +from report import report_sxw + +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.localcontext.update({ + 'time': time, + 'process':self.process, + 'price_total': self._price_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, []) + + 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) + +report_sxw.report_sxw('report.lot.stock.overview_all', 'stock.location', 'addons/stock/report/lot_overview_all.rml', parser=lot_overview_all) + + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/addons/stock/report/lot_overview_all.rml b/addons/stock/report/lot_overview_all.rml new file mode 100644 index 00000000000..ca137d619de --- /dev/null +++ b/addons/stock/report/lot_overview_all.rml @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + Code + Product + Variants + Amount + UoM + Unit Price + Value + + + [[repeatIn(objects,'o')]] +
+ + + [[ repeatIn(process(o.id),'ob') ]] + [[ ob['code'] ]] + [[ ob['name'] ]] + [[ ob['variants'] ]] + [[ ob['amount'] ]] + [[ ob['uom'] ]] + [[ ob['price'] ]] + [[ ob['value'] ]] + + + + + + + + + + + + + Total : + [[ price_total() ]] + + + + + +
+
+
+
diff --git a/addons/stock/report/lot_overview_all.xml b/addons/stock/report/lot_overview_all.xml deleted file mode 100644 index a7c19977499..00000000000 --- a/addons/stock/report/lot_overview_all.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/addons/stock/report/lot_overview_all.xsl b/addons/stock/report/lot_overview_all.xsl deleted file mode 100644 index c78b8f63bfa..00000000000 --- a/addons/stock/report/lot_overview_all.xsl +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CodeProductVariantsAmountUoMUnit PriceValue - - - - - - - - - - - - - - - - - - - - - diff --git a/addons/stock/report/picking.rml b/addons/stock/report/picking.rml index d9e50d2b5ba..f6cf2387433 100644 --- a/addons/stock/report/picking.rml +++ b/addons/stock/report/picking.rml @@ -134,10 +134,10 @@ - [[ (picking.address_id and picking.address_id.partner_id and picking.address_id.partner_id.title) or '' ]] [[ picking.address_id and picking.address_id.partner_id and picking.address_id.partner_id.name ]] - [[ (picking.address_id and picking.address_id.title) or '' ]] [[ (picking.address_id and picking.address_id.name) or '' ]] - [[ (picking.address_id and picking.address_id.street) or '' ]] - [[ (picking.address_id and picking.address_id.zip) or '' ]] [[ (picking.address_id and picking.address_id.city) or '' ]] [[ (picking.address_id and picking.address_id.state_id and picking.address_id.state_id.name) or '' ]] + [[ (picking.address_id and picking.address_id.partner_id and picking.address_id.partner_id.title) or '' ]][[ picking.address_id and picking.address_id.partner_id and picking.address_id.partner_id.name ]] + [[ (picking.sale_id and picking.sale_id.partner_shipping_id and picking.sale_id.partner_shipping_id.title) or '' ]][[ (picking.sale_id and picking.sale_id.partner_shipping_id and picking.sale_id.partner_shipping_id.name) or '' ]] + [[ (picking.sale_id and picking.sale_id.partner_shipping_id and picking.sale_id.partner_shipping_id.street) or '' ]] + [[ (picking.sale_id and picking.sale_id.partner_shipping_id and picking.sale_id.partner_shipping_id.zip) or '' ]][[ (picking.sale_id and picking.sale_id.partner_shipping_id and picking.sale_id.partner_shipping_id.city) or '' ]][[ (picking.address_id and picking.address_id.state_id and picking.address_id.state_id.name) or '' ]] [[ (picking.address_id and picking.address_id.country_id and picking.address_id.country_id.name) or '' ]] @@ -176,7 +176,7 @@ Expected Shipping Date - + weight @@ -186,13 +186,13 @@ [[ picking.origin ]] - [[ (picking.address_id and picking.address_id.title) or '' ]] [[ (picking.address_id and picking.address_id.name) or '' ]] + [[ (picking.sale_id and picking.sale_id.partner_shipping_id and picking.sale_id.partner_shipping_id and picking.sale_id.partner_shipping_id.title) or '' ]][[ (picking.sale_id and picking.sale_id.partner_shipping_id and picking.sale_id.partner_shipping_id.name) or '' ]] - [[ formatLang(picking.min_date,date_time = True) ]] + [[ formatLang(picking.min_date,date_time = True) ]] - + [[ formatLang(picking.weight) ]] @@ -218,7 +218,9 @@ - + + +
[[ repeatIn([line for line in picking.move_lines if (line.state == 'assigned' )],'move_lines') ]] @@ -227,13 +229,13 @@ [ [[ move_lines.product_id.default_code ]] ] [[ move_lines.product_id.name ]] - [[ (move_lines.prodlot_id and move_lines.prodlot_id.name) or '' ]] + [[ (move_lines.prodlot_id and move_lines.prodlot_id.name) or '' ]] [[ move_lines.state ]] - [[ move_lines.product_qty ]] + [[ formatLang(move_lines.product_qty) ]] [[ move_lines.product_uom.name ]] @@ -250,25 +252,25 @@ - Non Assigned Products: [[ (line.state == 'assigned') and removeParentNode('para') ]] + Non Assigned Products: [[ ((line.state == 'assigned') or (line.state == 'done')) and removeParentNode('para') ]]
- [[ repeatIn([line for line in picking.move_lines if (line.state != 'assigned' )],'move_lines') ]] + [[ repeatIn([line for line in picking.move_lines if (line.state != 'assigned' )],'move_lines') ]] [ [[ move_lines.product_id.default_code ]] ] [[ move_lines.product_id.name ]] - [[ (move_lines.prodlot_id and move_lines.prodlot_id.name) or '' ]] + [[ (move_lines.prodlot_id and move_lines.prodlot_id.name) or '' ]] [[ move_lines.state ]] - [[ move_lines.product_qty ]] + [[ formatLang(move_lines.product_qty) ]] [[ move_lines.product_uom.name ]] diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 352709ed0a7..b8acb06e73f 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -791,7 +791,7 @@ class stock_production_lot(osv.osv): ''') res.update(dict(cr.fetchall())) return res - + def _stock_search(self, cr, uid, obj, name, args): locations = self.pool.get('stock.location').search(cr, uid, [('usage','=','internal')]) cr.execute('''select @@ -803,12 +803,12 @@ class stock_production_lot(osv.osv): location_id in ('''+','.join(map(str, locations)) +''') group by prodlot_id - having sum(name) ''' + str(args[0][1]) + ''' ''' + str(args[0][2]) + having sum(name) ''' + str(args[0][1]) + ''' ''' + str(args[0][2]) ) res = cr.fetchall() ids = [('id','in',map(lambda x:x[0], res))] return ids - + _columns = { 'name': fields.char('Serial', size=64, required=True), 'ref': fields.char('Internal Ref', size=64), diff --git a/addons/stock/stock_report.xml b/addons/stock/stock_report.xml index c5ddcf0ed38..ed71ca90635 100644 --- a/addons/stock/stock_report.xml +++ b/addons/stock/stock_report.xml @@ -9,11 +9,11 @@ - + - + From fd34e7cb2c4c5ca76c61da8abd228f7b3b16e1b1 Mon Sep 17 00:00:00 2001 From: Naresh Choksy Date: Thu, 28 May 2009 18:41:45 +0530 Subject: [PATCH 2/5] 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')): From 6bcad2575681f91c4bb176ef20c0d3d8c5cb2ace Mon Sep 17 00:00:00 2001 From: Naresh Choksy Date: Fri, 29 May 2009 11:03:24 +0530 Subject: [PATCH 3/5] Improved Stock Reports bzr revid: nch@tinyerp.com-20090529053324-3ejzedfyo4jkxp4g --- addons/stock/report/lot_location.rml | 1 - addons/stock/report/lot_overview.rml | 1 - addons/stock/report/lot_overview_all.rml | 152 ++++++++++------------- 3 files changed, 68 insertions(+), 86 deletions(-) diff --git a/addons/stock/report/lot_location.rml b/addons/stock/report/lot_location.rml index ef7be095740..001804e75ae 100644 --- a/addons/stock/report/lot_location.rml +++ b/addons/stock/report/lot_location.rml @@ -13,7 +13,6 @@ - diff --git a/addons/stock/report/lot_overview.rml b/addons/stock/report/lot_overview.rml index 6820d1c497a..f62da3ef0d8 100644 --- a/addons/stock/report/lot_overview.rml +++ b/addons/stock/report/lot_overview.rml @@ -83,7 +83,6 @@ [[ repeatIn(objects,'o') ]]
[[ repeatIn(process(o.id),'ob') ]] - [[ ob['location_name'] ]] diff --git a/addons/stock/report/lot_overview_all.rml b/addons/stock/report/lot_overview_all.rml index 2f1f30564d6..e848ba89f6a 100644 --- a/addons/stock/report/lot_overview_all.rml +++ b/addons/stock/report/lot_overview_all.rml @@ -20,6 +20,7 @@ + @@ -31,14 +32,23 @@ - + - - - + + + + + + + + + + + + @@ -47,10 +57,11 @@ - + - + + @@ -73,100 +84,73 @@
- + - - Code - - - Product - - - Variants - - - Amount - - - UoM - - - Unit Price - - - Value - + Location + Code + Product + Variants + Amount + UoM + UnitPrice + Value - [[repeatIn(objects,'o')]] + [[repeatIn(objects,'o')]]
[[ repeatIn(process(o.id),'ob') ]] - Location :[[ ob['location_name'] ]] - + + + [[ ob['location_name'] ]] + + [[ ob['product'] or 'No products in this Location' ]] + + + + + + - - [[ repeatIn(ob['product'],'p') ]] - - - [[ p['code'] ]] - - - [[ p['prod_name'] ]] - - - [[ p['variants'] ]] - - - [[ p['prod_qty'] ]] - - - [[ p['uom'] ]] - - - [[ p['price'] ]] - - - [[ p['price_value'] ]] - + [[ repeatIn(ob['product'],'p') ]] + [[ p['code'] ]] + [[ 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() ]] - + Grand Total: + + + + + + + [[ grand_total_price() ]] - + From ae9626caa4829e8f226921d000041592d24b7e3b Mon Sep 17 00:00:00 2001 From: Naresh Choksy Date: Fri, 29 May 2009 12:03:19 +0530 Subject: [PATCH 4/5] Bugfix:380480 bzr revid: nch@tinyerp.com-20090529063319-9mwtlnbrj3y7399n --- addons/stock/report/picking.rml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/stock/report/picking.rml b/addons/stock/report/picking.rml index f6cf2387433..203ccf64fee 100644 --- a/addons/stock/report/picking.rml +++ b/addons/stock/report/picking.rml @@ -199,7 +199,7 @@ - + Description @@ -223,7 +223,7 @@
[[ repeatIn([line for line in picking.move_lines if (line.state == 'assigned' )],'move_lines') ]] - + [ [[ move_lines.product_id.default_code ]] ] [[ move_lines.product_id.name ]] @@ -241,7 +241,7 @@ [[ move_lines.product_uom.name ]] - [[ (move_lines.location_id and move_lines.location_id.name) or '' ]] + [[ (((picking.type == 'out') and move_lines.location_id.name) or ((picking.type == 'in') and move_lines.location_dest_id.name) or ((picking.type == 'internal') and (move_lines.location_id.name + '-' + move_lines.location_dest_id.name)) or '' ) ]] @@ -258,7 +258,7 @@
[[ repeatIn([line for line in picking.move_lines if (line.state != 'assigned' )],'move_lines') ]] - + [ [[ move_lines.product_id.default_code ]] ] [[ move_lines.product_id.name ]] @@ -276,7 +276,7 @@ [[ move_lines.product_uom.name ]] - [[ (move_lines.location_id and move_lines.location_id.name) or '' ]] + [[ (((picking.type == 'out') and move_lines.location_id.name) or ((picking.type == 'in') and move_lines.location_dest_id.name) or ((picking.type == 'internal') and (move_lines.location_id.name + '-' + move_lines.location_dest_id.name)) or '' ) ]] From 513686a640ed83f75af69432a92a0c6bd75a6367 Mon Sep 17 00:00:00 2001 From: Naresh Choksy Date: Fri, 29 May 2009 14:34:22 +0530 Subject: [PATCH 5/5] corrections in Stock Reports bzr revid: nch@tinyerp.com-20090529090422-x7sa1cykywouebm4 --- .../sale_delivery_report/report/shipping.rml | 2 +- addons/stock/report/lot_location.rml | 6 ++--- addons/stock/report/lot_overview.rml | 22 +++++++++---------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/addons/sale_delivery_report/report/shipping.rml b/addons/sale_delivery_report/report/shipping.rml index 7b02c71c7f8..30061c03352 100644 --- a/addons/sale_delivery_report/report/shipping.rml +++ b/addons/sale_delivery_report/report/shipping.rml @@ -161,7 +161,7 @@ [[ o.sale_id and o.sale_id.name ]] - [[ o.sale_id and o.sale_id.date_order ]] + [[ o.sale_id and formatLang(o.sale_id.date_order,date_time = True) ]] [[ formatLang(o.min_date,date_time = True) ]] diff --git a/addons/stock/report/lot_location.rml b/addons/stock/report/lot_location.rml index 001804e75ae..a075637955f 100644 --- a/addons/stock/report/lot_location.rml +++ b/addons/stock/report/lot_location.rml @@ -73,9 +73,9 @@ [[ ob['location_name'] ]] - - - + [[ ob['product'] or 'No products in this Location !' ]] + + [[ repeatIn(ob['product'], 'p') ]] diff --git a/addons/stock/report/lot_overview.rml b/addons/stock/report/lot_overview.rml index f62da3ef0d8..65c48fa43c1 100644 --- a/addons/stock/report/lot_overview.rml +++ b/addons/stock/report/lot_overview.rml @@ -13,7 +13,7 @@ - + @@ -44,7 +44,7 @@ - + @@ -69,7 +69,7 @@
- + Location Product @@ -83,15 +83,15 @@ [[ repeatIn(objects,'o') ]]
[[ repeatIn(process(o.id),'ob') ]] - + [[ ob['location_name'] ]] - - - - - - + [[ ob['product'] or 'No products in this Location !' ]] + + + + + [[ repeatIn(ob['product'],'p') ]] @@ -103,7 +103,7 @@ [[ p['price_value'] ]] - + Total: