1
votes

Iam new in Odoo-9.0c, I have tried to create a custom module, that includes some fields, and for new purpose I want to add 1 more fileds.Char to that module. this is the code of new field.

    @api.multi
    def _get_show_name(self):
        for order_line in self:
            if order_line.product_id: 
                if oder_line.width_id:
                    if order_line.width_id.id == ids in range(12):
                        order_line.show_name = '%d - %d' % (order_line.product_id.id(name), order_line.widt$
                    else:
                        order_line.show_name = '%d' % (order_line.product_id.id(name))

show_name = fields.Char(compute=get_show_name, string='new name')

width_id is a many2one field that has been created in my custom module.

Please give me a hand to check the above code and show me how can I add this field to sale.xml. Thanks for your time.

1

1 Answers

1
votes

There is mistake on following line. ids variable not declared.

if order_line.width_id.id == ids in range(12):

You can try with following code to add field in sale.xml view file

<record model="ir.ui.view" id="view_sale_order_extend_form">
    <field name="name">view.sale.order.extend.form</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">

        <!-- Add show_name field in Sale order line tree view-->
        <xpath expr="//field[@name='order_line']/tree//field[@name='product_id']" position="after">
            <field name="show_name"/>
        </xpath>

        <!-- Add show_name field in Sale order line form view-->
        <xpath expr="//field[@name='order_line']/form//field[@name='product_id']" position="after">
            <field name="show_name"/>
        </xpath>

    </field>
</record>