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
1=== modified file 'kit/kit_creation.py'
2--- kit/kit_creation.py 2013-10-07 14:53:32 +0000
3+++ kit/kit_creation.py 2013-11-21 13:07:00 +0000
4@@ -473,10 +473,11 @@
5 data = {}
6 # moves consolidated
7 move_list = []
8+ move_manual = []
9
10 for move in obj.consumed_ids_kit_creation:
11 # the stock move should not be canceled, but... we recycle them in case.
12- if move.state in ['confirmed', 'cancel']:
13+ if move.state in ['confirmed', 'cancel'] and not move.kol_lot_manual:
14 move_list.append(move.id)
15 # consolidate the moves qty
16 qty = data.setdefault(move.product_id.id, {}).setdefault('uoms', {}).setdefault(move.product_uom.id, {}).setdefault('qty', 0.0)
17@@ -489,8 +490,10 @@
18 data.setdefault(move.product_id.id, {}).setdefault('uoms', {})[move.product_uom.id]['qty'] = qty
19 # save object for efficiency
20 data.setdefault(move.product_id.id, {}).setdefault('object', move.product_id)
21+ elif move.kol_lot_manual:
22+ move_manual.append(move.id)
23
24- return data, move_list
25+ return data, move_list, move_manual
26
27 def consolidate_lines(self, cr, uid, ids, context=None):
28 '''
29@@ -510,7 +513,7 @@
30
31 for obj in self.browse(cr, uid, ids, context=context):
32 # consolidate data
33- data, move_list = self._consolidate_data(cr, uid, obj.id, context=context)
34+ data, move_list, move_manual = self._consolidate_data(cr, uid, obj.id, context=context)
35 # delete stock moves
36 move_obj.unlink(cr, uid, move_list, context=dict(context, call_unlink=True))
37 # default location
38@@ -561,16 +564,41 @@
39 loc_obj = self.pool.get('stock.location')
40 prodlot_obj = self.pool.get('stock.production.lot')
41 data_tools_obj = self.pool.get('data.tools')
42+ uom_obj = self.pool.get('product.uom')
43 # load data into the context
44 data_tools_obj.load_common_data(cr, uid, ids, context=context)
45
46 for obj in self.browse(cr, uid, ids, context=context):
47 # consolidate data
48- data, move_list = self._consolidate_data(cr, uid, obj.id, context=context)
49+ data, move_list, move_manual = self._consolidate_data(cr, uid, obj.id, context=context)
50+ # default location
51+ default_location_id = obj.default_location_src_id_kit_creation.id
52+
53+ # Check availability of manual moves
54+ for move in move_obj.browse(cr, uid, move_manual, context=context):
55+ if move.state != 'confirmed' or not move.prodlot_id:
56+ continue
57+
58+ location_ids = loc_obj.search(cr, uid, [('location_id', 'child_of', move.location_id.id)], context=context)
59+ needed_qty = move.product_qty
60+ for loc in location_ids:
61+ available_qty = prodlot_obj.browse(cr, uid, move.prodlot_id.id, context=dict(context, location_id=loc)).stock_virtual
62+ diff_qty = available_qty - uom_obj._compute_qty(cr, uid, move.product_uom.id, needed_qty, move.product_id.uom_id.id)
63+ if diff_qty >= 0:
64+ move_obj.write(cr, uid, [move.id], {'state': 'assigned'}, context=context)
65+ break
66+ else:
67+ if available_qty:
68+ move_obj.copy(cr, uid, move.id, {'product_qty': available_qty, 'state': 'assigned'}, context=context)
69+ needed_qty -= available_qty
70+ move_obj.write(cr, uid, [move.id], {'product_qty': needed_qty}, context=context)
71+ else:
72+ move_obj.write(cr, uid, [move.id], {'prodlot_id': False, 'kol_lot_manual': False}, context=context)
73+
74+ data, move_list, move_manual = self._consolidate_data(cr, uid, obj.id, context=context)
75 # delete stock moves
76 move_obj.unlink(cr, uid, move_list, context=dict(context, call_unlink=True))
77- # default location
78- default_location_id = obj.default_location_src_id_kit_creation.id
79+
80 # create consolidated stock moves
81 for product_id in data.keys():
82 for uom_id in data[product_id]['uoms'].keys():
83@@ -1250,6 +1278,7 @@
84 '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),
85 '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),
86 '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),
87+ 'kol_lot_manual': fields.boolean(string='The batch is set manually'),
88 }
89
90 _defaults = {'to_consume_id_stock_move': False,
91@@ -1273,6 +1302,15 @@
92 # open the selected wizard
93 res = wiz_obj.open_wizard(cr, uid, ids, name=name, model=model, step=step, context=dict(context))
94 return res
95+
96+ def kol_prodlot_change(self, cr, uid, ids, prodlot_id, context=None):
97+ '''
98+ Set a new attribute on stock move if the prodolt is change manually in the Kit order creation
99+ '''
100+ if prodlot_id:
101+ return {'value': {'kol_lot_manual': True}}
102+
103+ return {'value': {'kol_lot_manual': False}}
104
105 def automatic_assignment(self, cr, uid, ids, context=None):
106 '''
107
108=== modified file 'kit/kit_creation_view.xml'
109--- kit/kit_creation_view.xml 2013-10-07 14:53:32 +0000
110+++ kit/kit_creation_view.xml 2013-11-21 13:07:00 +0000
111@@ -77,7 +77,8 @@
112 attrs="{'readonly': ['|', ('hidden_state', '!=', 'confirmed'), ('hidden_asset_check', '=', False)]}" />
113 <field name="prodlot_id"
114 context="{'location_id':location_id, 'product_id':product_id, 'hidden_perishable_mandatory': hidden_perishable_mandatory,
115- 'search_default_real': True}"
116+ 'search_default_real': True}"
117+ on_change="kol_prodlot_change(prodlot_id)"
118 domain="[('product_id', '=', product_id),('check_type','=', True)]"
119 attrs="{'readonly': ['|', ('hidden_state', '!=', 'confirmed'), ('hidden_exp_check', '=', False)],
120 'required': [('hidden_exp_check', '=', True)]}" />
121@@ -88,7 +89,8 @@
122 domain="[('usage', '=', 'internal')]" />
123 <field name="state" />
124 <field name="lot_check" />
125- <field name="exp_check" />
126+ <field name="exp_check" />
127+ <field name="kol_lot_manual" invisible="True" />
128 <field name="hidden_perishable_mandatory" invisible="True" />
129 <field name="hidden_exp_check" invisible="True" />
130 <field name="hidden_state" invisible="True" />

Subscribers

People subscribed via source and target branches