Merge lp:~unifield-team/unifield-wm/uf-2191 into lp:unifield-wm

Proposed by jftempo
Status: Merged
Merged at revision: 1854
Proposed branch: lp:~unifield-team/unifield-wm/uf-2191
Merge into: lp:unifield-wm
Diff against target: 130 lines (+48/-8)
2 files modified
kit/kit_creation.py (+44/-6)
kit/kit_creation_view.xml (+4/-2)
To merge this branch: bzr merge lp:~unifield-team/unifield-wm/uf-2191
Reviewer Review Type Date Requested Status
UniField Dev Team Pending
Review via email: mp+196100@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'kit/kit_creation.py'
--- kit/kit_creation.py 2013-10-07 14:53:32 +0000
+++ kit/kit_creation.py 2013-11-21 13:07:00 +0000
@@ -473,10 +473,11 @@
473 data = {}473 data = {}
474 # moves consolidated474 # moves consolidated
475 move_list = []475 move_list = []
476 move_manual = []
476 477
477 for move in obj.consumed_ids_kit_creation:478 for move in obj.consumed_ids_kit_creation:
478 # the stock move should not be canceled, but... we recycle them in case.479 # the stock move should not be canceled, but... we recycle them in case.
479 if move.state in ['confirmed', 'cancel']:480 if move.state in ['confirmed', 'cancel'] and not move.kol_lot_manual:
480 move_list.append(move.id)481 move_list.append(move.id)
481 # consolidate the moves qty482 # consolidate the moves qty
482 qty = data.setdefault(move.product_id.id, {}).setdefault('uoms', {}).setdefault(move.product_uom.id, {}).setdefault('qty', 0.0)483 qty = data.setdefault(move.product_id.id, {}).setdefault('uoms', {}).setdefault(move.product_uom.id, {}).setdefault('qty', 0.0)
@@ -489,8 +490,10 @@
489 data.setdefault(move.product_id.id, {}).setdefault('uoms', {})[move.product_uom.id]['qty'] = qty490 data.setdefault(move.product_id.id, {}).setdefault('uoms', {})[move.product_uom.id]['qty'] = qty
490 # save object for efficiency491 # save object for efficiency
491 data.setdefault(move.product_id.id, {}).setdefault('object', move.product_id)492 data.setdefault(move.product_id.id, {}).setdefault('object', move.product_id)
493 elif move.kol_lot_manual:
494 move_manual.append(move.id)
492 495
493 return data, move_list496 return data, move_list, move_manual
494 497
495 def consolidate_lines(self, cr, uid, ids, context=None):498 def consolidate_lines(self, cr, uid, ids, context=None):
496 '''499 '''
@@ -510,7 +513,7 @@
510 513
511 for obj in self.browse(cr, uid, ids, context=context):514 for obj in self.browse(cr, uid, ids, context=context):
512 # consolidate data515 # consolidate data
513 data, move_list = self._consolidate_data(cr, uid, obj.id, context=context)516 data, move_list, move_manual = self._consolidate_data(cr, uid, obj.id, context=context)
514 # delete stock moves517 # delete stock moves
515 move_obj.unlink(cr, uid, move_list, context=dict(context, call_unlink=True))518 move_obj.unlink(cr, uid, move_list, context=dict(context, call_unlink=True))
516 # default location519 # default location
@@ -561,16 +564,41 @@
561 loc_obj = self.pool.get('stock.location')564 loc_obj = self.pool.get('stock.location')
562 prodlot_obj = self.pool.get('stock.production.lot')565 prodlot_obj = self.pool.get('stock.production.lot')
563 data_tools_obj = self.pool.get('data.tools')566 data_tools_obj = self.pool.get('data.tools')
567 uom_obj = self.pool.get('product.uom')
564 # load data into the context568 # load data into the context
565 data_tools_obj.load_common_data(cr, uid, ids, context=context)569 data_tools_obj.load_common_data(cr, uid, ids, context=context)
566 570
567 for obj in self.browse(cr, uid, ids, context=context):571 for obj in self.browse(cr, uid, ids, context=context):
568 # consolidate data572 # consolidate data
569 data, move_list = self._consolidate_data(cr, uid, obj.id, context=context)573 data, move_list, move_manual = self._consolidate_data(cr, uid, obj.id, context=context)
574 # default location
575 default_location_id = obj.default_location_src_id_kit_creation.id
576
577 # Check availability of manual moves
578 for move in move_obj.browse(cr, uid, move_manual, context=context):
579 if move.state != 'confirmed' or not move.prodlot_id:
580 continue
581
582 location_ids = loc_obj.search(cr, uid, [('location_id', 'child_of', move.location_id.id)], context=context)
583 needed_qty = move.product_qty
584 for loc in location_ids:
585 available_qty = prodlot_obj.browse(cr, uid, move.prodlot_id.id, context=dict(context, location_id=loc)).stock_virtual
586 diff_qty = available_qty - uom_obj._compute_qty(cr, uid, move.product_uom.id, needed_qty, move.product_id.uom_id.id)
587 if diff_qty >= 0:
588 move_obj.write(cr, uid, [move.id], {'state': 'assigned'}, context=context)
589 break
590 else:
591 if available_qty:
592 move_obj.copy(cr, uid, move.id, {'product_qty': available_qty, 'state': 'assigned'}, context=context)
593 needed_qty -= available_qty
594 move_obj.write(cr, uid, [move.id], {'product_qty': needed_qty}, context=context)
595 else:
596 move_obj.write(cr, uid, [move.id], {'prodlot_id': False, 'kol_lot_manual': False}, context=context)
597
598 data, move_list, move_manual = self._consolidate_data(cr, uid, obj.id, context=context)
570 # delete stock moves599 # delete stock moves
571 move_obj.unlink(cr, uid, move_list, context=dict(context, call_unlink=True))600 move_obj.unlink(cr, uid, move_list, context=dict(context, call_unlink=True))
572 # default location601
573 default_location_id = obj.default_location_src_id_kit_creation.id
574 # create consolidated stock moves602 # create consolidated stock moves
575 for product_id in data.keys():603 for product_id in data.keys():
576 for uom_id in data[product_id]['uoms'].keys():604 for uom_id in data[product_id]['uoms'].keys():
@@ -1250,6 +1278,7 @@
1250 'hidden_creation_state': fields.function(_vals_get_kit_creation, method=True, type='selection', selection=KIT_CREATION_STATE, string='Hidden Creation State', multi='get_vals_kit_creation', store=False, readonly=True),1278 'hidden_creation_state': fields.function(_vals_get_kit_creation, method=True, type='selection', selection=KIT_CREATION_STATE, string='Hidden Creation State', multi='get_vals_kit_creation', store=False, readonly=True),
1251 'assigned_qty_stock_move': fields.function(_vals_get_kit_creation, method=True, type='float', string='Assigned Qty', multi='get_vals_kit_creation', store=False, readonly=True),1279 'assigned_qty_stock_move': fields.function(_vals_get_kit_creation, method=True, type='float', string='Assigned Qty', multi='get_vals_kit_creation', store=False, readonly=True),
1252 'hidden_creation_qty_stock_move': fields.function(_vals_get_kit_creation, method=True, type='integer', string='Hidden Creation Qty', multi='get_vals_kit_creation', store=False, readonly=True),1280 'hidden_creation_qty_stock_move': fields.function(_vals_get_kit_creation, method=True, type='integer', string='Hidden Creation Qty', multi='get_vals_kit_creation', store=False, readonly=True),
1281 'kol_lot_manual': fields.boolean(string='The batch is set manually'),
1253 }1282 }
1254 1283
1255 _defaults = {'to_consume_id_stock_move': False,1284 _defaults = {'to_consume_id_stock_move': False,
@@ -1273,6 +1302,15 @@
1273 # open the selected wizard1302 # open the selected wizard
1274 res = wiz_obj.open_wizard(cr, uid, ids, name=name, model=model, step=step, context=dict(context))1303 res = wiz_obj.open_wizard(cr, uid, ids, name=name, model=model, step=step, context=dict(context))
1275 return res1304 return res
1305
1306 def kol_prodlot_change(self, cr, uid, ids, prodlot_id, context=None):
1307 '''
1308 Set a new attribute on stock move if the prodolt is change manually in the Kit order creation
1309 '''
1310 if prodlot_id:
1311 return {'value': {'kol_lot_manual': True}}
1312
1313 return {'value': {'kol_lot_manual': False}}
1276 1314
1277 def automatic_assignment(self, cr, uid, ids, context=None):1315 def automatic_assignment(self, cr, uid, ids, context=None):
1278 '''1316 '''
12791317
=== modified file 'kit/kit_creation_view.xml'
--- kit/kit_creation_view.xml 2013-10-07 14:53:32 +0000
+++ kit/kit_creation_view.xml 2013-11-21 13:07:00 +0000
@@ -77,7 +77,8 @@
77 attrs="{'readonly': ['|', ('hidden_state', '!=', 'confirmed'), ('hidden_asset_check', '=', False)]}" />77 attrs="{'readonly': ['|', ('hidden_state', '!=', 'confirmed'), ('hidden_asset_check', '=', False)]}" />
78 <field name="prodlot_id"78 <field name="prodlot_id"
79 context="{'location_id':location_id, 'product_id':product_id, 'hidden_perishable_mandatory': hidden_perishable_mandatory,79 context="{'location_id':location_id, 'product_id':product_id, 'hidden_perishable_mandatory': hidden_perishable_mandatory,
80 'search_default_real': True}"80 'search_default_real': True}"
81 on_change="kol_prodlot_change(prodlot_id)"
81 domain="[('product_id', '=', product_id),('check_type','=', True)]"82 domain="[('product_id', '=', product_id),('check_type','=', True)]"
82 attrs="{'readonly': ['|', ('hidden_state', '!=', 'confirmed'), ('hidden_exp_check', '=', False)],83 attrs="{'readonly': ['|', ('hidden_state', '!=', 'confirmed'), ('hidden_exp_check', '=', False)],
83 'required': [('hidden_exp_check', '=', True)]}" />84 'required': [('hidden_exp_check', '=', True)]}" />
@@ -88,7 +89,8 @@
88 domain="[('usage', '=', 'internal')]" />89 domain="[('usage', '=', 'internal')]" />
89 <field name="state" />90 <field name="state" />
90 <field name="lot_check" />91 <field name="lot_check" />
91 <field name="exp_check" />92 <field name="exp_check" />
93 <field name="kol_lot_manual" invisible="True" />
92 <field name="hidden_perishable_mandatory" invisible="True" />94 <field name="hidden_perishable_mandatory" invisible="True" />
93 <field name="hidden_exp_check" invisible="True" />95 <field name="hidden_exp_check" invisible="True" />
94 <field name="hidden_state" invisible="True" />96 <field name="hidden_state" invisible="True" />

Subscribers

People subscribed via source and target branches