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 _
30
class mrp_production(osv.Model):
31
_inherit = 'mrp.production'
34
'picking_ids': fields.one2many('stock.picking', 'production_id',
38
def action_finished_consume(self, cr, uid, ids, context=None):
42
stock_picking = self.pool.get('stock.picking')
43
mrp_production2 = self.pool.get('mrp.production')
44
stock_move = self.pool.get('stock.move')
45
production = self.pool.get('mrp.production').browse(
46
cr, uid, ids, context=context)[0]
48
for wizard_moves in self.browse(cr, uid, ids, context=context):
49
context['type'] = 'return'
50
pick_id_return = mrp_production2._make_production_internal_shipment2(
51
cr, uid, production, context=context)
52
stock_picking.write(cr, uid, pick_id_return, {
54
'auto_picking': False,
55
'production_id': production.id})
56
for wiz_move2 in wizard_moves.move_lines:
57
if wiz_move2.product_qty > 0.0:
58
shipment_move_id = mrp_production2._make_production_internal_shipment_line2(
59
cr, uid, production, wiz_move2, pick_id_return,
60
parent_move_id=False, destination_location_id=False)
61
stock_move.write(cr, uid, shipment_move_id, {
63
res = super(mrp_production, self).action_finished_consume(
64
cr, uid, ids, context=context)
67
def _make_production_internal_shipment_line2(self, cr, uid, production,
68
production_line, shipment_id,
70
destination_location_id=False,
72
stock_move = self.pool.get('stock.move')
73
date_planned = production.date_planned
74
if production_line.product_id.type not in ('product', 'consu'):
76
move_name = _('PROD: %s') % production.name
77
source_location_id = production.location_src_id.id
79
if not destination_location_id:
80
destination_location_id = source_location_id
81
return stock_move.create(cr, uid, {
83
'picking_id': shipment_id,
84
'product_id': production_line.product_id.id,
85
'product_qty': production_line.product_qty,
86
'product_uom': production_line.product_uom.id,
87
'product_uos_qty': production_line.product_uos and
88
production_line.product_uos_qty or False,
89
'product_uos': production_line.product_uos and
90
production_line.product_uos.id or False,
92
'move_dest_id': parent_move_id,
93
'location_id': source_location_id,
94
'location_dest_id': destination_location_id,
96
'company_id': production.company_id.id,
99
def _make_production_internal_shipment2(self, cr, uid, production,
101
ir_sequence = self.pool.get('ir.sequence')
102
stock_picking = self.pool.get('stock.picking')
104
pick_type = 'internal'
107
# Take routing address as a Shipment Address.
108
# If usage of routing location is a internal, make outgoing shipment
109
# otherwise internal shipment
110
if production.bom_id.routing_id and\
111
production.bom_id.routing_id.location_id:
112
routing_loc = production.bom_id.routing_id.location_id
113
if routing_loc.usage != 'internal':
115
address_id = routing_loc.address_id and\
116
routing_loc.address_id.id or False
118
# Take next Sequence number of shipment base on type
119
pick_name = ir_sequence.get(cr, uid, 'stock.picking')
120
picking_id = stock_picking.create(cr, uid, {
121
'name': pick_name + '-' + context.get('type', ''),
122
'origin': (production.origin or '').split(':')[0]\
123
+ ':' + production.name,
126
'address_id': address_id,
127
'company_id': production.company_id.id,
131
def copy(self, cr, uid, id, default=None, context=None):
137
return super(mrp_production, self).copy(cr, uid, id, default, context)
140
class stock_picking(osv.Model):
141
_inherit = 'stock.picking'
144
'production_id': fields.many2one('mrp.production', 'Production')