This question has been flagged
7 Replies
64497 Views

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

Avatar
Discard

Hi All,

   I want to add custom field named "Test" into BoM & Structure report also, please help to share

   The "Test" field was inputed line by line with bom line

Thanks,

Best Answer

In Odoo 10,

Python file
from odoo import models, fields

class SaleOrderInherited(models.Model):
_inherit = 'sale.order'

custom_field = fields.Char(string='Custom Field')
Xml file
<!--Inherit the sale order form view--> 
<record id="view_sale_order_custom" model="ir.ui.view">
<field name="name">sale.order.custom.form.inherited</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="after">
<field name="custom_field"/>
  </xpath>
</field>
</record>
Watch this on YouTube : Additional field to existing view in odoo 10

All the best !

Avatar
Discard
Best Answer

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>


Avatar
Discard
Best Answer

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

Avatar
Discard
Author

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

Best Answer

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

Avatar
Discard
Author

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

What do you mean with "flange"?

Author

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

Author

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

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.

Best Answer

It is Better If You Use Odoo Studio for Customisation. 

Avatar
Discard
Author Best Answer

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

Avatar
Discard

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

Best Answer

Hi ,

tutorial link : http://maheshwarimayur.blogspot.in/2013/02/how-to-add-new-field-on-any-object-in.html

Hope it helps you more !

Avatar
Discard
Author

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