Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
2903 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Autor

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

Autor

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.