~unifield-team/unifield-wm/us-927

« back to all changes in this revision

Viewing changes to stock_move_tracking/wizard/stock_tracking.py

  • Committer: Quentin THEURET
  • Date: 2011-04-18 12:12:33 UTC
  • mto: This revision was merged to the branch mainline in revision 60.
  • Revision ID: qt@tempo-consulting.fr-20110418121233-6r3481nhijh82ias
UF-123: [ADD] Added the stock_move_tracking module

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2011 TeMPO Consulting, MSF 
 
6
#
 
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.
 
11
#
 
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.
 
16
#
 
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/>.
 
19
#
 
20
##############################################################################
 
21
 
 
22
from osv import osv, fields
 
23
from tools.translate import _
 
24
 
 
25
 
 
26
class stock_move_tracking(osv.osv_memory):
 
27
    _name = 'stock.move.tracking'
 
28
    _description = 'Stock Move Tracking'
 
29
    
 
30
    _columns= {
 
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'),
 
34
    }
 
35
    
 
36
    def get_ids(self, cr, uid, ids, context={}):
 
37
        '''
 
38
        Returns all stock moves according to parameters
 
39
        '''
 
40
        move_obj = self.pool.get('stock.move')
 
41
        
 
42
        res = []
 
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'))
 
46
            
 
47
            domain = []
 
48
            if track.expired_date:
 
49
                domain.append(('expired_date', '=', track.expired_date))
 
50
            if track.product_id:
 
51
                domain.append(('product_id', '=', track.product_id.id))
 
52
            if track.prodlot_id:
 
53
                domain.append(('prodlot_id', '=', track.prodlot_id.id))
 
54
            
 
55
            res.extend(move_obj.search(cr, uid, domain, order='date'))
 
56
            
 
57
        return res
 
58
    
 
59
    def print_report(self, cr, uid, ids, context={}):
 
60
        '''
 
61
        Print the report as PDF file
 
62
        '''
 
63
        product_name = False
 
64
        product_code = False
 
65
        prodlot_id = False
 
66
        expired_date = False
 
67
        
 
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
 
73
        
 
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}
 
79
        
 
80
        datas = {'ids': self.get_ids(cr, uid, ids, context=context),
 
81
                 'model': 'stock.move',
 
82
                 'form': data}
 
83
 
 
84
        return {'type': 'ir.actions.report.xml',
 
85
                'report_name': 'tracking.move.report',
 
86
                'datas': datas}
 
87
    
 
88
    def print_view(self, cr, uid, ids, context={}):
 
89
        '''
 
90
        Print the report on Web client (search view)
 
91
        '''
 
92
        mod_obj = self.pool.get('ir.model.data')
 
93
        act_obj = self.pool.get('ir.actions.act_window')
 
94
 
 
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']
 
97
 
 
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']
 
100
        
 
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']
 
103
        
 
104
        result = act_obj.read(cr, uid, [id], context=context)[0]
 
105
        result['domain'] = [('id', 'in', self.get_ids(cr, uid, ids, context=context))]
 
106
        
 
107
        return result
 
108
    
 
109
stock_move_tracking()
 
110
 
 
111
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
 
b'\\ No newline at end of file'