On Mon, Jul 15, 2013 at 6:19 PM, Cédric Krier <[email protected]> wrote:
> On 15/07/13 10:25 +0300, Giedrius Slavinskas wrote: > > 2013/7/15 Guillem Barba Domingo <[email protected]> > > > > > > > > El 15/07/2013 2:16, "Oscar Alvarez" <[email protected]> > va > > > escriure: > > > > > > > > > > > El 14/07/13 17:20, Cédric Krier escribió: > > > > > > > >> Hi, > > > >> > > > >> I would like to submit this poll for this change: > > > >> > > > >> http://codereview.tryton.org/969002/#msg9 > > > >> > > > >> > > > >> kg.convert(1000, gr) == 1 > > > > > > > The above one is more logical and more object-oriented approach as you > > provide the quantity (units and units of measurement) to the method > convert. > > > > It would be even more logical if we would have quantity as object and we > > could pass it as a single argument: > > > > class Quantity: > > def __init__(self, units, uom): > > self.units = units > > self.uom = uom > > > > Unfortunatily, there is no such a infrastructure on tryton's orm, so the > > best we can do is to pass the quantity by two arguments. > > So let's introduce it. > > > class Measure(namedtuple('Measure', ['quantity', 'unit'])): > __slots__ = () > > def convert_to(self, uom, round=True): > Uom = Pool().get('product.uom') > return Measure(Uom.compute_qty(self.unit, self.quantity, uom, > round=round), uom) > > > Which will make: > > Measure(1000, gr).convert_to(kg) == Measure(1, kg) Nice, perhaps we could implement other magic methods in Measure class making comparisons and operators also work ? More like the python package Udo mentioned. Thanks & Regards -- -- Sharoon Thomas Openlabs Technologies & Consulting (P) Limited w: http://www.openlabs.co.in m: +1 813.793.6736 (OPEN) Extn. 200 t: @sharoonthomas - We CARE for our customers
