351
352
# numbering value
352
353
start_num = start_num+1
353
354
if item_data[i][seq_field] != start_num:
354
dest_obj.write(cr, uid, [item_data[i]['id']], {seq_field: start_num}, context=context)
355
cr.execute("update "+dest_obj._table+" set "+seq_field+"=%s where id=%s", (start_num, item_data[i]['id']))
356
#dest_obj.write(cr, uid, [item_data[i]['id']], {seq_field: start_num}, context=context)
356
358
# reset sequence to start_num + 1 all time, checking if needed would take much time
357
359
# get the sequence id
508
class uom_tools(osv.osv_memory):
510
This osv_memory class helps to check certain consistency related to the UOM.
514
def check_uom(self, cr, uid, product_id, uom_id, context=None):
516
Check the consistency between the category of the UOM of a product and the category of a UOM.
517
Return a boolean value (if false, it will raise an error).
518
:param cr: database cursor
519
:param product_id: takes the id of a product
520
:param product_id: takes the id of a uom
521
Note that this method is not consistent with the onchange method that returns a dictionary.
525
if product_id and uom_id:
526
if isinstance(product_id, (int, long)):
527
product_id = [product_id]
528
if isinstance(uom_id, (int, long)):
533
FROM product_uom AS uom,
534
product_template AS pt,
535
product_product AS pp,
537
WHERE uom.id = pt.uom_id
538
AND pt.id = pp.product_tmpl_id
540
AND uom2.category_id = uom.category_id
542
(product_id[0], uom_id[0]))
543
count = cr.fetchall()[0][0]
550
class product_uom(osv.osv):
551
_inherit = 'product.uom'
553
def _compute_round_up_qty(self, cr, uid, uom_id, qty, context=None):
555
Round up the qty according to the UoM
557
uom = self.browse(cr, uid, uom_id, context=context)
558
rounding_value = Decimal(str(uom.rounding).rstrip('0'))
560
return float(Decimal(str(qty)).quantize(rounding_value, rounding=ROUND_UP))
562
def _change_round_up_qty(self, cr, uid, uom_id, qty, fields=[], result=None, context=None):
564
Returns the error message and the rounded value
567
result = {'value': {}, 'warning': {}}
569
if isinstance(fields, str):
572
message = {'title': _('Bad rounding'),
573
'message': _('The quantity entered is not valid according to the rounding value of the UoM. The product quantity has been rounded to the highest good value.')}
576
new_qty = self._compute_round_up_qty(cr, uid, uom_id, qty, context=context)
579
result.setdefault('value', {}).update({f: new_qty})
580
result.setdefault('warning', {}).update(message)