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.
Guys, I'm a newbie, still learning and quiet often I have a dilemma how should I do this or that :)
So if would you like to explain and enlighten it a bit for me please.
cr.execute("""SELECT sum(qty) from stock_quant where location_id = %s""" % obj.id)
tot_qty = cr.fetchall()
how to do the same using old API ?
self.pool.get(stock.quant)..search(cr, uid, [('usage', '=', 'production')], context=context)
like that ?
and how should it look like in new API ?
self.env['stock.quant'].search([('usage', '=', 'production')])
or more generic:
self.env['model.name'].search([('variable', 'operator', 'value')])
at search you can also limit the recordsets:
self.env['model.name'].search([('variable', 'operator', 'value')], limit=1)
self.env['model.name'].search([('variable', 'operator', 'value')]).name
and much more.
is new api. If you're using odoo8 or 9 I'd stick with the new API style.
On a side note: If you want to add or modify records and you've got computed fields, stay away from using queries as computed fields will not be calculated using raw queries.
Further reading: http://odoo-new-api-guide-line.readthedocs.org/en/latest/environment.html
edit: improved answer
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: 2/8/16, 7:01 AM|
|Seen: 617 times|
|Last updated: 2/8/16, 9:17 AM|