1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 TeMPO Consulting, MSF
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
22
from osv import osv, fields
23
from tools.translate import _
26
class stock_move_tracking(osv.osv_memory):
27
_name = 'stock.move.tracking'
28
_description = 'Stock Move Tracking'
31
'product_id': fields.many2one('product.product', string='Product'),
32
'prodlot_id': fields.many2one('stock.production.lot', string='Batch number'),
33
'expired_date': fields.date('Expired date'),
36
def get_ids(self, cr, uid, ids, context={}):
38
Returns all stock moves according to parameters
40
move_obj = self.pool.get('stock.move')
43
for track in self.browse(cr, uid, ids):
44
if not track.product_id and not track.prodlot_id and not track.expired_date:
45
raise osv.except_osv(_('Error'), _('You should at least enter one information'))
48
if track.expired_date:
49
domain.append(('expired_date', '=', track.expired_date))
51
domain.append(('product_id', '=', track.product_id.id))
53
domain.append(('prodlot_id', '=', track.prodlot_id.id))
55
res.extend(move_obj.search(cr, uid, domain, order='date'))
59
def print_report(self, cr, uid, ids, context={}):
61
Print the report as PDF file
68
for track in self.browse(cr, uid, ids):
69
product_name = track.product_id and track.product_id.name or False
70
product_code = track.product_id and track.product_id.default_code or False
71
prodlot_id = track.prodlot_id and track.prodlot_id.name or False
72
expired_date = track.expired_date
74
data = {'move_ids': self.get_ids(cr, uid, ids, context=context),
75
'product_id': product_name,
76
'product_code': product_code,
77
'prodlot_id': prodlot_id,
78
'expired_date': expired_date}
80
datas = {'ids': self.get_ids(cr, uid, ids, context=context),
81
'model': 'stock.move',
84
return {'type': 'ir.actions.report.xml',
85
'report_name': 'tracking.move.report',
88
def print_view(self, cr, uid, ids, context={}):
90
Print the report on Web client (search view)
92
mod_obj = self.pool.get('ir.model.data')
93
act_obj = self.pool.get('ir.actions.act_window')
95
result_tree = mod_obj._get_id(cr, uid, 'stock_move_tracking', 'stock_move_tracking_tree_view')
96
tree_id = mod_obj.read(cr, uid, [result_tree], ['res_id'], context=context)[0]['res_id']
98
result_search = mod_obj._get_id(cr, uid, 'stock_move_tracking', 'stock_move_tracking_search_view')
99
search_id = mod_obj.read(cr, uid, [result_search], ['res_id'], context=context)[0]['res_id']
101
result = mod_obj._get_id(cr, uid, 'stock_move_tracking', 'action_stock_move_tracking')
102
id = mod_obj.read(cr, uid, [result], ['res_id'], context=context)[0]['res_id']
104
result = act_obj.read(cr, uid, [id], context=context)[0]
105
result['domain'] = [('id', 'in', self.get_ids(cr, uid, ids, context=context))]
109
stock_move_tracking()
111
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
b'\\ No newline at end of file'