=== added directory 'stock_picking_webkit' === added file 'stock_picking_webkit/__init__.py' --- stock_picking_webkit/__init__.py 1970-01-01 00:00:00 +0000 +++ stock_picking_webkit/__init__.py 2012-07-12 13:56:17 +0000 @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (c) 2011 Camptocamp SA (http://www.camptocamp.com) +# @author Nicolas Bessi +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# 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 2 +# 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, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +import report === added file 'stock_picking_webkit/__openerp__.py' --- stock_picking_webkit/__openerp__.py 1970-01-01 00:00:00 +0000 +++ stock_picking_webkit/__openerp__.py 2012-07-12 13:56:17 +0000 @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (c) 2011 Camptocamp SA (http://www.camptocamp.com) +# @author Nicolas Bessi +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# 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 2 +# 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, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +{ + 'name': 'Picking report using Webkit Library', + 'version': '1.0', + 'category': 'Reports/Webkit', + 'description': """ +Replaces the legacy rml picking Order report by a brand new webkit report. + """, + 'author': 'Camptocamp', + 'website': 'http://www.openerp.com', + 'depends': ['base', 'report_webkit', 'base_headers_webkit', 'stock'], + 'init_xml': [], + 'update_xml': ['report.xml'], + 'demo_xml': [], + 'test': [], + 'installable': True, + 'active': False, +} === added directory 'stock_picking_webkit/report' === added file 'stock_picking_webkit/report.xml' --- stock_picking_webkit/report.xml 1970-01-01 00:00:00 +0000 +++ stock_picking_webkit/report.xml 2012-07-12 13:56:17 +0000 @@ -0,0 +1,25 @@ + + + + + + + + + === added file 'stock_picking_webkit/report/__init__.py' --- stock_picking_webkit/report/__init__.py 1970-01-01 00:00:00 +0000 +++ stock_picking_webkit/report/__init__.py 2012-07-12 13:56:17 +0000 @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (c) 2011 Camptocamp SA (http://www.camptocamp.com) +# @author Nicolas Bessi +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# 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 2 +# 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, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## +import stock_report === added file 'stock_picking_webkit/report/delivery.html.mako' --- stock_picking_webkit/report/delivery.html.mako 1970-01-01 00:00:00 +0000 +++ stock_picking_webkit/report/delivery.html.mako 2012-07-12 13:56:17 +0000 @@ -0,0 +1,55 @@ + + + + + +<%from datetime import date %> +${_('Date')}: ${formatLang(str(date.today()), date=True)}   +          ${_('Done by')}: ${user.name}            ${_('Visa')}:_________________ +
+
+${_('Company')}: ${user.company_id.name} +
+
+%for aggr in objects: + + + + + + + + + + %for move in aggr.moves_by_sale_order(): + + + + + + + + %endfor +
${aggr.src_stock.name} => ${aggr.dest_stock.name}
${_('Product Code')}${_('Product')}${_('QTY')}${_('origin')}${_('Carrier')}
${move.product_id.default_code}${move.product_id.name}${move.product_qty and formatLang(move.product_qty) or ' '}${move.picking_id.origin}${move.picking_id.carrier_id and move.picking_id.carrier_id.partner_id.name or ''}
+
+ + + + + + + + %for product, qty in aggr.product_quantity(): + + + + + + %endfor +
${_('Products summary')}
${_('Product Code')}${_('Product')}${_('QTY')}
${product.default_code}${product.name}${qty}
+
+%endfor + + === added file 'stock_picking_webkit/report/picking.html.mako' --- stock_picking_webkit/report/picking.html.mako 1970-01-01 00:00:00 +0000 +++ stock_picking_webkit/report/picking.html.mako 2012-07-12 13:56:17 +0000 @@ -0,0 +1,41 @@ + + + + + +<%from datetime import date %> +${_('Date')}: ${formatLang(str(date.today()), date=True)}   +          ${_('Done by')}: ${user.name}            ${_('Visa')}:_________________ +
+
+${_('Company')}: ${user.company_id.name} +
+
+%for aggr in objects: + + + + + + + + + + + %for move in aggr.moves_by_product(): + + + + + + + + + %endfor +
${aggr.src_stock.name} => ${aggr.dest_stock.name}
${_('Product Code')}${_('Picking')}${_('Product')}${_('QTY')}${_('origin')}${_('Carrier')}
${move.product_id.default_code}${move.picking_id.name}${move.product_id.name}${formatLang(move.product_qty)}${move.picking_id.origin}${move.picking_id.carrier_id and move.picking_id.carrier_id.partner_id.name or ''}
+
+%endfor + + === added file 'stock_picking_webkit/report/stock_report.py' --- stock_picking_webkit/report/stock_report.py 1970-01-01 00:00:00 +0000 +++ stock_picking_webkit/report/stock_report.py 2012-07-12 13:56:17 +0000 @@ -0,0 +1,129 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (c) 2011 Camptocamp SA (http://www.camptocamp.com) +# @author Nicolas Bessi +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# 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 2 +# 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. +# +## -*- coding: utf-8 -*- +import operator +from report import report_sxw +import pooler + +class NullMove(object): + """helper class to generate empty lines in the delivery report""" + def __init__(self): + self.product_id = NullObj() + self.picking_id = NullObj() + self.product_qty = '' + +class NullObj(object): + """the null obj has any attribute you want with an empty string as the value""" + def __getattr__(self, attr): + return '' + + +class PickingAgregation(object): + + def __init__(self, src_stock, dest_stock, stock_moves): + self.src_stock = src_stock + self.dest_stock = dest_stock + self.stock_moves = stock_moves + + def exists(self): + return False + + def __hash__(self): + return hash((self.src_stock.id, self.dest_stock.id)) + + def __eq__(self, other): + return (self.src_stock.id, self.dest_stock.id) == (other.src_stock.id, other.dest_stock.id) + + def moves_by_product(self): + """iterate over moves sorted by product default_code""" + return sorted(self.stock_moves, key=operator.attrgetter('product_id.default_code')) + + def moves_by_sale_order(self): + """iterate over moves sorted by sale order name + + a NullMove is inserted when for each new sale order so that + the report displays an empty line + """ + origin = None + for move in sorted(self.stock_moves, key=operator.attrgetter('picking_id.origin')): + if origin is None: + origin = move.picking_id.origin + else: + if move.picking_id.origin != origin: + yield NullMove() + origin = move.picking_id.origin + yield move + + def product_quantity(self): + """iterate over the different products concerned by the moves + with their total quantity, sorted by product default_code""" + products = {} + product_qty = {} + for move in self.stock_moves: + p_code = move.product_id.default_code + products[p_code] = move.product_id + if p_code not in product_qty: + product_qty[p_code] = move.product_qty + else: + product_qty[p_code] += move.product_qty + for p_code in sorted(products): + yield products[p_code], product_qty[p_code] + +class PrintPick(report_sxw.rml_parse): + + def __init__(self, cursor, uid, name, context): + super(PrintPick, self).__init__(cursor, uid, name, context=context) + self.pool = pooler.get_pool(self.cr.dbname) + self.cursor = self.cr + + self.numeration_type = False + self.localcontext.update({}) + + def _get_form_param(self, param, data, default=False): + return data.get('form', {}).get(param, default) or default + + def set_context(self, objects, data, ids, report_type=None): + """Return res.partner.category""" + #!! data form is manually set in wizard + agreg = {} + for pick in objects: + for move in pick.move_lines: + if move.state == 'assigned': + key = (move.location_id, move.location_dest_id) + agreg.setdefault(key, []).append(move) + objects = [] + for agr in agreg: + print agr + objects.append(PickingAgregation(agr[0], agr[1], agreg[agr])) + return super(PrintPick, self).set_context(objects, data, ids, report_type=report_type) + +report_sxw.report_sxw('report.webkit.aggregated_picking', + 'stock.picking', + 'addons/stock_picking_webkit/report/picking.html.mako', + parser=PrintPick) + +report_sxw.report_sxw('report.webkit.aggregated_delivery', + 'stock.picking', + 'addons/stock_picking_webkit/report/delivery.html.mako', + parser=PrintPick)