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.
Hello, I have Odoo 8 running over Win 7 x64.
I am developing a new module, I have created a class that inherit from product.template:
from openerp import fields, models
_inherit = 'product.template'
last_cost_price = fields.Float(digits=(8,2), string="Last cost price", readonly=True)
When the user confirms a PO, I want to read every line order and set the unit_price of this order_line in last_cost_price of the corresponding product.template.
Have I to override wkf_confirm_order() method of purchase_order class? In this case, how can I access to product.last_cost_price attribute to edit it?
Odoo has average product calculation method that will update the cost price when there is incoming shipment completed. But if you really want to fix the price by PO price, yes you have to inherit and override wkf_confirm_order of purchase.order. You need to loop through all ids (which is purchase.order model) that is passed to wkf_confirm_order, then within that loop through all it's order_line (which is purchase.order.line model) and then from the line you can access the product_id field (which will be product.product model). Then you can write to that product record.
Thanks for your reply John. So have I to inherit purchase.order class and override wkf_confirm_order method? Can you help me with some example python code to search the corresponding product and edit them? Thanks!
I have overrided the method, but I get an error when confirm the PO:
ValueError: "can't adapt type 'product.product'" while evaluating u'wkf_confirm_order()'
in the line marked with bold.
_inherit = 'purchase.order'
def wkf_confirm_order(self, cr, uid, ids, context=None):
for po in self.browse(cr, uid, ids, context=context):
for line in po.order_line:
product_tmpl_id = self.pool.get('product.product').browse(cr, uid, line.product_id, context).product_tmpl_id
product_tmpl = self.pool.get('product.template').browse(cr, uid, product_tmpl_id, context)
#... write the last_price_cost in the product.template object
return super(purchase_order, self).wkf_confirm_order(cr, uid, ids, context)
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: 12/1/14, 3:58 PM|
|Seen: 2614 times|
|Last updated: 3/16/15, 8:10 AM|