~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to mrp_consume_produce/mrp.py

  • Committer: Gabriela (Vauxoo)
  • Date: 2012-01-02 16:24:49 UTC
  • Revision ID: gabrielaquilarque97@gmail.com-20120102162449-lhxnrtif2ud36du2

[ADD] Added new module invoice_so.

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) 2012 Vauxoo - http://www.vauxoo.com
6
 
#    All Rights Reserved.
7
 
#    info@vauxoo.com
8
 
############################################################################
9
 
#    Coded by: julio (julio@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
 
from openerp.tools.translate import _
28
 
 
29
 
import openerp.netsvc as netsvc
30
 
 
31
 
 
32
 
class mrp_production(osv.Model):
33
 
    _inherit = 'mrp.production'
34
 
 
35
 
    def _check_boolean(self, cr, uid, ids, field_name, args, context={}):
36
 
        res = {}
37
 
        for production in self.browse(cr, uid, ids, context=context):
38
 
            moves = [move for move in production.move_lines]
39
 
            if len(moves) == 0 and production.state != 'draft':
40
 
                res[production.id] = True
41
 
            else:
42
 
                res[production.id] = False
43
 
        return res
44
 
 
45
 
    def _check_len_move(self, cr, uid, ids, field_name, args, context={}):
46
 
        res = {}
47
 
        for production in self.browse(cr, uid, ids, context=context):
48
 
            moves = [
49
 
                move for move in production.move_lines2\
50
 
                if move.state == 'done']
51
 
            res[production.id] = len(moves)
52
 
        return res
53
 
 
54
 
    def _check_len_move_prod(self, cr, uid, ids, field_name, args, context={}):
55
 
        res = {}
56
 
        for production in self.browse(cr, uid, ids, context=context):
57
 
            res[production.id] = len(production.move_created_ids2)
58
 
        return res
59
 
 
60
 
    def _check_move_lines2(self, cr, uid, ids, field_name, args, context={}):
61
 
        res = {}
62
 
        for production in self.browse(cr, uid, ids, context=context):
63
 
            moves = [move for move in production.move_lines2]
64
 
            res[production.id] = len(moves)
65
 
        return res
66
 
 
67
 
    _columns = {
68
 
        'consumed': fields.function(_check_boolean, string='consumed?',
69
 
            type='boolean',
70
 
            help="indicates if product to consume have been consumed\
71
 
                or canceled"),
72
 
        'len_move': fields.function(_check_len_move, string='moves',
73
 
            type='float'),
74
 
        'len_move_prod': fields.function(_check_len_move_prod,
75
 
            string='produced', type='integer',),
76
 
        'moves_lines2': fields.function(_check_move_lines2,
77
 
            string='moves_lines2', type='integer',),
78
 
    }
79
 
 
80
 
    def action_finished_consume(self, cr, uid, ids, context={}):
81
 
        stock_move = self.pool.get('stock.move')
82
 
        for production in self.browse(cr, uid, ids, context=context):
83
 
            for moves in production.move_lines:
84
 
                stock_move.action_cancel(cr, uid, [moves.id], context=context)
85
 
        return True
86
 
 
87
 
    def action_finish(self, cr, uid, ids, context={}):
88
 
        stock_move = self.pool.get('stock.move')
89
 
        stock_picking = self.pool.get('stock.picking')
90
 
        for production in self.browse(cr, uid, ids, context=context):
91
 
            for moves in production.move_created_ids:
92
 
                stock_move.action_cancel(cr, uid, [moves.id], context=context)
93
 
            try:
94
 
                wf_service = netsvc.LocalService("workflow")
95
 
                wf_service.trg_validate(
96
 
                    uid, 'mrp.production', production.id,
97
 
                    'button_produce_done', cr)
98
 
            except:
99
 
                pass
100
 
        return True