Odoo Help

Welcome!

This community 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.

0

Odoo7:Add a field in Purchase Order Line,but can't save

By
chen rong
on 9/3/14, 1:58 AM 560 views

Here is my code 

class purchase_order_line(orm.Model):
    _inherit = 'purchase.order.line'
    _columns = {'packaging': fields.selection(((1, 1), (2, 2)), string='Packaging')}

xml

        <record id="purchase_purchase_order_packaging_form" model="ir.ui.view">
            <field name="name">purchase.purchase.order.packaging.form</field>
            <field name="model">purchase.order</field>
            <field name="inherit_id" ref="purchase.purchase_order_form"/>
            <field name="arch" type="xml">
                <xpath expr="//field[@name='order_line']//field[@name='price_unit']" position="before">
                    <field name="packaging"/>
                </xpath>
            </field>                  
        </record>
        <record id="purchase_purchase_order_line_packaging_form" model="ir.ui.view">
            <field name="name">purchase.purchase.order.line.packaging.form</field>
            <field name="model">purchase.order.line</field>
            <field name="inherit_id" ref="purchase.purchase_order_line_form"/>
            <field name="arch" type="xml">
                <xpath expr="//field[@name='price_unit']" position="before">
                    <field name="packaging"/>
                </xpath>
            </field>                  
        </record>

I edit a line and select packaging 1,and save,in order line it was 1 too

but after I save , the value missed

 

1

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 9/3/14, 2:43 AM

I think it may have something to do with the fact that you use tuple instead of list.  Try changing your line to: _columns = {'packaging': fields.selection([(1, 1), (2, 2)], string='Packaging')}.

 

 

Yeah,it works..Many thanks,it save me many time

chen rong
on 9/3/14, 2:48 AM

Yeah,it works..Many thanks,it save me many time

chen rong
on 9/3/14, 2:48 AM

Also, it is more common to use strings instead of integers as the code and value. So, _columns = {'packaging': fields.selection([("1", "1"), ("2", "2")], string='Packaging')}. It will be stored as a charater varying field anyway in PostgreSQL.

Ivan
on 9/3/14, 3:24 AM

Your 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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/3/14, 1:58 AM
Seen: 560 times
Last updated: 3/16/15, 8:10 AM