如果在数量上如何使用,如果数量< = 0则会被警告"缺货"。
from openerp.osv import fields,osv import time from datetime import datetime,timedeltaclass hd_product(osv.osv):
_name="hd.product" _description="Data of Products" def _auto_qty(self, cr, uid, ids, qty, arg, context=None): records = self.browse(cr, uid, ids, context=context) result = {} for product in self.browse(cr, uid, ids, context=context): qty=0 qty = product.income-product.outcome result[product.id] = qty return result def _auto_income(self, cr, uid, ids, income, arg, context=None): result = {} for product in self.browse(cr, uid, ids, context=context): income = 0 for buy in product.buy_line_ids: income += buy.qty result[product.id] = income return result def _auto_outcome(self, cr, uid, ids, outcome, arg, context=None): result = {} for product in self.browse(cr, uid, ids, context=context): outcome = 0 for sale in product.sale_line_ids: outcome += sale.qty result[product.id] = outcome return result _columns={ 'name':fields.char('Product', size=30), 'price':fields.float('Price', size=64), 'qty':fields.function(_auto_qty, type='integer',method='true', string='Quantity'), 'income':fields.function(_auto_income, type='integer', method='true', string='Income'), 'outcome':fields.function(_auto_outcome, type='integer', method='true', string='Outcome'), 'sale_line_ids':fields.one2many('hd.sale.line', 'product_id', 'Name'), 'buy_line_ids':fields.one2many('hd.buy.line', 'product_id', 'Name'), }