On 15/07/13 19:34 +0530, Sharoon Thomas wrote: > On Mon, Jul 15, 2013 at 6:19 PM, Cédric Krier <cedric.kr...@b2ck.com> wrote: > > > On 15/07/13 10:25 +0300, Giedrius Slavinskas wrote: > > 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.
But what will be the result of: Measure(10, gr) + Measure(1, kg) Or we must restrict operators to measures with the same unit. -- Cédric Krier B2CK SPRL Rue de Rotterdam, 4 4000 Liège Belgium Tel: +32 472 54 46 59 Email/Jabber: cedric.kr...@b2ck.com Website: http://www.b2ck.com/
pgpp2eN1DOvKi.pgp
Description: PGP signature