This question has been flagged
3 Replies
18897 Views

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>
Avatar
Discard
Best Answer

you can not add the order_line_label as a new argument just rename

def product_id_change_new(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


<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_new(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>
Avatar
Discard

i read you add "order_line_label" this is not possible to change the count of argument, define a new method name is the correct solution

Author

Thanks for your help now am getting a new error. ProgrammingError: column res_partner.email does not exist LINE 1: ...mer",res_partner."name",res_partner."debit_limit",res_partne... ^

2013-09-02 15:00:11,421 2596 ERROR ? openerp.netsvc: column res_partner.email does not exist LINE 1: ...mer",res_partner."name",res_partner."debit_limit",res_partne...

can you mark my anwser as correct, it is the check on the left side on the top of my anwser

For the new problem i can not help you it is not in the code you add here, and this is a new question, but here should be general question and not every little bug.

Best Answer

1 more arguement you have to give in that method product_id_change(). You have to find out which 1 is missing. Because that error represents that , that method accepts atmost 20 arguements, but you have given 19 arguements. Thank you.

Avatar
Discard
Author

Thanks for responding. But I think you might have got it wrong because the error says I have 20 arguments where there should be 19 (not the other way round). I would expect to use 20 considering I added "order_line_label".

Match your number of arguements, and please verify whether there is any change or not.

Author

It makes no difference.The error only goes away if I remove the "order_line_label" in the xml of the on_change function.

Author Best Answer

Solved all the problems and now it works fine. Find the code below. You can always add to the code to suit all your needs. __init__.py

import label_make

__openerp__.py

{
    "name" : "labelmake",
    "version" : "0.1",
    "author" : "Tiny",
    "website" : "http://openerp.com",
    "category" : "Unknown",
    "description": """  """,
    "depends" : ['base','sale','stock','product'],
    "init_xml" : [ ],
    "demo_xml" : [ ],
    "update_xml" : ['label_make_view.xml',],
    "installable": True,
    "application": True,
    "active": False,
    "auto_install": False,}

The module .py is:

     class label_maker(osv.osv):
_name = 'label.maker'
_columns = {
    'name': fields.char('Label Name',size=200,required=True, help='This is the name of the label'),
    'label_owner': fields.char('Company Name',size=200,select=True, help='selects the product on the order line'),
}
    label_maker()

    class product_product(osv.osv):
_name = 'product.product'
_inherit = 'product.product'
_columns = {
    'order_line_label': fields.many2one('label.maker','Label',select=True, help='label name'),
}
    product_product()

    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, flag=False, order_line_label=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)
    if product:
        product_obj = self.pool.get('product.product').browse(cr, uid, product, context=context)


        res['value'].update({'order_line_label': product_obj.order_line_label.id 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.order_line_label.id
    return res
    sale_order()

    class order_line_picking_list(osv.osv):
_name = 'order.line.picking.list'
_inherit = 'stock.picking'
_columns = {
    'order_line_label': fields.many2one('label.maker','Label',select=True, help='label for the product on the picking list'),

}
    order_line_picking_list()

    class stock_move(osv.osv): 
_name = 'stock.move'
_inherit = 'stock.move'

def onchange_product_id(self, cr, uid, ids, prod_id=False, loc_id=False,
                        loc_dest_id=False, partner_id=False):
    res_prod = super(stock_move, self).onchange_product_id(cr, uid, ids, prod_id, loc_id,loc_dest_id, partner_id)
    prod_obj = self.pool.get('product.product')
    obj = prod_obj.browse(cr, uid, prod_id)
    res_prod['value'].update({'order_line_label': obj.order_line_label.id})
    return res_prod
_columns = {
    'order_line_label': fields.many2one('label.maker','Label',select=True, help='label for the product on the picking list'),
}
    stock_move()

module _view.xml is:

<openerp> <data>

    <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="order_line_label" />
            </field>
        </field>
    </record>

    <record model='ir.ui.view' id='stock_move_form_view'>
        <field name='name'>Stock Move Form Inherit</field>
        <field name='model'>stock.move</field>
        <field name='inherit_id' ref='stock.view_move_form'/>
        <field name='arch' type='xml'>
            <data>
                <field name="product_qty" position="after">
                    <field name="order_line_label"/>
                </field>
            </data>                
        </field>
    </record>

    <record id="view_stock_move_7" model="ir.ui.view">
        <field name="name">stock.move.tree.inherit7</field>
        <field name="model">stock.move</field>
        <field name="inherit_id" ref="stock.view_move_tree"/>
        <field name="arch" type="xml">
            <data>
                <field name="product_qty" position="after">
                    <field name="order_line_label"/>
                </field>
            </data>
        </field>
    </record>

    <record model="ir.ui.view" id="view_order_line_picking_list_tree">
        <field name="name">order.line.picking.list.form.in</field>
        <field name="model">stock.picking</field>
        <field name="view_type">form</field>
        <field name="inherit_id" ref="stock.view_picking_in_form"/>
        <field name="arch" type="xml">
            <data>
                <field name="product_qty" position="before">
                    <field name="order_line_label"/>
                </field>
                <xpath expr="/form/notebook/page/field[@name='move_lines']/form/field[@name='state']" position="before">
                   <field name="order_line_label"/>
                </xpath>
            </data>
        </field>
    </record>

    <record id="view_move_form_inherit" model="ir.ui.view">
        <field name="name">stock.move.form.out</field>
        <field name="model">stock.picking</field>
        <field name="view_type">form</field>
        <field name="inherit_id" ref="stock.view_picking_out_form"/>
        <field name="arch" type="xml">
            <data>
                <field name="product_qty" position="before">
                    <field name="order_line_label"/>
                </field>
                <xpath expr="/form/notebook/page/field[@name='move_lines']/form/field[@name='state']" position="before">
                   <field name="order_line_label"/>
                </xpath>
            </data> 
        </field>
    </record>     

    <record model="ir.ui.view" id="view_order_line_labels_list_form">
        <field name="name">order.line.labels.list.form</field>
        <field name="model">stock.picking</field>
        <field name="inherit_id" ref="stock.view_picking_form"/>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <data>
                <xpath expr="//tree/field[@name='product_qty' ]" position="before">
                    <field name="order_line_label" />
                </xpath>
                <xpath expr="/form/notebook/page/field[@name='move_lines']/form/field[@name='state']" position="before">
                   <field name="order_line_label"/>
                </xpath>
            </data>
        </field>
    </record>

    <record model="ir.ui.view" id="view_label_maker_form">
        <field name="name">label.maker.form</field>
        <field name="model">label.maker</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="label.maker" position= "inside">
                <field name="name" select="1"/>
                <field name="label_owner" select="2"/>
            </form>
        </field>
    </record>
    <record model="ir.ui.view" id="view_label_maker_tree">
        <field name="name">label.maker.tree</field>
        <field name="model">label.maker</field>
        <field name="type">tree</field>
        <field name="arch" type="xml">
            <tree string="label.maker" position="inside">
                <field name="name"/>
                <field name="label_owner"/>
            </tree>
        </field>
    </record>
    <record model="ir.actions.act_window" id="action_label_maker">
        <field name="name">Labels</field>
        <field name="res_model">label.maker</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
    </record>
    <menuitem name="Warehouse/Configuration/Paragon/Labels" id="menu_label_maker" action="action_label_maker"/>

</data>
</openerp>
Avatar
Discard