Odoo Help

0

Adding a field to a form (field defined in sale.order.line, field to be added into sale.order.form)

By
E.M.
on 7/22/15, 2:15 AM 851 views

I am trying to add a field to sale.order.form.

Specifically, I am trying to add x_sale_margin field to sale.order.lines so there is information on the sale margin for every sales order line. I have managed to complete the task by modifying everything in the GUI but now I am trying to get it working via module.

 I have tried this:

sale_margin_lines.py

# -*- coding: utf-8 -*-
from openerp import models, fields, api
class SaleMarginLines(models.Model):
_inherit = 'sale.order.line',
x_sale_margin = fields.Float('Margen de Ventas (%)', (4, 2))


sale_margin_lines.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<record model="ir.ui.view" id="sale_margin_lines_sale_order">
<field name="name">sale.order.margin.lines.view.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//group[@name='sale_total']" position="after">
<group name="sale_margin_grp">
<field name="x_sale_margin" groups="base.group_user"/>
</group>
</xpath>
</field>
</record>

<record model="ir.ui.view" id="sale_margin_lines_sale_order_line">
<field name="name">sale.order.line.margin.lines.view.form</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='order_line']/form//field[@name='price_unit']" position="after">
<field name="x_sale_margin" groups="base.group_user"/>
</xpath>
</field>
</record>

<record model="ir.ui.view" id="sale_margin_lines_sale_order_line_form">
<field name="name">sale.order.line.tree.margin.view.form</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='order_line']/tree//field[@name='price_unit']" position="after">
<field name="x_sale_margin" groups="base.group_user"/>
</xpath>
</field>
</record>
</data>
</openerp>
But I got an error that states that "x_sale_margin" field is not defined. I wonder why If it is actually being defined by the module (and without the XML the field can be seen in configuration -> database -> models)

Thanks,

P.D.

I also include the __init__.py and __openerp__.py files in case it helps to reproduce or to other people learning how to write modules.


__init__.py

 from . import sale_margin_lines


__openerp__.py

 {

'name': 'Sales Margin in Sales Orders',

'description': 'Provides sales margin information in Sales Orders, both line by line and in total order',

'author': 'E.M.',

'depends': ['sale','sale_margin'],

'data': ['sale_margin_lines.xml'],

}

4
Solanki Shamji
On 7/22/15, 2:48 AM

Hello, In this code you try to put field in sale.order object because sale_total is out of sale.order.line view.

If you inherit sale.order.line than you can put field in sale.order.line view only. In sale order form view there is inner view of sale.order.line so put field in only sale.order.line inner view.

May be this will help you.

 <xpath expr="//group[@name='sale_total']" position="after">
    <group name="sale_margin_grp">
    <field name="x_sale_margin" groups="base.group_user"/>
</group>
</xpath>
 

Thanks, I used sale_margin module as template and it uses sale_total which effectively I understood is outside sale_order_line. Instead your solution I removed the firstof the three blocks I used and it works. That was what I was actually looking for.

E.M.
on 7/22/15, 3:41 PM

By block I mean "".

E.M.
on 7/22/15, 3:42 PM

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 7/22/15, 2:15 AM
Seen: 851 times
Last updated: 7/22/15, 3:39 PM