Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
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
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) )
<field name="quantity" on_change="on_change_quantity(quantity,parent_id,product_id)"/>
If you try to count the amount of the same product for one doctor in one year, change
totaal=sum([rec.quantity for rec in self.browse(cr, uid, ids)])
totaal += 1
Or instead of the nested ifs use the search method:
def on_change_quantity(self, cr, uid, ids, quantity, parent ,product , context=None): if parent: currentYear = datetime.now().year totaal=quantity rec_ids = self.search(cr, uid, [('id','!=',ids), ('parent_id','=',parent), ('year','=',currentYear), ('product_id','=',product)]); total += sum([rec.quantity for rec in self.browse(cr, uid, rec_ids, context=context)])
Hope that helps somehow.
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
About This Community
This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 3/27/14, 7:43 AM|
|Seen: 1106 times|
|Last updated: 3/16/15, 8:10 AM|