1
# -*- encoding: utf-8 -*-
2
###########################################################################
3
# Module Writen to OpenERP, Open Source Management Solution
5
# Copyright (c) 2012 Vauxoo - http://www.vauxoo.com
8
############################################################################
9
# Coded by: julio (julio@vauxoo.com)
10
############################################################################
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.
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.
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/>.
25
##############################################################################
26
from openerp.osv import osv, fields
27
from openerp.tools.translate import _
29
import openerp.netsvc as netsvc
32
class mrp_production(osv.Model):
33
_inherit = 'mrp.production'
35
def _check_boolean(self, cr, uid, ids, field_name, args, context={}):
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
42
res[production.id] = False
45
def _check_len_move(self, cr, uid, ids, field_name, args, context={}):
47
for production in self.browse(cr, uid, ids, context=context):
49
move for move in production.move_lines2\
50
if move.state == 'done']
51
res[production.id] = len(moves)
54
def _check_len_move_prod(self, cr, uid, ids, field_name, args, context={}):
56
for production in self.browse(cr, uid, ids, context=context):
57
res[production.id] = len(production.move_created_ids2)
60
def _check_move_lines2(self, cr, uid, ids, field_name, args, context={}):
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)
68
'consumed': fields.function(_check_boolean, string='consumed?',
70
help="indicates if product to consume have been consumed\
72
'len_move': fields.function(_check_len_move, string='moves',
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',),
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)
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)
94
wf_service = netsvc.LocalService("workflow")
95
wf_service.trg_validate(
96
uid, 'mrp.production', production.id,
97
'button_produce_done', cr)