Hi All,
Working with OpenERP V6 on windows. I have created a module that adds a field to the product form to indicate what type of label should go on each product. This label type is also to display on the sales order line tree&form and eventually on the delivery order stock move tree&form so that warehouse knows what label to print on the box. I am trying to create on_change function for the sales order line and delivery order so that when a product is selected the label type is displayed in its field, the same applies to the delivery form. The module loads and runs without product_id_change function in the xml code but the on_change function is required for this module to be useful. I get this error when I select product from sales order line. Please what am i doing wrongly? Thanks in advance. Any help is very much appreciated.
Error is: Traceback (most recent call last):
File "C:\Program Files (x86)\OpenERP 6.1-1\server.\openerp\osv\osv.py", line 121, in wrapper File "C:\Program Files (x86)\OpenERP 6.1-1\server.\openerp\osv\osv.py", line 176, in execute File "C:\Program Files (x86)\OpenERP 6.1-1\server.\openerp\osv\osv.py", line 164, in execute_cr TypeError: product_id_change() takes at most 19 arguments (20 given) 2013-09-02 12:38:53,305 1012 ERROR ? openerp.netsvc: product_id_change() takes at most 19 arguments (20 given)
python code:
from osv import fields,osv
class sale_order_line(osv.osv):
_name = 'sale.order.line'
_inherit = 'sale.order.line'
_columns = {
'order_line_label': fields.many2one('label.maker','Label',select=True, help='select the right label for the product and partner'),
}
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, order_line_label=False, flag=False, context=None):
context = context or {}
res = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty=qty,
uom=uom, qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id,
lang=lang, update_tax=update_tax, date_order=date_order, packaging=packaging, fiscal_position=fiscal_position, flag=flag, context=context)
product_obj = self.pool.get('product.product')
product_obj = product_obj.browse(cr, uid, product, context=context)
res['value'].update({'order_line_label': product_obj.labelnid or False})
return res
sale_order_line()
class sale_order(osv.osv):
_name = 'sale.order'
_inherit = 'sale.order'
def _prepare_order_line_move(self, cr, uid, order, line, picking_id, date_planned, context=None):
res = super(sale_order, self)._prepare_order_line_move(cr, uid, order=order, line=line, picking_id=picking_id, date_planned=date_planned, context=context)
res['order_line_label'] = line.labelnid
return res
sale_order()
xml is:
<openerp>
<data>
<record id="view_order_label_form_change" model="ir.ui.view">
<field name="name">sale.order.form.sale.label</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']/form/notebook/page[@string='Order Line']//field[@name='product_id']" position="replace">
<field name="product_id"
context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
groups="base.group_user"
on_change="product_id_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, True, parent.date_order, False, parent.fiscal_position, False, order_line_label, context)"/>
</xpath>
</field>
</record>
<record model="ir.ui.view" id="view_order_line_tree">
<field name="name">order.line.tree</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@string='Sales Order']/field[@name='order_line']/tree[@string='Sales Order Lines']/field[@name='product_uom_qty']" position="before">
<field name="order_line_label"/>
</xpath>
<xpath expr="//field[@name='order_line']/form/notebook/page[@string='Order Line']//field[@name='product_uom_qty' ]" position="before">
<field name="order_line_label" />
</xpath>
</field>
</record>
<!--
-->
<record model="ir.ui.view" id="view_product_product_form">
<field name="name">product.product.form</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="type">form</field>
<field name="arch" type="xml">
<field name="variants" position="before">
<field name="labelnid" />
</field>
</field>
</record>
</data>
</openerp>