Merge lp:~alexaubin/unifield-server/US-3252 into lp:unifield-server

Proposed by jftempo
Status: Merged
Merged at revision: 4627
Proposed branch: lp:~alexaubin/unifield-server/US-3252
Merge into: lp:unifield-server
Diff against target: 176 lines (+66/-35)
3 files modified
bin/addons/kit/kit.py (+40/-2)
bin/addons/kit/wizard/substitute.py (+17/-33)
bin/addons/stock/product.py (+9/-0)
To merge this branch: bzr merge lp:~alexaubin/unifield-server/US-3252
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+331426@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 'bin/addons/kit/kit.py'
2--- bin/addons/kit/kit.py 2016-08-18 08:32:03 +0000
3+++ bin/addons/kit/kit.py 2017-11-28 10:56:17 +0000
4@@ -297,21 +297,56 @@
5 prodlot_id = datas[0]['composition_lot_id'][0]
6 # update the context with needed data
7 context.update(kit_id=kit_id, product_id=product_id, prodlot_id=prodlot_id)
8-
9+
10 return context
11-
12+
13+ def assert_available_stock(self, cr, uid, ids, context=None):
14+ if context is None:
15+ context = {}
16+
17+ assert isinstance(ids, list)
18+
19+ for kit in self.browse(cr, uid, ids, context=context):
20+
21+ def qty_available(id_):
22+ request_context = context.copy()
23+ request_context.update({ 'states': ('done',),
24+ 'what': ('in', 'out'),
25+ 'location_usage': ['internal'],
26+ 'location_category': ['stock', 'consumption_unit'] })
27+ return self.pool.get("product.product").get_product_available(cr, uid, [id_], context=request_context)[id_]
28+
29+ # For kits with a batch, take the stock of the batch
30+ # Otherwise, take the global stock of the product
31+ if kit.composition_reference:
32+ product_id = kit.composition_product_id.id
33+ else:
34+ product_id = kit.composition_lot_id.id
35+
36+ stock = qty_available(product_id)
37+
38+ if stock <= 0:
39+ raise osv.except_osv(_('Error'),
40+ _('This kit product / batch is not available in stock !'))
41+
42+
43 def substitute_items(self, cr, uid, ids, context=None):
44 '''
45 substitute lines from the composition kit with created new lines
46 '''
47+
48 # we need the context for the wizard switch
49 if context is None:
50 context = {}
51+
52+ self.assert_available_stock(cr, uid, ids, context=context)
53+
54 # data
55 name = _("Substitute Kit Items")
56 model = 'substitute'
57 step = 'substitute' # this value is used in substitute wizard for attrs of src location
58 wiz_obj = self.pool.get('wizard')
59+
60 # get a context with needed data
61 wiz_context = self._get_new_context(cr, uid, ids, context=dict(context))
62 # open the selected wizard
63@@ -336,6 +371,9 @@
64 # we need the context for the wizard switch
65 if context is None:
66 context = {}
67+
68+ self.assert_available_stock(cr, uid, ids, context=context)
69+
70 # data
71 name = _("De-Kitting")
72 model = 'substitute'
73
74=== modified file 'bin/addons/kit/wizard/substitute.py'
75--- bin/addons/kit/wizard/substitute.py 2016-08-18 08:32:03 +0000
76+++ bin/addons/kit/wizard/substitute.py 2017-11-28 10:56:17 +0000
77@@ -51,25 +51,33 @@
78 context = {}
79 if isinstance(ids, (int, long)):
80 ids = [ids]
81-
82+
83 for obj in self.browse(cr, uid, ids, context=context):
84 for item in obj.composition_item_ids:
85 # integrity is not met
86 if item.integrity_status_func_substitute_item != 'empty':
87 return False
88-
89+
90 return True
91-
92+
93 def validate_item_from_stock(self, cr, uid, ids, context=None):
94 '''
95 both integrity and availability must be OK
96-
97+
98 'availability_status_func_substitute_item'
99 'integrity_status_func_substitute_item'
100-
101+
102 return True or False
103 '''
104+ if context is None:
105+ context = {}
106+
107+ kit_obj = self.pool.get('composition.kit')
108+
109 for obj in self.browse(cr, uid, ids, context=context):
110+
111+ kit_obj.assert_available_stock(cr, uid, [obj.kit_id.id], context=context)
112+
113 for item in obj.replacement_item_ids:
114 # integrity is not met
115 if item.integrity_status_func_substitute_item != 'empty':
116@@ -376,36 +384,12 @@
117 available_qty = res['value']['qty_substitute_item']
118 if available_qty < 1.0:
119 # we display the back button - hide close button
120- return self.confirmation_de_kitting(cr, uid, ids, context=dict(context, display_back_confirm=True, display_close_confirm=False))
121+ raise osv.except_osv(_("Error"),
122+ _("The Kit \'%s\' is not available from selected source location \'%s\'"
123+ %(obj.product_id_substitute.name, obj.source_location_id.name)))
124 else:
125 return self._do_de_kitting(cr, uid, ids, context=context)
126-
127- def confirmation_de_kitting(self, cr, uid, ids, context=None):
128- '''
129- open confirmation wizard
130- '''
131- # objects
132- wiz_obj = self.pool.get('wizard')
133-
134- # to de kitting
135- for obj in self.browse(cr, uid, ids, context=context):
136- # data
137- name = _("The Kit \'%s\' is not available from selected source location \'%s\'. Are you sure you want to process the Dekitting?")%(obj.product_id_substitute.name, obj.source_location_id.name)
138- model = 'confirm'
139- step = context.get('step', 'default')
140- question = 'The Kit \'%s\' is not available from selected source location \'%s\'. Are you sure you want to process the Dekitting?'
141- clazz = 'substitute'
142- func = '_do_de_kitting'
143- args = [ids]
144- kwargs = {}
145- # open the selected wizard - context['active_ids']
146- res = wiz_obj.open_wizard(cr, uid, context['active_ids'], name=name, model=model, step=step, context=dict(context, question=question,
147- callback={'clazz': clazz,
148- 'func': func,
149- 'args': args,
150- 'kwargs': kwargs}))
151- return res
152-
153+
154 def _do_de_kitting(self, cr, uid, ids, context=None):
155 '''
156 de-kitting method
157
158=== modified file 'bin/addons/stock/product.py'
159--- bin/addons/stock/product.py 2016-08-26 14:25:42 +0000
160+++ bin/addons/stock/product.py 2017-11-28 10:56:17 +0000
161@@ -216,6 +216,15 @@
162 order='NO_ORDER', context=context)
163 else:
164 location_ids = context['location']
165+ elif context.get('location_category', False) and context.get('location_usage', False):
166+ location_category = context.get('location_category')
167+ location_usage = context.get('location_usage')
168+ assert isinstance(location_category, list)
169+ assert isinstance(location_usage, list)
170+ location_ids = stock_location_obj.search(cr, uid,
171+ [('location_category','in', location_category),
172+ ('usage', 'in', location_usage)],
173+ order='NO_ORDER', context=context)
174 else:
175 location_ids = []
176 wids = stock_warehouse_obj.search(cr, uid, [], order='NO_ORDER', context=context)

Subscribers

People subscribed via source and target branches