[WIP] Give warnings when not possible to do traceability and needed, group by quants

bzr revid: jco@openerp.com-20140120162828-6xgxshtkc44tlesi
This commit is contained in:
Josse Colpaert
2014-01-20 17:28:28 +01:00
parent b50247109c
commit 24f6ed8973
5 changed files with 34 additions and 13 deletions
+2 -1
View File
@@ -773,7 +773,6 @@ class mrp_production(osv.osv):
return 1
def action_produce(self, cr, uid, production_id, production_qty, production_mode, wiz, context=None):
""" To produce final product based on production mode (consume/consume&produce).
If Production mode is consume, all stock move lines of raw materials will be done/consumed.
@@ -784,6 +783,8 @@ class mrp_production(osv.osv):
@param production_mode: specify production mode (consume/consume&produce).
@return: True
"""
stock_mov_obj = self.pool.get('stock.move')
production = self.browse(cr, uid, production_id, context=context)
if not production.move_lines and production.state == 'ready':
+3 -1
View File
@@ -37,7 +37,9 @@ class StockMove(osv.osv):
super(StockMove, self).check_tracking(cr, uid, move, lot_id, context=context)
if move.product_id.track_production and (move.location_id.usage == 'production' or move.location_dest_id.usage == 'production') and not lot_id:
raise osv.except_osv(_('Warning!'), _('You must assign a serial number for the product %s') % (move.product_id.name))
if move.raw_material_production_id and move.location_dest_id.usage == 'production' and move.raw_material_production_id.product_id.track_production and not move.consumed_for:
raise osv.except_osv(_('Warning!'), _('You should not process it like this as both your raw materials and finished product require to track manufacturing. In that case, you should be able to make the link between the raw materials and the finished products and this is not possible with this method. '))
def _action_explode(self, cr, uid, move, context=None):
""" Explodes pickings.
@param move: Stock moves
+26 -9
View File
@@ -75,14 +75,15 @@ class mrp_product_produce(osv.osv_memory):
if not consumed_data.get(consumed.product_id.id, False):
consumed_data[consumed.product_id.id] = 0
consumed_data[consumed.product_id.id] += consumed.product_qty
print "Consumed data", consumed_data
new_consume_lines = []
dicts = {}
# Find product qty to be consumed and consume it
for scheduled in production.product_lines:
if not dicts.get(scheduled.product_id.id):
dicts[scheduled.product_id.id] = {}
# total qty of consumed product we need after this consumption
total_consume = ((product_qty + produced_qty) * scheduled.product_qty / production.product_qty)
@@ -104,13 +105,26 @@ class mrp_product_produce(osv.osv_memory):
prefered_domain=[('reservation_id', '=', move.id)], fallback_domain=[('reservation_id', '=', False)], context=context)
for quant in quants:
if quant[0]:
dict_new = {'product_id': scheduled.product_id.id, 'product_qty': quant[1], 'lot_id': quant[0].lot_id.id}
new_consume_lines.append([0, False, dict_new])
product_id = scheduled.product_id.id
lot_id = quant[0].lot_id.id
prod_qty = quant[1]
if not product_id in dicts.keys():
dicts[product_id] = {lot_id : prod_qty}
elif lot_id in dicts[product_id].keys():
dicts[product_id][lot_id] += prod_qty
else:
dicts[product_id][lot_id] = prod_qty
qty -= quant[1]
if qty > 0:
dict_new = {'product_id': scheduled.product_id.id, 'product_qty': qty}
new_consume_lines.append([0, False, dict_new])
if qty > 0:
if dicts[product_id][False]:
dicts[product_id][False] += qty
else:
dicts[product_id][False] = qty
for prod in dicts.keys():
for lot in dicts[prod].keys():
dict_new = {'product_id': prod, 'product_qty':dicts[prod][lot], 'lot_id': lot}
new_consume_lines.append([0, False, dict_new]) #Todo for all qtys
return {'value': {'consume_lines': new_consume_lines}}
@@ -155,6 +169,9 @@ class mrp_product_produce(osv.osv_memory):
'track_production': _get_track,
}
def do_produce(self, cr, uid, ids, context=None):
production_id = context.get('active_id', False)
assert production_id, "Production Id should be specified in context as a Active ID."
@@ -17,7 +17,7 @@
<field name="track_production" invisible="1"/>
<field name="lot_id" domain="[('product_id', '=', product_id)]"
context="{'default_product_id':product_id}"
attrs="{'required': [('track_production','=',True)]}"
attrs="{'required': [('track_production', '=', True), ('mode', '=', 'consume_produce')]}"
groups="stock.group_tracking_lot"/>
</group>
<separator/>
+2 -1
View File
@@ -60,6 +60,8 @@ class stock_move_consume(osv.osv_memory):
return res
def do_move_consume(self, cr, uid, ids, context=None):
""" To move consumed products
@param self: The object pointer.
@@ -115,7 +117,6 @@ class stock_move_scrap(osv.osv_memory):
res.update({'location_id': scrap_location_id[0]})
else:
res.update({'location_id': False})
return res
def move_scrap(self, cr, uid, ids, context=None):