I'm currently making a module for a pharmaceutical company.
When one of the representitives gives out samples to the doctors they have to register it in openerp. Every doctor only gets 8 samples of any product a year. so when they add a sample to openerp they need to supply a product, quantity and parent_id, date is automatic today.
i can get the information from the current form and add it to the raise osv.except_osv event. but it only outputs the data of the form no sum of all the quantity's. so it seems that the function doesn't go into the loop.
here is my code
samples.py
def on_change_quantity(self, cr, uid, ids, quantity, parent ,product , context=None):
if parent:
currentYear = datetime.now().year
totaal=quantity
for item in self.browse(cr, uid, ids):
if parent==item.parent_id:
if currentYear==item.year:
if product==item.product_id:
totaal=sum([rec.quantity for rec in self.browse(cr, uid, ids)])
raise osv.except_osv(('fout'), (totaal) )
samples.xml
<field name="quantity" on_change="on_change_quantity(quantity,parent_id,product_id)"/>