~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to stock_picking_cancel/stock.py

  • Committer: Sabrina Romero
  • Date: 2013-08-20 21:10:39 UTC
  • mto: (543.7.272 vaddddddd)
  • mto: This revision was merged to the branch mainline in revision 840.
  • Revision ID: sabrina@vauxoo.com-20130820211039-9jqrffvg2nz8q3vx

[ADD] Module product_do_merge added

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
###########################################################################
 
3
#    Module Writen to OpenERP, Open Source Management Solution
 
4
#
 
5
#    Copyright (c) 2010 Vauxoo - http://www.vauxoo.com/
 
6
#    All Rights Reserved.
 
7
#    info Vauxoo (info@vauxoo.com)
 
8
############################################################################
 
9
#    Coded by: Luis Torres (luis_t@vauxoo.com)
 
10
############################################################################
 
11
#
 
12
#    This program is free software: you can redistribute it and/or modify
 
13
#    it under the terms of the GNU Affero General Public License as
 
14
#    published by the Free Software Foundation, either version 3 of the
 
15
#    License, or (at your option) any later version.
 
16
#
 
17
#    This program is distributed in the hope that it will be useful,
 
18
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
#    GNU Affero General Public License for more details.
 
21
#
 
22
#    You should have received a copy of the GNU Affero General Public License
 
23
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
24
#
 
25
##############################################################################
 
26
from openerp.osv import osv, fields
 
27
import openerp.netsvc as netsvc
 
28
from openerp.tools.translate import _
 
29
 
 
30
 
 
31
class stock_picking(osv.Model):
 
32
    _inherit = 'stock.picking'
 
33
 
 
34
    def action_cancel_draft(self, cr, uid, ids, *args):
 
35
        if not len(ids):
 
36
            return False
 
37
        move_obj = self.pool.get('stock.move')
 
38
        self.write(cr, uid, ids, {'state': 'draft'})
 
39
        wf_service = netsvc.LocalService("workflow")
 
40
        for p_id in ids:
 
41
            moves = move_obj.search(cr, uid, [('picking_id', '=', p_id)])
 
42
            move_obj.write(cr, uid, moves, {'state': 'draft'})
 
43
            # Deleting the existing instance of workflow for PO
 
44
            wf_service.trg_delete(uid, 'stock.picking', p_id, cr)
 
45
            wf_service.trg_create(uid, 'stock.picking', p_id, cr)
 
46
        for (id, name) in self.name_get(cr, uid, ids):
 
47
            message = _("Picking '%s' has been set in draft state.") % name
 
48
            self.log(cr, uid, id, message)
 
49
        return True
 
50
 
 
51
 
 
52
class stock_move(osv.Model):
 
53
    _inherit = 'stock.move'
 
54
 
 
55
    def action_cancel(self, cr, uid, ids, context=None):
 
56
        account_move_line = self.pool.get('account.move.line')
 
57
        account_move = self.pool.get('account.move')
 
58
        res = super(stock_move, self).action_cancel(
 
59
            cr, uid, ids, context=context)
 
60
        result = {}
 
61
        for move in self.browse(cr, uid, ids, context=context):
 
62
            account_move_line_id = account_move_line.search(
 
63
                cr, uid, [('stock_move_id', '=', move.id)])
 
64
            for move_line in account_move_line.browse(cr, uid,
 
65
                                                      account_move_line_id,
 
66
                                                      context=context):
 
67
                result.setdefault(move_line.move_id.id, move.id)
 
68
                account_move_line.unlink(cr, uid, [move_line.id])
 
69
        for lin in result.items():
 
70
            account_production = account_move.browse(
 
71
                cr, uid, lin[0], context=context)
 
72
            if len(account_production.line_id) == 0:
 
73
                try:
 
74
                    account_move.button_cancel(
 
75
                        cr, uid, [lin[0]], context=context)
 
76
                except:
 
77
                    pass
 
78
                account_move.unlink(cr, uid, [lin[0]])
 
79
        return True