28
28
_name = 'stock.warehouse.automatic.supply'
29
29
_description = 'Automatic Supply'
30
30
_order = 'name, id'
32
32
def _get_next_date_from_frequence(self, cr, uid, ids, name, args, context=None):
34
34
Returns the next date of the frequency
38
38
for proc in self.browse(cr, uid, ids):
39
39
if proc.frequence_id and proc.frequence_id.next_date:
40
40
res[proc.id] = proc.frequence_id.next_date
42
42
res[proc.id] = False
46
46
def _get_frequence_change(self, cr, uid, ids, context=None):
48
48
Returns Auto. Sup. ids when frequence change
62
62
for proc in self.browse(cr, uid, ids):
63
63
if proc.frequence_id:
64
res[proc.id] = self.pool.get('stock.frequence').name_get(cr, uid, [proc.frequence_id.id], context=context)[0][1]
64
res[proc.id] = self.pool.get('stock.frequence').name_get(cr, uid, [proc.frequence_id.id])[0][1]
68
68
def _get_product_ids(self, cr, uid, ids, field_name, arg, context=None):
70
70
Returns a list of products for the rule
74
74
for rule in self.browse(cr, uid, ids, context=context):
76
76
for line in rule.line_ids:
77
77
res[rule.id].append(line.product_id.id)
81
81
def _src_product_ids(self, cr, uid, obj, name, args, context=None):
88
88
if arg[0] == 'product_ids':
92
92
if l.supply_id.id not in rule_ids:
93
93
rule_ids.append(l.supply_id.id)
94
94
res.append(('id', 'in', rule_ids))
99
99
'sequence': fields.integer(string='Order', required=False, help='A higher order value means a low priority'),
100
100
'name': fields.char(size=64, string='Reference', required=True),
121
121
'stock.frequence': (_get_frequence_change, None, 20)}),
122
122
'product_ids': fields.function(_get_product_ids, fnct_search=_src_product_ids,
123
123
type='many2many', relation='product.product', method=True, string='Products'),
124
'sublist_id': fields.many2one('product.list', string='List/Sublist', ondelete='set null'),
125
'nomen_manda_0': fields.many2one('product.nomenclature', 'Main Type', ondelete='set null'),
126
'nomen_manda_1': fields.many2one('product.nomenclature', 'Group', ondelete='set null'),
127
'nomen_manda_2': fields.many2one('product.nomenclature', 'Family', ondelete='set null'),
128
'nomen_manda_3': fields.many2one('product.nomenclature', 'Root', ondelete='set null'),
124
'sublist_id': fields.many2one('product.list', string='List/Sublist'),
125
'nomen_manda_0': fields.many2one('product.nomenclature', 'Main Type'),
126
'nomen_manda_1': fields.many2one('product.nomenclature', 'Group'),
127
'nomen_manda_2': fields.many2one('product.nomenclature', 'Family'),
128
'nomen_manda_3': fields.many2one('product.nomenclature', 'Root'),
132
132
'active': lambda *a: 1,
133
133
'name': lambda x,y,z,c: x.pool.get('ir.sequence').get(y,z,'stock.automatic.supply') or '',
136
136
def default_get(self, cr, uid, fields, context=None):
138
138
Get the default values for the replenishment rule
140
140
res = super(stock_warehouse_automatic_supply, self).default_get(cr, uid, fields, context=context)
142
142
company_id = res.get('company_id')
143
143
warehouse_id = res.get('warehouse_id')
145
145
if not 'company_id' in res:
146
146
company_id = self.pool.get('res.company')._company_default_get(cr, uid, 'stock.warehouse.automatic.supply', context=context)
147
147
res.update({'company_id': company_id})
149
149
if not 'warehouse_id' in res:
150
150
warehouse_id = self.pool.get('stock.warehouse').search(cr, uid, [('company_id', '=', company_id)], context=context)[0]
151
151
res.update({'warehouse_id': warehouse_id})
153
153
if not 'location_id' in res:
154
154
location_id = self.pool.get('stock.warehouse').browse(cr, uid, warehouse_id, context=context).lot_stock_id.id
155
155
res.update({'location_id': location_id})
159
159
def choose_change_frequence(self, cr, uid, ids, context=None):
161
161
Open a wizard to define a frequency for the automatic supply
186
186
frequence_id = self.pool.get('stock.frequence').create(cr, uid, frequence_data, context=context)
187
187
self.write(cr, uid, proc.id, {'frequence_id': frequence_id}, context=context)
190
190
context.update({'active_id': res_id,
191
191
'active_model': 'stock.warehouse.automatic.supply',
192
192
'res_ok': res_ok})
194
194
return {'type': 'ir.actions.act_window',
196
196
'res_model': 'stock.frequence',
324
324
for product in self.pool.get('product.product').browse(cr, uid, product_ids, context=context):
325
325
# Check if the product is not already on the report
326
if product.type not in ('consu', 'service', 'service_recep') and product.id not in products:
326
if product.id not in products:
327
327
self.pool.get('stock.warehouse.automatic.supply.line').create(cr, uid, {'product_id': product.id,
328
328
'product_uom_id': product.uom_id.id,
329
329
'product_qty': 1.00,
345
345
_name = 'stock.warehouse.automatic.supply.line'
346
346
_description = 'Automatic Supply Line'
347
347
_rec_name = 'product_id'
350
350
'product_id': fields.many2one('product.product', string='Product', required=True),
351
351
'product_uom_id': fields.many2one('product.uom', string='Product UoM', required=True),
352
352
'product_qty': fields.float(digit=(16,2), string='Quantity to order', required=True),
353
353
'supply_id': fields.many2one('stock.warehouse.automatic.supply', string='Supply', ondelete='cascade', required=True)
357
357
'product_qty': lambda *a: 1.00,
360
def _check_product_qty(self, cr, uid, ids, context=None):
362
Check if the quantity is larger than 0.00
364
context = context is None and {} or context
366
if isinstance(ids, (int, long)):
369
if not context.get('noraise'):
370
for line in self.read(cr, uid, ids, ['product_qty'], context=context):
371
if line['product_qty'] <= 0.00:
372
raise osv.except_osv(_('Error'), _('Lines must have a quantity larger than 0.00'))
377
def create(self, cr, uid, vals, context=None):
378
res = super(stock_warehouse_automatic_supply_line, self).create(cr, uid, vals, context=context)
379
self._check_product_qty(cr, uid, res, context=context)
382
def write(self, cr, uid, ids, vals, context=None):
383
res = super(stock_warehouse_automatic_supply_line, self).write(cr, uid, ids, vals, context=context)
384
self._check_product_qty(cr, uid, ids, context=context)
361
('product_qty_check', 'CHECK( product_qty > 0 )', 'Product Qty must be greater than zero.'),
387
364
def _check_uniqueness(self, cr, uid, ids, context=None):
389
366
Check if the product is not already in the current rule
394
371
('supply_id', '=', line.supply_id.id)], context=context)
401
378
(_check_uniqueness, 'You cannot have two times the same product on the same automatic supply rule', ['product_id'])
404
def onchange_product_id(self, cr, uid, ids, product_id, uom_id, product_qty, context=None):
381
def onchange_product_id(self, cr, uid, ids, product_id, context=None):
405
382
""" Finds UoM for changed product.
406
383
@param product_id: Changed id of product.
407
384
@return: Dictionary of values.
412
387
prod = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
413
388
v = {'product_uom_id': prod.uom_id.id}
414
res.update({'value': v})
417
uom_id = res.get('value', {}).get('product_uom_id', uom_id)
418
res = self.pool.get('product.uom')._change_round_up_qty(cr, uid, uom_id, product_qty, 'product_qty', result=res)
422
def onchange_uom_qty(self, cr, uid, ids, uom_id, product_qty, context=None):
424
Check the round of qty according to UoM
429
res = self.pool.get('product.uom')._change_round_up_qty(cr, uid, uom_id, product_qty, 'product_qty', result=res)
433
392
stock_warehouse_automatic_supply_line()
435
394
class stock_frequence(osv.osv):
436
395
_name = 'stock.frequence'
437
396
_inherit = 'stock.frequence'
440
399
'auto_sup_ids': fields.one2many('stock.warehouse.automatic.supply', 'frequence_id', string='Auto. Sup.'),
443
402
def choose_frequency(self, cr, uid, ids, context=None):
445
404
Adds the support of automatic supply on choose frequency method
449
408
if context is None:
452
411
if not context.get('res_ok', False) and 'active_id' in context and 'active_model' in context and \
453
412
context.get('active_model') == 'stock.warehouse.automatic.supply':
454
413
self.pool.get('stock.warehouse.automatic.supply').write(cr, uid, [context.get('active_id')], {'frequence_id': ids[0]})
456
415
return super(stock_frequence, self).choose_frequency(cr, uid, ids, context=context)
458
417
def copy(self, cr, uid, id, default=None, context=None):