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"?>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)
<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>
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'],
}