From 6ffb9684bcedb6bc4b51748279cec8bc41211f02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 31 Oct 2008 14:14:36 +0100 Subject: [PATCH] Add quantity and forecast_quantity on product.template --- product.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/product.py b/product.py index e0175984ad..e6e8280cc4 100644 --- a/product.py +++ b/product.py @@ -1,9 +1,30 @@ -#This file is part of Tryton. The COPYRIGHT file at the top level -#of this repository contains the full copyright notices and license terms. +#This file is part of Tryton. The COPYRIGHT file at the top level of +#this repository contains the full copyright notices and license terms. from trytond.osv import fields, OSV from trytond.wizard import Wizard, WizardOSV import datetime + +class Template(OSV): + _name = "product.template" + + quantity = fields.Function('get_quantity', type='float', string='Quantity') + forecast_quantity = fields.Function('get_quantity', type='float', + string='Forecast Quantity') + + def get_quantity(self, cursor, user, ids, name, args, context=None): + res = {} + if name not in ('quantity', 'forecast_quantity'): + raise Exception('Bad argument') + + for template in self.browse(cursor, user, ids, context=context): + res[template.id] = 0.0 + for product in template.products: + res[template.id] += product[name] + return res + +Template() + class Product(OSV): "Product" _name = "product.product"