33
33
class sale_order(osv.osv):
35
35
_inherit = 'sale.order'
36
36
_description = 'Sales Order'
37
37
_columns = {'sequence_id': fields.many2one('ir.sequence', 'Lines Sequence', help="This field contains the information related to the numbering of the lines of this order.", required=True, ondelete='cascade'),
40
40
def create_sequence(self, cr, uid, vals, context=None):
42
42
Create new entry sequence for every new order
67
67
return seq_pool.create(cr, uid, seq)
69
69
def create(self, cr, uid, vals, context=None):
71
71
create from sale_order
77
77
if not context.get('keepClientOrder') or not context.get('keepDateAndDistrib') or not vals.get('sequence_id'):
78
78
vals.update({'sequence_id': self.create_sequence(cr, uid, vals, context)})
80
80
return super(sale_order, self).create(cr, uid, vals, context)
82
82
def reorder_line_numbering(self, cr, uid, ids, context=None):
87
87
tools_obj = self.pool.get('sequence.tools')
88
88
tools_obj.reorder_sequence_number(cr, uid, 'sale.order', 'sequence_id', 'sale.order.line', 'order_id', ids, 'line_number', context=context)
91
91
def allow_resequencing(self, cr, uid, so_browse, context=None):
93
93
allow resequencing criteria
95
95
if so_browse.state == 'draft' and not so_browse.client_order_ref:
99
def _hook_ship_create_stock_move(self, cr, uid, ids, context=None, *args, **kwargs):
101
Please copy this to your module's method also.
102
This hook belongs to the action_ship_create method from sale>sale.py
104
- allow to modify the data for stock move creation
105
- set the line number of the Out corresponding to the one from Sale order
107
move_data = super(sale_order, self)._hook_ship_create_stock_move(cr, uid, ids, context=context, *args, **kwargs)
108
line = kwargs['line']
109
# copy original line number
110
move_data['line_number'] = line.line_number
122
108
_columns = {'line_number': fields.integer(string='Line', required=True),
124
110
_order = 'line_number, id'
126
112
def create(self, cr, uid, vals, context=None):
128
114
_inherit = 'sale.order.line'
144
130
# create the new sale order line
145
131
result = super(sale_order_line, self).create(cr, uid, vals, context=context)
148
134
def copy_data(self, cr, uid, id, default=None, context=None):
150
136
if the line_number is not in the default, we set it to False
154
140
if context is None:
157
143
# we set line_number, so it will not be copied in copy_data - keepLineNumber - the original Line Number will be kept
158
144
if 'line_number' not in default and not context.get('keepLineNumber', False):
159
145
default.update({'line_number': False})
160
146
return super(sale_order_line, self).copy_data(cr, uid, id, default, context=context)
162
148
def unlink(self, cr, uid, ids, context=None):
164
150
check the numbering on deletion
169
155
if isinstance(ids, (int, long)):
173
159
tools_obj = self.pool.get('sequence.tools')
175
161
if not context.get('skipResequencing', False):
176
# re sequencing only happen if field order is draft and not synchronized (PUSH flow) (behavior 1)
162
# re sequencing only happen if field order is draft and not synchronized (PUSH flow) (behavior 1)
177
163
draft_not_synchronized_ids = self.allow_resequencing(cr, uid, ids, context=context)
178
164
tools_obj.reorder_sequence_number_from_unlink(cr, uid, draft_not_synchronized_ids, 'sale.order', 'sequence_id', 'sale.order.line', 'order_id', 'line_number', context=context)
180
166
return super(sale_order_line, self).unlink(cr, uid, ids, context=context)
182
168
def allow_resequencing(self, cr, uid, ids, context=None):
184
170
define if a resequencing has to be performed or not
186
172
return the list of ids for which resequencing will can be performed
188
174
linked to Fo + Fo draft + Fo not sync
191
177
so_obj = self.pool.get('sale.order')
193
179
resequencing_ids = [x.id for x in self.browse(cr, uid, ids, context=context) if x.order_id and so_obj.allow_resequencing(cr, uid, x.order_id, context=context)]
194
180
return resequencing_ids
196
182
sale_order_line()
199
185
class purchase_order(osv.osv):
201
187
_inherit = 'purchase.order'
202
188
_description = 'Purchase Order'
203
189
_columns = {'sequence_id': fields.many2one('ir.sequence', 'Lines Sequence', help="This field contains the information related to the numbering of the lines of this order.", required=True, ondelete='cascade'),
206
192
def create_sequence(self, cr, uid, vals, context=None):
208
194
Create new entry sequence for every new order
233
219
return seq_pool.create(cr, uid, seq)
235
221
def create(self, cr, uid, vals, context=None):
237
223
create from purchase_order
238
224
create the sequence for the numbering of the lines
240
226
vals.update({'sequence_id': self.create_sequence(cr, uid, vals, context)})
242
228
return super(purchase_order, self).create(cr, uid, vals, context)
244
230
def reorder_line_numbering(self, cr, uid, ids, context=None):
249
235
tools_obj = self.pool.get('sequence.tools')
250
236
tools_obj.reorder_sequence_number(cr, uid, 'purchase.order', 'sequence_id', 'purchase.order.line', 'order_id', ids, 'line_number', context=context)
253
239
def allow_resequencing(self, cr, uid, po_browse, context=None):
255
241
allow resequencing criteria
280
266
po_obj = self.pool.get('purchase.order')
281
267
seq_pool = self.pool.get('ir.sequence')
283
269
# I leave this line from QT related to purchase.order.merged.line for compatibility and safety reasons
284
270
# merged lines, set the line_number to 0 when calling create function
285
271
# the following line should *logically* be removed safely
293
279
sequence_id = po_obj.read(cr, uid, [vals['order_id']], ['sequence_id'], context=context)[0]['sequence_id'][0]
294
280
line = seq_pool.get_id(cr, uid, sequence_id, code_or_id='id', context=context)
295
281
vals.update({'line_number': line})
297
283
# create the new sale order line
298
284
result = super(purchase_order_line, self).create(cr, uid, vals, context=context)
301
287
def copy_data(self, cr, uid, id, default=None, context=None):
303
289
if the line_number is not in the default, we set it to False
307
293
if context is None:
310
296
# we set line_number, so it will not be copied in copy_data - keepLineNumber - the original Line Number will be kept
311
297
if 'line_number' not in default and not context.get('keepLineNumber', False):
312
298
default.update({'line_number': False})
313
299
return super(purchase_order_line, self).copy_data(cr, uid, id, default, context=context)
315
301
def unlink(self, cr, uid, ids, context=None):
317
303
check the numbering on deletion
322
308
if isinstance(ids, (int, long)):
326
312
tools_obj = self.pool.get('sequence.tools')
328
314
if not context.get('skipResequencing', False):
329
# re sequencing only happen if purchase order is draft (behavior 1)
315
# re sequencing only happen if purchase order is draft (behavior 1)
330
316
# get ids with corresponding po at draft state
331
317
draft_ids = self.allow_resequencing(cr, uid, ids, context=context)
332
318
tools_obj.reorder_sequence_number_from_unlink(cr, uid, draft_ids, 'purchase.order', 'sequence_id', 'purchase.order.line', 'order_id', 'line_number', context=context)
334
320
return super(purchase_order_line, self).unlink(cr, uid, ids, context=context)
336
322
def allow_resequencing(self, cr, uid, ids, context=None):
338
324
define if a resequencing has to be performed or not
340
326
return the list of ids for which resequencing will can be performed
342
328
linked to Po + Po allows resequencing
345
331
po_obj = self.pool.get('purchase.order')
347
333
resequencing_ids = [x.id for x in self.browse(cr, uid, ids, context=context) if x.order_id and po_obj.allow_resequencing(cr, uid, x.order_id, context=context)]
348
334
return resequencing_ids
350
336
purchase_order_line()
361
347
Please copy this to your module's method also.
362
348
This hook belongs to the make_po method from purchase>purchase.py>procurement_order
364
350
- allow to modify the data for purchase order line creation
366
352
if isinstance(ids, (int, long)):
370
356
po_obj = self.pool.get('purchase.order')
371
357
procurement = kwargs['procurement']
373
359
line = super(procurement_order, self).po_line_values_hook(cr, uid, ids, context=context, *args, **kwargs)
374
360
# if we are updating the sale order from the corresponding on order purchase order
375
361
# the purchase order to merge the new line to is locked and provided in the procurement
379
365
if not po_obj.allow_resequencing(cr, uid, procurement.so_back_update_dest_po_id_procurement_order, context=context):
380
366
line.update({'line_number': procurement.so_back_update_dest_pol_id_procurement_order.line_number})
383
369
procurement_order()
386
372
class supplier_catalogue(osv.osv):
388
374
_inherit = 'supplier.catalogue'
389
375
_description = 'Supplier catalogue'
390
376
_columns = {'sequence_id': fields.many2one('ir.sequence', 'Lines Sequence', help="This field contains the information related to the numbering of the lines of this order.", required=True, ondelete='cascade'),
393
379
def create_sequence(self, cr, uid, vals, context=None):
395
381
Create new entry sequence for every new order
420
406
return seq_pool.create(cr, uid, seq)
422
408
def create(self, cr, uid, vals, context=None):
424
410
create from purchase_order
425
411
create the sequence for the numbering of the lines
427
413
vals.update({'sequence_id': self.create_sequence(cr, uid, vals, context)})
429
415
return super(supplier_catalogue, self).create(cr, uid, vals, context)
431
417
supplier_catalogue()
445
431
def create(self, cr, uid, vals, context=None):
447
433
_inherit = 'supplier.catalogue.line'
449
435
add the corresponding line number
451
437
if self._name != 'supplier.catalogue.merged.line':
454
440
sequence = order.sequence_id
455
441
line = sequence.get_id(code_or_id='id', context=context)
456
442
vals.update({'line_number': line})
458
444
# create the new sale order line
459
445
result = super(supplier_catalogue_line, self).create(cr, uid, vals, context=context)
463
449
supplier_catalogue_line()
519
505
if s and '%(instance)s' in s:
520
506
data['instance'] = self._get_instance(cr, uid)
521
507
if s and '%(hqcode)s' in s:
522
data['hqcode'] = self._get_hqcode(cr, uid)
508
data['hqcode'] = self._get_hqcode(cr, uid)
523
509
if s and '%(instance_code)s' in s:
524
510
data['instance_code'] = self._get_instance_code(cr, uid)
526
512
return (s or '') % data