~camptocamp/stock-logistic-flows/7.0-stock-obsolete-mdh

« back to all changes in this revision

Viewing changes to stock_picking_show_returns/stock_picking.py

  • Committer: Pedro M. Baeza
  • Date: 2013-10-29 15:58:32 UTC
  • mto: This revision was merged to the branch mainline in revision 41.
  • Revision ID: pedro.baeza@serviciosbaeza.com-20131029155832-51fohr62cq9y5gr8
[ADD] stock_picking_show_returns: Little module that shows in a new tab returns associated to current picking.

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) 2013 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
 
6
#                       Pedro M. Baeza <pedro.baeza@serviciosbaeza.com> 
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU Affero General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU Affero General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU Affero General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
from openerp.osv import fields, orm
 
23
 
 
24
class stock_picking(orm.Model):
 
25
    _inherit = 'stock.picking'
 
26
 
 
27
    def _get_return_ids(self, cr, uid, ids, name, arg, context=None):
 
28
        result = {}
 
29
        for picking in self.browse(cr, uid, ids, context=context):
 
30
            for line in picking.move_lines:
 
31
                return_ids = []
 
32
                if line.state == 'done':
 
33
                    for rec in line.move_history_ids2:
 
34
                        if rec.location_dest_id.id == line.location_id.id \
 
35
                                and rec.location_id.id == line.location_dest_id.id:
 
36
                            return_ids.append(rec.picking_id.id)
 
37
                result[picking.id] = return_ids
 
38
        return result
 
39
 
 
40
    _columns = {
 
41
        'return_ids': fields.function(_get_return_ids,
 
42
                                      relation='stock.picking',
 
43
                                      string="Return pickings",
 
44
                                      type='many2many'),
 
45
    }
 
46
 
 
47
class stock_picking_out(orm.Model):
 
48
    _inherit = 'stock.picking.out'
 
49
 
 
50
    def _get_return_ids(self, cr, uid, ids, name, arg, context=None):
 
51
        return super(stock_picking_out, self)._get_return_ids(cr, uid, ids,
 
52
                                                              name, arg,
 
53
                                                              context=context)
 
54
 
 
55
    _columns = {
 
56
        'return_ids': fields.function(_get_return_ids,
 
57
                                      relation='stock.picking',
 
58
                                      string="Return pickings",
 
59
                                      type='many2many'),
 
60
    }
 
61
 
 
62
class stock_picking_in(orm.Model):
 
63
    _inherit = 'stock.picking.in'
 
64
 
 
65
    def _get_return_ids(self, cr, uid, ids, name, arg, context=None):
 
66
        return super(stock_picking_out, self)._get_return_ids(cr, uid, ids,
 
67
                                                              name, arg,
 
68
                                                              context=context)
 
69
 
 
70
    _columns = {
 
71
        'return_ids': fields.function(_get_return_ids,
 
72
                                      relation='stock.picking',
 
73
                                      string="Return pickings",
 
74
                                      type='many2many'),
 
75
    }