1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from osv import fields
27 class StockMove(osv.osv):
28 _inherit = 'stock.move'
31 'production_id': fields.many2one('mrp.production', 'Production', select=True),
34 def _action_explode(self, cr, uid, move, context={}):
35 """ Explodes pickings.
36 @param move: Stock moves
39 bom_obj = self.pool.get('mrp.bom')
40 move_obj = self.pool.get('stock.move')
41 procurement_obj = self.pool.get('procurement.order')
42 product_obj = self.pool.get('product.product')
43 wf_service = netsvc.LocalService("workflow")
44 if move.product_id.supply_method == 'produce' and move.product_id.procure_method == 'make_to_order':
45 bis = bom_obj.search(cr, uid, [
46 ('product_id','=',move.product_id.id),
48 ('type','=','phantom')])
50 factor = move.product_qty
51 bom_point = bom_obj.browse(cr, uid, bis[0])
52 res = bom_obj._bom_explode(cr, uid, bom_point, factor, [])
53 dest = move.product_id.product_tmpl_id.property_stock_production.id
55 if move.state == 'assigned':
59 'picking_id': move.picking_id.id,
60 'product_id': line['product_id'],
61 'product_uom': line['product_uom'],
62 'product_qty': line['product_qty'],
63 'product_uos': line['product_uos'],
64 'product_uos_qty': line['product_uos_qty'],
65 'move_dest_id': move.id,
68 'location_dest_id': dest,
69 'move_history_ids': [(6,0,[move.id])],
70 'move_history_ids2': [(6,0,[])],
73 mid = move_obj.copy(cr, uid, move.id, default=valdef)
74 prodobj = product_obj.browse(cr, uid, line['product_id'], context=context)
75 proc_id = procurement_obj.create(cr, uid, {
76 'name': (move.picking_id.origin or ''),
77 'origin': (move.picking_id.origin or ''),
78 'date_planned': move.date,
79 'product_id': line['product_id'],
80 'product_qty': line['product_qty'],
81 'product_uom': line['product_uom'],
82 'product_uos_qty': line['product_uos'] and line['product_uos_qty'] or False,
83 'product_uos': line['product_uos'],
84 'location_id': move.location_id.id,
85 'procure_method': prodobj.procure_method,
88 wf_service.trg_validate(uid, 'procurement.order', proc_id, 'button_confirm', cr)
89 move_obj.write(cr, uid, [move.id], {
90 'location_id': move.location_dest_id.id,
91 'auto_validate': True,
95 for m in procurement_obj.search(cr, uid, [('move_id','=',move.id)], context):
96 wf_service.trg_validate(uid, 'procurement.order', m, 'button_wait_done', cr)
99 def action_consume(self, cr, uid, ids, product_qty, location_id=False, context=None):
100 """ Consumed product with specific quatity from specific source location.
101 @param product_qty: Consumed product quantity
102 @param location_id: Source location
103 @return: Consumed lines
106 production_obj = self.pool.get('mrp.production')
107 wf_service = netsvc.LocalService("workflow")
108 for move in self.browse(cr, uid, ids):
109 new_moves = super(StockMove, self).action_consume(cr, uid, [move.id], product_qty, location_id, context=context)
110 production_ids = production_obj.search(cr, uid, [('move_lines', 'in', [move.id])])
111 for prod in production_obj.browse(cr, uid, production_ids, context=context):
112 if prod.state == 'confirmed':
113 production_obj.force_production(cr, uid, [prod.id])
114 wf_service.trg_validate(uid, 'mrp.production', prod.id, 'button_produce', cr)
115 for new_move in new_moves:
116 production_obj.write(cr, uid, production_ids, {'move_lines': [(4, new_move)]})
120 def action_scrap(self, cr, uid, ids, product_qty, location_id, context=None):
121 """ Move the scrap/damaged product into scrap location
122 @param product_qty: Scraped product quantity
123 @param location_id: Scrap location
124 @return: Scraped lines
127 production_obj = self.pool.get('mrp.production')
128 wf_service = netsvc.LocalService("workflow")
129 for move in self.browse(cr, uid, ids):
130 new_moves = super(StockMove, self).action_scrap(cr, uid, [move.id], product_qty, location_id, context=context)
131 self.write(cr, uid, [move.id], {'prodlot_id': False, 'tracking_id': False})
132 production_ids = production_obj.search(cr, uid, [('move_lines', 'in', [move.id])])
133 for prod_id in production_ids:
134 wf_service.trg_validate(uid, 'mrp.production', prod_id, 'button_produce', cr)
135 for new_move in new_moves:
136 production_obj.write(cr, uid, production_ids, {'move_lines': [(4, new_move)]})
143 class StockPicking(osv.osv):
144 _inherit = 'stock.picking'
147 # Explode picking by replacing phantom BoMs
149 def action_explode(self, cr, uid, picks, *args):
150 """ Explodes picking by replacing phantom BoMs
151 @param picks: Picking ids.
152 @param *args: Arguments
153 @return: Picking ids.
155 move_obj = self.pool.get('stock.move')
156 for move in move_obj.browse(cr, uid, picks):
157 move_obj._action_explode(cr, uid, move)
163 class spilt_in_production_lot(osv.osv_memory):
164 _inherit = "stock.move.split"
166 def split(self, cr, uid, ids, move_ids, context=None):
167 """ Splits move lines into given quantities.
168 @param move_ids: Stock moves.
169 @return: List of new moves.
171 production_obj = self.pool.get('mrp.production')
172 move_obj = self.pool.get('stock.move')
174 for move in move_obj.browse(cr, uid, move_ids, context=context):
175 new_moves = super(spilt_in_production_lot, self).split(cr, uid, ids, move_ids, context=context)
176 production_ids = production_obj.search(cr, uid, [('move_lines', 'in', [move.id])])
177 for new_move in new_moves:
178 production_obj.write(cr, uid, production_ids, {'move_lines': [(4, new_move)]})
181 spilt_in_production_lot()
182 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: