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.

2

Add custom fields to sales order

By
Jhon Felipe Urrego Mejia
on 2/26/14, 3:57 AM 18,699 views

Hi, please give me instructions or share me a little documentation for add custom fields to sales order, tnks

2
Carlos
On 11/13/15, 8:52 PM

In odoo 9 (in you have you odoo server in other directory, just change the path to you odoo directory installation)

Create a new custom module:

cd /odoo/odoo-server <--Here inside is the odoo.py script to create a new custom module.

sudo ./odoo.py scaffold myfieldsinsaleorder /odoo/custom/addons <--This is my directory for my custom modules, this code create a new custom module

cd /odoo/custom/addons/myfieldsinsaleorder

Edit __openerp__.py and save this settings:

locate: 'depends': ['base'], and add 'sale' and 'product' like this:

'depends': ['base','sale','product'],

Edit models.py and save this settings: <-- here you can add your custom fields

from openerp import models, fields, api

class myfieldsinsaleorder(models.Model):

_inherit = 'sale.order'

mycustomfield1 = fields.Char('My custom field 1 Label', default = 'My custom field 1 default value')

Edit templates.xml and save this settings: <-- here you can add the custom field to sale order form and print to sale order quotation document

 <openerp>

<data>

<record id="my_view_saleorder_form_inherit" model="ir.ui.view">

<field name="name">my.view.saleorder.form.inherit</field>

<field name="model">sale.order</field>

<field name="inherit_id" ref="sale.view_order_form"/>

<field name="arch" type="xml">

<!-- Locate the position to add a new tab "My New Tab" in "Form View Sale Order"-->

<xpath expr="//page[1]" position="after">

<page string="My New Tab">

<group>

<!-- here we add our new field "mycustomfield1" inside our new tab -->

<field name="mycustomfield1"/>

</group>

</page>

</xpath>

</field>

</record>

<!-- This is to add our field in the quotation saler order and print -->

<template id="my_report_saleorder_document" inherit_id="sale.report_saleorder_document">

<xpath expr="//table[@class='table table-condensed']" position="after">

<strong>My label field for quotation sale order: </strong><span t-field="doc.mycustomfield1"/><br></br>

<!-- with this code we can add fields from other module (products) to sale order document and print -->

<strong>Field get it from product module: </strong><span t-field="doc.product_id.product_tmpl_id.warranty"/>

</xpath>

</template>

 </data>

</openerp>


2

Nehal

--Nehal--
2090
| 5 2 8
Ahmadabad, India
--Nehal--
Nehal
On 2/26/14, 5:11 AM

HI,

You can create custom field in Sale order by creating a module or from GUI.

From GUI, you can add the custom field using menu: Settings > Technical > Database Structure > Fields (Make sure the user has 'Technical Features' enabled in their access rights) To make them show up on the UI itself you will then need to add them to a view (Settings > Technical > User Interface > Views).

I need create with new module, i don't want after update lose everything

Jhon Felipe Urrego Mejia
on 2/26/14, 6:27 PM
0

I need create with new module, i don't want after update lose everything

You may refer the following link for developing custom module: http://www.pixelite.co.nz/article/adding-additional-fields-using-custom-module-openerp-7

Nehal
on 2/27/14, 12:20 AM
0
Bart Criel
On 2/27/14, 2:58 AM

Hi,

You need to create 2 files: a xml- and a py-file. The example below shows how to add a field 'MRSP' to the product form.

Content of the py-file

class product_product(osv.osv):
    _inherit = "product.product"

    _columns = {
                'mrsp': fields.float('MRSP', digits_compute=dp.get_precision('Product Price'),
                                    help="The Manufacturer Recommended Sales Price."),
    }

product_product()

Example content of the xml-file (this depends heavily on where and how you want to put the field, so I can't be more specific; use existing xml files as inspiration)

<record id="product_mrsp_form_view" model="ir.ui.view">
    <field name="name">product.normal.form</field>
    <field name="model">product.product</field>
    <field name="inherit_id" ref="product.product_normal_form_view"/>
    <field eval="7" name="priority"/>
    <field name="arch" type="xml">
               <field name="mrsp" attrs="{'invisible': [('sale_ok', '!=', True)]}"/>
    </field>
</record>

You of course need to add these files in __init__ and __openerp__

Bart

hI, how can i create other flange in sales order?

Jhon Felipe Urrego Mejia
on 3/5/14, 12:20 AM

What do you mean with "flange"?

Bart Criel
on 3/5/14, 4:19 PM

https://dl.dropboxusercontent.com/u/75366808/flange.png

Jhon Felipe Urrego Mejia
on 3/5/14, 6:52 PM

Hi please give me some support i need add 5 columns to sales order line, tnks

Jhon Felipe Urrego Mejia
on 3/19/14, 7:08 PM

This topic http://help.openerp.com/question/16336/how-i-can-create-module-openerp-7/ is full of interesting and relevant information. Use a simple existing module (e.g. sale_margin) as example or inspiration.

Bart Criel
on 3/27/14, 10:46 AM
0
Mayur Maheshwari
On 2/26/14, 7:33 AM

But .it's batter you add custom field in xml with use of view inheritance.

Jhon Felipe Urrego Mejia
on 2/26/14, 1:21 PM

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

2 follower(s)

Stats

Asked: 2/26/14, 3:57 AM
Seen: 18699 times
Last updated: 4/27/16, 10:27 PM