mirror of
https://github.com/OCA/stock-logistics-reporting.git
synced 2025-02-16 17:13:21 +02:00
[MRG] From trunk branch, tests and bugfix. Most improvements are on:
- Margin modules - picking dispatch (better warehouse handling)) - grouping PO - Filter on stock delivers from sales (lp:c2c-addons/6.1 rev 69)
This commit is contained in:
30
stock_picking_webkit/__init__.py
Normal file
30
stock_picking_webkit/__init__.py
Normal file
@@ -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
|
||||
46
stock_picking_webkit/__openerp__.py
Normal file
46
stock_picking_webkit/__openerp__.py
Normal file
@@ -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,
|
||||
}
|
||||
25
stock_picking_webkit/report.xml
Normal file
25
stock_picking_webkit/report.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<report id="webkit_aggregated_picking"
|
||||
name="webkit.aggregated_picking"
|
||||
auto="False"
|
||||
model="stock.picking"
|
||||
file="stock_picking_webkit/report/picking.html.mako"
|
||||
string="Aggregated pickings"
|
||||
report_type="webkit"
|
||||
header="False"
|
||||
webkit_header="base_headers_webkit.base_minimum_reports_portrait_header" />
|
||||
<report id="webkit_aggregated_delivery"
|
||||
name="webkit.aggregated_delivery"
|
||||
auto="False"
|
||||
model="stock.picking"
|
||||
file="stock_picking_webkit/report/delivery.html.mako"
|
||||
string="Aggregated deliveries"
|
||||
report_type="webkit"
|
||||
header="False"
|
||||
webkit_header="base_headers_webkit.base_minimum_reports_portrait_header" />
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
29
stock_picking_webkit/report/__init__.py
Normal file
29
stock_picking_webkit/report/__init__.py
Normal file
@@ -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
|
||||
55
stock_picking_webkit/report/delivery.html.mako
Normal file
55
stock_picking_webkit/report/delivery.html.mako
Normal file
@@ -0,0 +1,55 @@
|
||||
<html>
|
||||
<head>
|
||||
<style type="text/css">
|
||||
${css}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<%from datetime import date %>
|
||||
${_('Date')}: ${formatLang(str(date.today()), date=True)}
|
||||
${_('Done by')}: ${user.name} ${_('Visa')}:_________________
|
||||
<br/>
|
||||
<br/>
|
||||
<b>${_('Company')}: ${user.company_id.name}<b>
|
||||
<br/>
|
||||
<br/>
|
||||
%for aggr in objects:
|
||||
<table style="border:solid 1px" width="100%">
|
||||
<caption><b><u>${aggr.src_stock.name} => ${aggr.dest_stock.name}</u></b></caption>
|
||||
<tr align="left">
|
||||
<th>${_('Product Code')}</th>
|
||||
<th>${_('Product')}</th>
|
||||
<th>${_('QTY')}</th>
|
||||
<th>${_('origin')}</th>
|
||||
<th>${_('Carrier')}</th>
|
||||
</tr>
|
||||
%for move in aggr.moves_by_sale_order():
|
||||
<tr align="left">
|
||||
<td>${move.product_id.default_code}</td>
|
||||
<td>${move.product_id.name}</td>
|
||||
<td>${move.product_qty and formatLang(move.product_qty) or ' '}</td>
|
||||
<td>${move.picking_id.origin}</td>
|
||||
<td>${move.picking_id.carrier_id and move.picking_id.carrier_id.partner_id.name or ''}</td>
|
||||
</tr>
|
||||
%endfor
|
||||
</table>
|
||||
<br/>
|
||||
<table style="border:solid 1px" width="100%">
|
||||
<caption><b><u>${_('Products summary')}</u></b></caption>
|
||||
<tr align="left">
|
||||
<th>${_('Product Code')}</th>
|
||||
<th>${_('Product')}</th>
|
||||
<th>${_('QTY')}</th>
|
||||
</tr>
|
||||
%for product, qty in aggr.product_quantity():
|
||||
<tr align="left">
|
||||
<td>${product.default_code}</td>
|
||||
<td>${product.name}</td>
|
||||
<td>${qty}</td>
|
||||
</tr>
|
||||
%endfor
|
||||
</table>
|
||||
<br/>
|
||||
%endfor
|
||||
</body>
|
||||
</html>
|
||||
41
stock_picking_webkit/report/picking.html.mako
Normal file
41
stock_picking_webkit/report/picking.html.mako
Normal file
@@ -0,0 +1,41 @@
|
||||
<html>
|
||||
<head>
|
||||
<style type="text/css">
|
||||
${css}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<%from datetime import date %>
|
||||
${_('Date')}: ${formatLang(str(date.today()), date=True)}
|
||||
${_('Done by')}: ${user.name} ${_('Visa')}:_________________
|
||||
<br/>
|
||||
<br/>
|
||||
<b>${_('Company')}: ${user.company_id.name}<b>
|
||||
<br/>
|
||||
<br/>
|
||||
%for aggr in objects:
|
||||
<table style="border:solid 1px" width="100%">
|
||||
<caption><b><u>${aggr.src_stock.name} => ${aggr.dest_stock.name}</u></b></caption>
|
||||
<tr align="left">
|
||||
<th>${_('Product Code')}</th>
|
||||
<th>${_('Picking')}</th>
|
||||
<th>${_('Product')}</th>
|
||||
<th>${_('QTY')}</th>
|
||||
<th>${_('origin')}</th>
|
||||
<th>${_('Carrier')}</th>
|
||||
</tr>
|
||||
%for move in aggr.moves_by_product():
|
||||
<tr align="left">
|
||||
<td>${move.product_id.default_code}</td>
|
||||
<td>${move.picking_id.name}</td>
|
||||
<td>${move.product_id.name}</td>
|
||||
<td>${formatLang(move.product_qty)}</td>
|
||||
<td>${move.picking_id.origin}</td>
|
||||
<td>${move.picking_id.carrier_id and move.picking_id.carrier_id.partner_id.name or ''}</td>
|
||||
</tr>
|
||||
%endfor
|
||||
</table>
|
||||
<br/>
|
||||
%endfor
|
||||
</body>
|
||||
</html>
|
||||
129
stock_picking_webkit/report/stock_report.py
Normal file
129
stock_picking_webkit/report/stock_report.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user