Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

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

Odoberať

Get notified when there's activity on this post

This question has been flagged
pythonfieldssale.order.linesale.order.formodooV8
2 Replies
6077 Zobrazenia
Avatar
E.M.

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

}

0
Avatar
Zrušiť
Avatar
Solanki Shamji
Best Answer

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>
 
4
Avatar
Zrušiť
E.M.
Autor

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

By block I mean "".

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrácia
Related Posts Replies Zobrazenia Aktivita
Add a new field to sale.order.lines and display it in the form Solved
python sale.order.line sale.order.form sale.order odooV8
Avatar
Avatar
Avatar
2
aug 16
12148
retrieving fields.Selection values, how??? Solved
python fields selection odooV8
Avatar
Avatar
Avatar
Avatar
Avatar
9
apr 22
30442
Select lines in sale.order.line
selection sale.order.line sale.order.form odooV8
Avatar
Avatar
1
júl 16
7059
purchase_price in sale.order.line, you can see it in database as column but not in sale.py sale_order_line class definition, why?
sale.order.line sale.order.form odooV8 purchases_price
Avatar
0
feb 16
5609
Adding a field to sale.order.line: which dependence should be specified in __openerp__.py?
modules python sale.order.line odooV8
Avatar
Avatar
1
júl 15
7069
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now