Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd

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'],

}

Avatar
Annuleer
Beste antwoord

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>
 
Avatar
Annuleer
Auteur

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.

Auteur

By block I mean "".

Gerelateerde posts Antwoorden Weergaven Activiteit
2
aug. 16
11041
9
apr. 22
29055
1
jul. 16
6369
0
feb. 16
4738
1
jul. 15
6139