Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
2915 Vues

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

 

Avatar
Ignorer
Meilleure réponse

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')}.

 

 

Avatar
Ignorer
Auteur

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

Auteur

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

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.