Merge lp:~unifield-team/unifield-server/us-771 into lp:unifield-server
- us-771
- Merge into trunk
Proposed by
jftempo
Status: | Merged |
---|---|
Merged at revision: | 3656 |
Proposed branch: | lp:~unifield-team/unifield-server/us-771 |
Merge into: | lp:unifield-server |
Diff against target: |
649 lines (+398/-173) 1 file modified
bin/addons/return_claim/return_claim.py (+398/-173) |
To merge this branch: | bzr merge lp:~unifield-team/unifield-server/us-771 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
UniField Reviewer Team | Pending | ||
Review via email: mp+289365@code.launchpad.net |
Commit message
Description of the change
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/return_claim/return_claim.py' |
2 | --- bin/addons/return_claim/return_claim.py 2014-03-05 10:54:21 +0000 |
3 | +++ bin/addons/return_claim/return_claim.py 2016-03-17 13:35:25 +0000 |
4 | @@ -371,51 +371,60 @@ |
5 | return result |
6 | |
7 | def load_products(self, cr, uid, ids, context=None): |
8 | - ''' |
9 | - load products data from selected origin |
10 | - ''' |
11 | + """ |
12 | + Load claim.product.line into the return.claim from the stock.picking linked to the claim |
13 | + :param cr: Cursor to the database |
14 | + :param uid: ID of the res.users that calls the method |
15 | + :param ids: List of ID of return.claim on which claim.product.line must be created |
16 | + :param context: Context of the call |
17 | + :return: True |
18 | + """ |
19 | + # Objects |
20 | + pl_obj = self.pool.get('claim.product.line') |
21 | + |
22 | # Some verifications |
23 | if context is None: |
24 | context = {} |
25 | if isinstance(ids, (int, long)): |
26 | ids = [ids] |
27 | - |
28 | - # objects |
29 | - product_line_obj = self.pool.get('claim.product.line') |
30 | - for obj in self.browse(cr, uid, ids, context=context): |
31 | - # clear existing products |
32 | - line_ids = product_line_obj.search(cr, uid, [('claim_id_claim_product_line', '=', obj.id)], context=context) |
33 | - product_line_obj.unlink(cr, uid, line_ids, context=context) |
34 | - # create new ones |
35 | - for move in obj.picking_id_return_claim.move_lines: |
36 | - # create corresponding product line |
37 | - if obj.type_return_claim not in TYPES_FOR_SRC_LOCATION: |
38 | - src_location_id = False |
39 | - else: |
40 | - src_location_id = obj.default_src_location_id_return_claim.id |
41 | - product_line_values = {'qty_claim_product_line': move.product_qty, |
42 | - 'claim_id_claim_product_line': obj.id, |
43 | - 'product_id_claim_product_line': move.product_id.id, |
44 | - 'uom_id_claim_product_line': move.product_uom.id, |
45 | - 'lot_id_claim_product_line': move.prodlot_id.id, |
46 | - 'expiry_date_claim_product_line': move.expired_date, |
47 | - 'asset_id_claim_product_line' : move.asset_id.id, |
48 | - 'composition_list_id_claim_product_line': move.composition_list_id.id, |
49 | - 'src_location_id_claim_product_line': src_location_id} |
50 | - |
51 | - new_prod_id = product_line_obj.create(cr, uid, product_line_values, context=context) |
52 | - |
53 | - return True |
54 | - return {'name': _('Claim'), |
55 | - 'view_mode': 'form,tree', |
56 | - 'view_id': False, |
57 | - 'view_type': 'form', |
58 | - 'res_model': 'return.claim', |
59 | - 'res_id': [obj.id], |
60 | - 'type': 'ir.actions.act_window', |
61 | - 'target': 'crash', |
62 | - 'domain': '[]', |
63 | - 'context': context} |
64 | + |
65 | + for claim in self.browse(cr, uid, ids, context=context): |
66 | + # Clear existing products |
67 | + line_ids = pl_obj.search(cr, uid, [ |
68 | + ('claim_id_claim_product_line', '=', claim.id), |
69 | + ], context=context) |
70 | + pl_obj.unlink(cr, uid, line_ids, context=context) |
71 | + |
72 | + if not claim.picking_id_return_claim: |
73 | + raise osv.except_osv( |
74 | + _('Error'), |
75 | + _('No Reception/Shipment reference selected on the %s claim.') % claim.name, |
76 | + ) |
77 | + |
78 | + src_location_id = False |
79 | + if claim.type_return_claim in TYPES_FOR_SRC_LOCATION and claim.default_src_location_id_return_claim: |
80 | + src_location_id = claim.default_src_location_id_return_claim.id |
81 | + |
82 | + # Create new claim.product.line on the return.claim from stock.move of the linked stock.picking |
83 | + for move in claim.picking_id_return_claim.move_lines: |
84 | + # Create corresponding product line |
85 | + product_line_values = { |
86 | + 'qty_claim_product_line': move.product_qty, |
87 | + 'price_unit_claim_product_line': move.price_unit, |
88 | + 'price_currency_claim_product_line': move.price_currency_id.id, |
89 | + 'claim_id_claim_product_line': claim.id, |
90 | + 'product_id_claim_product_line': move.product_id.id, |
91 | + 'uom_id_claim_product_line': move.product_uom.id, |
92 | + 'lot_id_claim_product_line': move.prodlot_id.id, |
93 | + 'expiry_date_claim_product_line': move.expired_date, |
94 | + 'asset_id_claim_product_line': move.asset_id.id, |
95 | + 'stock_move_id_claim_product_line': move.id, |
96 | + 'composition_list_id_claim_product_line': move.composition_list_id.id, |
97 | + 'src_location_id_claim_product_line': src_location_id, |
98 | + } |
99 | + pl_obj.create(cr, uid, product_line_values, context=context) |
100 | + |
101 | + return True |
102 | |
103 | def on_change_origin(self, cr, uid, ids, picking_id, context=None): |
104 | ''' |
105 | @@ -465,38 +474,130 @@ |
106 | |
107 | return result |
108 | |
109 | - _columns = {'name': fields.char(string='Reference', size=1024, required=True), # default value |
110 | - 'creation_date_return_claim': fields.date(string='Creation Date', required=True), # default value |
111 | - 'po_so_return_claim': fields.char(string='Order reference', size=1024), |
112 | - 'order_line_number_return_claim': fields.char(string='Order line number', size=1024), |
113 | - 'type_return_claim': fields.selection(CLAIM_TYPE, string='Type', required=True), |
114 | - 'category_return_claim': fields.selection(ORDER_CATEGORY, string='Category'), |
115 | - 'description_return_claim': fields.text(string='Description'), |
116 | - 'follow_up_return_claim': fields.text(string='Follow Up'), |
117 | - 'state': fields.selection(CLAIM_STATE, string='State', readonly=True), # default value |
118 | - # many2one |
119 | - 'sequence_id_return_claim': fields.many2one('ir.sequence', 'Events Sequence', required=True, ondelete='cascade'), # from create function |
120 | - 'partner_id_return_claim': fields.many2one('res.partner', string='Partner', required=True), |
121 | - 'po_id_return_claim': fields.many2one('purchase.order', string='Purchase Order'), |
122 | - 'so_id_return_claim': fields.many2one('sale.order', string='Sale Order'), |
123 | - 'picking_id_return_claim': fields.many2one('stock.picking', string='Reception/Shipment reference', required=True), # origin |
124 | - 'default_src_location_id_return_claim': fields.many2one('stock.location', string='Default Source Location', required=True), # default value |
125 | - # one2many |
126 | - 'event_ids_return_claim': fields.one2many('claim.event', 'return_claim_id_claim_event', string='Events'), |
127 | - 'product_line_ids_return_claim': fields.one2many('claim.product.line', 'claim_id_claim_product_line', string='Products'), |
128 | - # functions |
129 | - 'contains_event_return_claim': fields.function(_vals_get_claim, method=True, string='Contains Events', type='boolean', readonly=True, multi='get_vals_claim'), |
130 | - 'fake_state_return_claim': fields.function(_vals_get_claim, method=True, string='Fake State', type='selection', selection=CLAIM_STATE, readonly=True, multi='get_vals_claim'), |
131 | - } |
132 | - |
133 | - _defaults = {'creation_date_return_claim': lambda *a: time.strftime('%Y-%m-%d'), |
134 | - 'name': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'return.claim'), |
135 | - 'default_src_location_id_return_claim': lambda obj, cr, uid, c: obj.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'stock_location_stock') and obj.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'stock_location_stock')[1] or False, |
136 | - 'state': 'draft', |
137 | - 'fake_state_return_claim': 'draft', |
138 | - 'po_id_return_claim': False, |
139 | - 'so_id_return_claim': False, |
140 | - } |
141 | + _columns = { |
142 | + 'name': fields.char( |
143 | + string='Reference', |
144 | + size=1024, |
145 | + required=True, |
146 | + ), |
147 | + 'creation_date_return_claim': fields.date( |
148 | + string='Creation Date', |
149 | + required=True, |
150 | + ), |
151 | + 'po_so_return_claim': fields.char( |
152 | + string='Order reference', |
153 | + size=1024, |
154 | + ), |
155 | + 'order_line_number_return_claim': fields.char( |
156 | + string='Order line number', |
157 | + size=1024, |
158 | + ), |
159 | + 'type_return_claim': fields.selection( |
160 | + selection=CLAIM_TYPE, |
161 | + string='Type', |
162 | + required=True, |
163 | + ), |
164 | + 'category_return_claim': fields.selection( |
165 | + selection=ORDER_CATEGORY, |
166 | + string='Category', |
167 | + ), |
168 | + 'description_return_claim': fields.text( |
169 | + string='Description', |
170 | + ), |
171 | + 'follow_up_return_claim': fields.text( |
172 | + string='Follow Up', |
173 | + ), |
174 | + 'state': fields.selection( |
175 | + selection=CLAIM_STATE, |
176 | + string='State', |
177 | + readonly=True, |
178 | + ), |
179 | + # Many2one |
180 | + 'sequence_id_return_claim': fields.many2one( |
181 | + 'ir.sequence', |
182 | + string='Events Sequence', |
183 | + required=True, |
184 | + ondelete='cascade', |
185 | + ), # from create function |
186 | + 'partner_id_return_claim': fields.many2one( |
187 | + 'res.partner', |
188 | + string='Partner', |
189 | + required=True, |
190 | + ), |
191 | + 'po_id_return_claim': fields.many2one( |
192 | + 'purchase.order', |
193 | + string='Purchase Order', |
194 | + ), |
195 | + 'so_id_return_claim': fields.many2one( |
196 | + 'sale.order', |
197 | + string='Sale Order', |
198 | + ), |
199 | + 'picking_id_return_claim': fields.many2one( |
200 | + 'stock.picking', |
201 | + string='Reception/Shipment reference', |
202 | + required=True, |
203 | + ), # origin |
204 | + 'default_src_location_id_return_claim': fields.many2one( |
205 | + 'stock.location', |
206 | + string='Default Source Location', |
207 | + required=True, |
208 | + ), # default value |
209 | + # One2many |
210 | + 'event_ids_return_claim': fields.one2many( |
211 | + 'claim.event', |
212 | + 'return_claim_id_claim_event', |
213 | + string='Events', |
214 | + ), |
215 | + 'product_line_ids_return_claim': fields.one2many( |
216 | + 'claim.product.line', |
217 | + 'claim_id_claim_product_line', |
218 | + string='Products', |
219 | + ), |
220 | + # Functions |
221 | + 'contains_event_return_claim': fields.function( |
222 | + _vals_get_claim, |
223 | + method=True, |
224 | + string='Contains Events', |
225 | + type='boolean', |
226 | + readonly=True, |
227 | + multi='get_vals_claim', |
228 | + ), |
229 | + 'fake_state_return_claim': fields.function( |
230 | + _vals_get_claim, |
231 | + method=True, |
232 | + string='Fake State', |
233 | + type='selection', |
234 | + selection=CLAIM_STATE, |
235 | + readonly=True, |
236 | + multi='get_vals_claim', |
237 | + ), |
238 | + } |
239 | + |
240 | + def _get_default_src_loc_id(self, cr, uid, context=None): |
241 | + """ |
242 | + Return the stock.location Stock as default source location |
243 | + :param cr: Cursor to the database |
244 | + :param uid: ID of the res.users that calls this method |
245 | + :param context: Context of the call |
246 | + :return: The ID of the stock.location named Stock |
247 | + """ |
248 | + data_obj = self.pool.get('ir.model.data') |
249 | + |
250 | + data_ids = data_obj.get_object_reference(cr, uid, 'stock', 'stock_location_stock') |
251 | + if data_ids: |
252 | + return data_ids[1] |
253 | + |
254 | + return False |
255 | + |
256 | + _defaults = { |
257 | + 'creation_date_return_claim': lambda *a: time.strftime('%Y-%m-%d'), |
258 | + 'name': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'return.claim'), |
259 | + 'default_src_location_id_return_claim': _get_default_src_loc_id, |
260 | + 'state': 'draft', |
261 | + 'fake_state_return_claim': 'draft', |
262 | + 'po_id_return_claim': False, |
263 | + 'so_id_return_claim': False, |
264 | + } |
265 | |
266 | def _check_claim(self, cr, uid, ids, context=None): |
267 | """ |
268 | @@ -835,108 +936,172 @@ |
269 | 'context': context} |
270 | |
271 | def _do_process_event(self, cr, uid, ids, context=None): |
272 | - ''' |
273 | - process the events |
274 | + """ |
275 | + Process the claim.event of the return.claim. |
276 | + If the return.claim not coming from a chained picking processing, create a stock.picking |
277 | + :param cr: Cursor to the database |
278 | + :param uid: ID of the res.users that calls the method |
279 | + :param ids: List of ID of the claim.event to process |
280 | + :param context: Context of the call |
281 | + :return: True |
282 | + """ |
283 | + # Objects |
284 | + claim_obj = self.pool.get('return.claim') |
285 | + fields_tools = self.pool.get('fields.tools') |
286 | + data_tools = self.pool.get('data.tools') |
287 | + pick_obj = self.pool.get('stock.picking') |
288 | |
289 | - - create a picking if not coming from chained picking processing |
290 | - ''' |
291 | # Some verifications |
292 | if context is None: |
293 | context = {} |
294 | + |
295 | if isinstance(ids, (int, long)): |
296 | ids = [ids] |
297 | |
298 | - # objects |
299 | - claim_obj = self.pool.get('return.claim') |
300 | - fields_tools = self.pool.get('fields.tools') |
301 | - data_tools = self.pool.get('data.tools') |
302 | - pick_obj = self.pool.get('stock.picking') |
303 | - move_obj = self.pool.get('stock.move') |
304 | - # load common data |
305 | + # Load common data |
306 | data_tools.load_common_data(cr, uid, ids, context=context) |
307 | - # base of function names |
308 | - base_func = '_do_process_' |
309 | - for obj in self.browse(cr, uid, ids, context=context): |
310 | - # event must be draft |
311 | - if obj.state != 'draft': |
312 | - raise osv.except_osv(_('Warning !'), _('Only events in state draft can be processed.')) |
313 | - # integrity check on product lines for corresponding claim - only for first event - only if from scratch - if from wizard, the checks must be done from the wizard logic |
314 | - # we do not check integrity from wizard because of force availability option at picking level -> processing even if no stock available |
315 | - events = obj.return_claim_id_claim_event.event_ids_return_claim |
316 | + |
317 | + no_draft_event_ids = self.search(cr, uid, [ |
318 | + ('state', '!=', 'draft'), |
319 | + ('id', 'in', ids) |
320 | + ], limit=1, order='NO_ORDER', context=context) |
321 | + if no_draft_event_ids: |
322 | + raise osv.except_osv( |
323 | + _('Warning !'), |
324 | + _('Only events in Draft state can be processed'), |
325 | + ) |
326 | + |
327 | + def _get_po_line_id(x): |
328 | + """ |
329 | + Return the ID of the purchase.order.line associated to the stock.move |
330 | + :param x: The browse_record of a stock.move |
331 | + :return: The ID of the purchase.order.line associated to the stock.move |
332 | + """ |
333 | + if x.stock_move_id_claim_product_line.purchase_line_id: |
334 | + return x.stock_move_id_claim_product_line.purchase_line_id.id |
335 | + return False |
336 | + |
337 | + for event in self.browse(cr, uid, ids, context=context): |
338 | + """ |
339 | + Integrity check on product lines for corresponding claim: |
340 | + - only for first event |
341 | + - only if from scratch |
342 | + - if from wizard, the check must be done from the wizard logic |
343 | + We do not check integrity from wizard because of force_availability option at picking level |
344 | + -> processing even if no stock available |
345 | + """ |
346 | + events = event.return_claim_id_claim_event.event_ids_return_claim |
347 | integrity_check = True |
348 | - if len(events) == 1 and not events[0].from_picking_wizard_claim_event and obj.return_claim_id_claim_event.type_return_claim in TYPES_FOR_INTEGRITY: |
349 | - integrity_check = claim_obj.check_product_lines_integrity(cr, uid, obj.return_claim_id_claim_event.id, context=context) |
350 | + if event.return_claim_id_claim_event.type_return_claim in TYPES_FOR_INTEGRITY: |
351 | + if len(events) == 1 and not events[0].from_picking_wizard_claim_event: |
352 | + integrity_check = claim_obj.\ |
353 | + check_product_lines_integrity(cr, uid, event.return_claim_id_claim_event.id, context=context) |
354 | + |
355 | if not integrity_check: |
356 | - # return False |
357 | return False |
358 | - # create picking object if not coming from chained IN picking process |
359 | - if not obj.from_picking_wizard_claim_event: |
360 | - # claim |
361 | - claim = obj.return_claim_id_claim_event |
362 | + |
363 | + # Create picking object if not coming from chained IN picking process |
364 | + if not event.from_picking_wizard_claim_event: |
365 | + claim = event.return_claim_id_claim_event |
366 | # we use default values as if the picking was from chained creation (so type is 'internal') |
367 | # different values need according to event type is then replaced during specific do_process functions |
368 | - event_picking_values = {'type': 'internal', |
369 | - 'partner_id2': claim.partner_id_return_claim.id, |
370 | - 'origin': claim.po_so_return_claim, |
371 | - 'order_category': claim.category_return_claim, |
372 | - 'reason_type_id': context['common']['rt_internal_supply'], |
373 | - } |
374 | - # create picking |
375 | + event_picking_values = { |
376 | + 'type': 'internal', |
377 | + 'partner_id2': claim.partner_id_return_claim.id, |
378 | + 'origin': claim.po_so_return_claim, |
379 | + 'order_category': claim.category_return_claim, |
380 | + 'purchase_id': claim.picking_id_return_claim.purchase_id.id, |
381 | + 'reason_type_id': context['common']['rt_internal_supply'], |
382 | + } |
383 | + |
384 | new_event_picking_id = pick_obj.create(cr, uid, event_picking_values, context=context) |
385 | - # we are interested in the previous value, as we are processing the last one, we must seek for -2 index |
386 | + |
387 | + # We are interested in the previous value, as we are processing the last one, we must seek for -2 index |
388 | previous_id = claim_obj.get_last_event(cr, uid, claim.id, pos=-2, context=context)[claim.id] |
389 | if previous_id: |
390 | - # previous event |
391 | previous = self.browse(cr, uid, previous_id, context=context) |
392 | # we've got a previous event, so we copy the moves from the previous event picking |
393 | # with destination as source for the new picking event |
394 | - moves_lines = [(0, 0, {'name': x.name, |
395 | - 'product_id': x.product_id.id, |
396 | - 'asset_id': x.asset_id.id, |
397 | - 'composition_list_id': x.composition_list_id.id, |
398 | - 'prodlot_id': x.prodlot_id.id, |
399 | - 'date': context['common']['date'], |
400 | - 'date_expected': context['common']['date'], |
401 | - 'product_qty': x.product_qty, |
402 | - 'product_uom': x.product_uom.id, |
403 | - 'product_uos_qty': x.product_uos_qty, |
404 | - 'product_uos': x.product_uos.id, |
405 | - 'location_id': x.location_dest_id.id, |
406 | - 'location_dest_id': context['common']['stock_id'], |
407 | - 'company_id': context['common']['company_id'], |
408 | - 'reason_type_id': context['common']['rt_internal_supply']}) for x in previous.event_picking_id_claim_event.move_lines] |
409 | + moves_lines = [(0, 0, { |
410 | + 'name': x.name, |
411 | + 'product_id': x.product_id.id, |
412 | + 'asset_id': x.asset_id.id, |
413 | + 'composition_list_id': x.composition_list_id.id, |
414 | + 'prodlot_id': x.prodlot_id.id, |
415 | + 'date': context['common']['date'], |
416 | + 'date_expected': context['common']['date'], |
417 | + 'product_qty': x.product_qty, |
418 | + 'product_uom': x.product_uom.id, |
419 | + 'product_uos_qty': x.product_uos_qty, |
420 | + 'product_uos': x.product_uos.id, |
421 | + 'price_unit': x.price_unit, |
422 | + 'price_currency_id': x.price_currency_id.id, |
423 | + 'location_id': x.location_dest_id.id, |
424 | + 'location_dest_id': context['common']['stock_id'], |
425 | + 'purchase_line_id': x.purchase_line_id and x.purchase_line_id.id or False, |
426 | + 'company_id': context['common']['company_id'], |
427 | + 'reason_type_id': context['common']['rt_internal_supply'], |
428 | + }) for x in previous.event_picking_id_claim_event.move_lines] |
429 | else: |
430 | - # no previous event, we generate the moves based on the claim's product lines |
431 | - moves_lines = [(0, 0, {'name': x.name, |
432 | - 'product_id': x.product_id_claim_product_line.id, |
433 | - 'asset_id': x.asset_id_claim_product_line.id, |
434 | - 'composition_list_id': x.composition_list_id_claim_product_line.id, |
435 | - 'prodlot_id': x.lot_id_claim_product_line.id, |
436 | - 'date': context['common']['date'], |
437 | - 'date_expected': context['common']['date'], |
438 | - 'product_qty': x.qty_claim_product_line, |
439 | - 'product_uom': x.uom_id_claim_product_line.id, |
440 | - 'product_uos_qty': x.qty_claim_product_line, |
441 | - 'product_uos': x.uom_id_claim_product_line.id, |
442 | - 'location_id': x.src_location_id_claim_product_line.id, |
443 | - 'location_dest_id': context['common']['stock_id'], |
444 | - 'company_id': context['common']['company_id'], |
445 | - 'reason_type_id': context['common']['rt_internal_supply']}) for x in claim.product_line_ids_return_claim] |
446 | - # update the created picking with stock moves |
447 | - pick_obj.write(cr, uid, [new_event_picking_id], {'move_lines': moves_lines}, context=context) |
448 | - # update the claim setting the link to created event picking |
449 | - self.write(cr, uid, [obj.id], {'event_picking_id_claim_event': new_event_picking_id}, context=context) |
450 | - |
451 | - for obj in self.browse(cr, uid, ids, context=context): |
452 | - # we start a new loop in order to have browse object reloaded, taking into account possible previous modification to claim object |
453 | - result = getattr(self, base_func + obj.type_claim_event)(cr, uid, obj, context=context) |
454 | - # event is done |
455 | - obj.write({'state': 'done'}, context=context) |
456 | - # log process message |
457 | - event_type_name = fields_tools.get_selection_name(cr, uid, object=self, field='type_claim_event', key=obj.type_claim_event, context=context) |
458 | - self.log(cr, uid, obj.id, _('%s Event %s has been processed.') % (event_type_name, obj.name)) |
459 | - # we force the state of claim to in_progress |
460 | - obj.return_claim_id_claim_event.write({'state': 'in_progress'}, context=context) |
461 | + moves_lines = [(0, 0, { |
462 | + 'name': x.name, |
463 | + 'product_id': x.product_id_claim_product_line.id, |
464 | + 'asset_id': x.asset_id_claim_product_line.id, |
465 | + 'composition_list_id': x.composition_list_id_claim_product_line.id, |
466 | + 'prodlot_id': x.lot_id_claim_product_line.id, |
467 | + 'date': context['common']['date'], |
468 | + 'date_expected': context['common']['date'], |
469 | + 'product_qty': x.qty_claim_product_line, |
470 | + 'product_uom': x.uom_id_claim_product_line.id, |
471 | + 'product_uos_qty': x.qty_claim_product_line, |
472 | + 'product_uos': x.uom_id_claim_product_line.id, |
473 | + 'price_unit': x.price_unit_claim_product_line, |
474 | + 'price_currency_id': x.price_currency_claim_product_line.id, |
475 | + 'purchase_line_id': _get_po_line_id(x), |
476 | + 'location_id': x.src_location_id_claim_product_line.id, |
477 | + 'location_dest_id': context['common']['stock_id'], |
478 | + 'company_id': context['common']['company_id'], |
479 | + 'reason_type_id': context['common']['rt_internal_supply'], |
480 | + }) for x in claim.product_line_ids_return_claim] |
481 | + |
482 | + # Update the created picking with stock moves |
483 | + pick_obj.write(cr, uid, [new_event_picking_id], { |
484 | + 'move_lines': moves_lines, |
485 | + }, context=context) |
486 | + # Update the claim setting the link to created event picking |
487 | + self.write(cr, uid, [event.id], { |
488 | + 'event_picking_id_claim_event': new_event_picking_id, |
489 | + }, context=context) |
490 | + |
491 | + claim_ids = set() |
492 | + log_msgs = [] |
493 | + base_func = '_do_process_' |
494 | + # Reload browse_record values to get last updated values |
495 | + for event in self.browse(cr, uid, ids, context=context): |
496 | + getattr(self, base_func + event.type_claim_event)(cr, uid, event, context=context) |
497 | + # Log process message |
498 | + event_type_name = fields_tools.get_selection_name(cr, uid, |
499 | + object=self, |
500 | + field='type_claim_event', |
501 | + key=event.type_claim_event, |
502 | + context=context) |
503 | + log_msgs.append((event.id, _('%s Event %s has been processed.') % (event_type_name, event.name))) |
504 | + claim_ids.add(event.return_claim_id_claim_event.id) |
505 | + |
506 | + # Update events |
507 | + self.write(cr, uid, ids, { |
508 | + 'state': 'done', |
509 | + }, context=context) |
510 | + |
511 | + # Create res.log |
512 | + for log_msg in log_msgs: |
513 | + self.log(cr, uid, log_msg[0], log_msg[1]) |
514 | + |
515 | + # Update claims |
516 | + claim_obj.write(cr, uid, list(claim_ids), { |
517 | + 'state': 'in_progress', |
518 | + }) |
519 | + |
520 | return True |
521 | |
522 | def _vals_get_claim(self, cr, uid, ids, fields, arg, context=None): |
523 | @@ -964,26 +1129,82 @@ |
524 | |
525 | return result |
526 | |
527 | - _columns = {'return_claim_id_claim_event': fields.many2one('return.claim', string='Claim', required=True, ondelete='cascade', readonly=True), |
528 | - 'creation_date_claim_event': fields.date(string='Creation Date', required=True, readonly=True), # default value |
529 | - 'type_claim_event': fields.selection(CLAIM_EVENT_TYPE, string='Type', required=True, readonly=True), |
530 | - 'replacement_picking_expected_claim_event': fields.boolean(string='Replacement expected for Return Claim?', help="An Incoming Shipment will be automatically created corresponding to returned products."), |
531 | - 'description_claim_event': fields.char(size=1024, string='Comment'), |
532 | - 'state': fields.selection(CLAIM_EVENT_STATE, string='State', readonly=True), # default value |
533 | - 'from_picking_wizard_claim_event': fields.boolean(string='From Picking Wizard', readonly=True), |
534 | - 'event_picking_id_claim_event': fields.many2one('stock.picking', string='Event Picking'), |
535 | - # auto fields from create function |
536 | - 'name': fields.char(string='Reference', size=1024, readonly=True), # from create function |
537 | - 'order_claim_event': fields.integer(string='Creation Order', readonly=True), # from create function |
538 | - # functions |
539 | - 'location_id_claim_event': fields.function(_vals_get_claim, method=True, string='Associated Location', type='many2one', relation='stock.location', readonly=True, multi='get_vals_claim'), |
540 | - 'hidden_state': fields.function(_vals_get_claim, method=True, string='Hidden State', type='selection', selection=CLAIM_EVENT_STATE, readonly=True, multi='get_vals_claim'), |
541 | - } |
542 | + _columns = { |
543 | + 'return_claim_id_claim_event': fields.many2one( |
544 | + 'return.claim', |
545 | + string='Claim', |
546 | + required=True, |
547 | + ondelete='cascade', |
548 | + readonly=True, |
549 | + ), |
550 | + 'creation_date_claim_event': fields.date( |
551 | + string='Creation Date', |
552 | + required=True, |
553 | + readonly=True, |
554 | + ), # default value |
555 | + 'type_claim_event': fields.selection( |
556 | + selection=CLAIM_EVENT_TYPE, |
557 | + string='Type', |
558 | + required=True, |
559 | + readonly=True, |
560 | + ), |
561 | + 'replacement_picking_expected_claim_event': fields.boolean( |
562 | + string='Replacement expected for Return Claim?', |
563 | + help="An Incoming Shipment will be automatically created corresponding to returned products.", |
564 | + ), |
565 | + 'description_claim_event': fields.char( |
566 | + size=1024, |
567 | + string='Comment', |
568 | + ), |
569 | + 'state': fields.selection( |
570 | + selection=CLAIM_EVENT_STATE, |
571 | + string='State', |
572 | + readonly=True, |
573 | + ), # default value |
574 | + 'from_picking_wizard_claim_event': fields.boolean( |
575 | + string='From Picking Wizard', |
576 | + readonly=True, |
577 | + ), |
578 | + 'event_picking_id_claim_event': fields.many2one( |
579 | + 'stock.picking', |
580 | + string='Event Picking', |
581 | + ), |
582 | + # Auto fields from create function |
583 | + 'name': fields.char( |
584 | + string='Reference', |
585 | + size=1024, |
586 | + readonly=True, |
587 | + ), |
588 | + 'order_claim_event': fields.integer( |
589 | + string='Creation Order', |
590 | + readonly=True, |
591 | + ), |
592 | + # Functions |
593 | + 'location_id_claim_event': fields.function( |
594 | + _vals_get_claim, |
595 | + method=True, |
596 | + string='Associated Location', |
597 | + type='many2one', |
598 | + relation='stock.location', |
599 | + readonly=True, |
600 | + multi='get_vals_claim', |
601 | + ), |
602 | + 'hidden_state': fields.function( |
603 | + _vals_get_claim, |
604 | + method=True, |
605 | + string='Hidden State', |
606 | + type='selection', |
607 | + selection=CLAIM_EVENT_STATE, |
608 | + readonly=True, |
609 | + multi='get_vals_claim', |
610 | + ), |
611 | + } |
612 | |
613 | - _defaults = {'creation_date_claim_event': lambda *a: time.strftime('%Y-%m-%d'), |
614 | - 'state': 'draft', |
615 | - 'from_picking_wizard_claim_event': False, |
616 | - } |
617 | + _defaults = { |
618 | + 'creation_date_claim_event': lambda *a: time.strftime('%Y-%m-%d'), |
619 | + 'state': 'draft', |
620 | + 'from_picking_wizard_claim_event': False, |
621 | + } |
622 | |
623 | claim_event() |
624 | |
625 | @@ -1257,6 +1478,7 @@ |
626 | _columns = {'integrity_status_claim_product_line': fields.selection(string=' ', selection=INTEGRITY_STATUS_SELECTION, readonly=True), |
627 | 'name': fields.char(string='Name', size=1024), # auto data from create/write |
628 | 'qty_claim_product_line': fields.float(string='Qty', digits_compute=dp.get_precision('Product UoM'), required=True), |
629 | + 'price_unit_claim_product_line': fields.float(string='Currency', digits_compute=dp.get_precision('Account'), required=True), |
630 | # many2one |
631 | 'claim_id_claim_product_line': fields.many2one('return.claim', string='Claim', required=True, ondelete='cascade'), |
632 | 'product_id_claim_product_line': fields.many2one('product.product', string='Product', required=True), |
633 | @@ -1266,6 +1488,7 @@ |
634 | 'asset_id_claim_product_line' : fields.many2one('product.asset', string='Asset'), |
635 | 'composition_list_id_claim_product_line': fields.many2one('composition.kit', string='Kit'), |
636 | 'src_location_id_claim_product_line': fields.many2one('stock.location', string='Src Location'), |
637 | + 'price_currency_claim_product_line': fields.many2one('res.currency', string='Currency'), |
638 | 'stock_move_id_claim_product_line': fields.many2one('stock.move', string='Corresponding IN stock move'), # value from wizard process |
639 | 'type_check': fields.char(string='Type Check', size=1024,), # default value |
640 | # functions |
641 | @@ -1496,6 +1719,8 @@ |
642 | 'picking_id_return_claim': picking_id, |
643 | 'product_line_ids_return_claim': [(0, 0, { |
644 | 'qty_claim_product_line': x.product_qty, |
645 | + 'price_unit_claim_product_line': x.price_unit, |
646 | + 'price_currency_claim_product_line': x.price_currency_id.id, |
647 | 'product_id_claim_product_line': x.product_id.id, |
648 | 'uom_id_claim_product_line': x.product_uom.id, |
649 | 'lot_id_claim_product_line': x.prodlot_id.id, |