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
##############################################################################
27
from openerp.osv import osv, fields
28
import decimal_precision as dp
29
from openerp.tools.translate import _
32
class mrp_consume(osv.TransientModel):
35
'consume_line_ids': fields.one2many('mrp.consume.line',
36
'wizard_id', 'Consume')
39
def action_consume(self, cr, uid, ids, context={}):
40
for production in self.browse(cr, uid, ids, context=context):
41
for raw_product in production.consume_line_ids:
43
'product_uom': raw_product.product_uom.id,
44
'product_uom_move': raw_product.move_id.product_uom.id,
45
'quantity': raw_product.quantity})
46
raw_product.move_id.action_consume(
47
raw_product.quantity, raw_product.location_id.id,
51
def default_get(self, cr, uid, fields, context=None):
54
res = super(mrp_consume, self).default_get(
55
cr, uid, fields, context=context)
56
mrp_ids = context.get('active_ids', [])
57
if not mrp_ids or (not context.get('active_model') == 'mrp.production') \
61
if 'consume_line_ids' in fields:
62
mrp = self.pool.get('mrp.production').browse(
63
cr, uid, mrp_id, context=context)
64
moves = [self._partial_move_for(cr, uid, m)\
65
for m in mrp.move_lines if m.state\
66
not in ('done', 'cancel')]
67
res.update(consume_line_ids=moves)
70
def _partial_move_for(self, cr, uid, move):
72
'product_id': move.product_id.id,
73
'quantity': move.product_qty,
74
'product_uom': move.product_uom.id,
75
'prodlot_id': move.prodlot_id.id,
77
'location_id': move.location_id.id,
78
'location_dest_id': move.location_dest_id.id,
83
class mrp_produce(osv.TransientModel):
86
'produce_line_ids': fields.one2many('mrp.consume.line',
87
'wizard2_id', 'Consume')
90
def default_get(self, cr, uid, fields, context=None):
93
res = super(mrp_produce, self).default_get(
94
cr, uid, fields, context=context)
95
mrp_ids = context.get('active_ids', [])
96
if not mrp_ids or (not context.get('active_model') == 'mrp.production') \
100
if 'produce_line_ids' in fields:
101
mrp = self.pool.get('mrp.production').browse(
102
cr, uid, mrp_id, context=context)
103
moves = [self.pool.get('mrp.consume')._partial_move_for(cr, uid, m) \
104
for m in mrp.move_created_ids if m.state\
105
not in ('done', 'cancel')]
106
res.update(produce_line_ids=moves)
109
def action_produce(self, cr, uid, ids, context={}):
110
for production in self.browse(cr, uid, ids, context=context):
111
for raw_product in production.produce_line_ids:
113
'product_uom': raw_product.product_uom.id,
114
'product_uom_move': raw_product.move_id.product_uom.id,
115
'quantity': raw_product.quantity})
116
raw_product.move_id.action_consume(
117
raw_product.quantity, raw_product.location_id.id,
122
class mrp_consume_line(osv.TransientModel):
123
_name = 'mrp.consume.line'
124
_rec_name = 'product_id'
126
'product_id': fields.many2one('product.product', string="Product",
128
'quantity': fields.float("Quantity",
129
digits_compute=dp.get_precision('Product UoM'), required=True),
130
'product_uom': fields.many2one('product.uom', 'Unit of Measure',
132
'location_id': fields.many2one('stock.location', 'Location',
134
'location_dest_id': fields.many2one('stock.location',
135
'Dest. Location', required=True),
136
'move_id': fields.many2one('stock.move', "Move"),
137
'wizard_id': fields.many2one('mrp.consume', string="Wizard"),
138
'wizard2_id': fields.many2one('mrp.produce', string="Wizard"),