Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • 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 Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & 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
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Odoo 10: show field of model “sale.order” in form view of “account.invoice”

Subscribe

Get notified when there's activity on this post

This question has been flagged
fieldqwebrelations
2 Replies
11137 Views
Avatar
Saitam

I usually create a new Field by using the Debugging Mode and then clicking "Edit FormView" when I am on the appropriate form and writing into the code something like:

<field name="x_delivery_date"/>. 

Also I can show it afterwards on the printed report like this:

<div name="x_delivery_date" t-if="doc.x_delivery_date">    
<strong>Delivery Date:</strong>   
 <p t-field="doc.x_delivery_date"/>
</div>

But how do I display a field (commitment_date), which is available in the model (sale.order) in another models formview (account.invoice)? I guess that I have to use object relations or related field, but I don't know how. I hope somebody can help me. Many thanks in advance.

0
Avatar
Discard
Avatar
Art
Best Answer

@Saitam

Try this, it works! I created 'commitment_date' field in 'sale.order' and added it to 'account.invoice':

class AddCommitmentDate(models.Model):
    _inherit = 'sale.order'
    commitment_date = fields.Date('Commitment Date')

class AddToAccountInvoice(models.Model):
    _inherit = 'account.invoice'
    sale_order_id = fields.Many2one('sale.order', 'Orders')
    commitment_date = fields.Date(related='sale_order_id.commitment_date')
<record id="test_commitment_field_id" model="ir.ui.view">        
    <field name="name">Add commitment field</field>
    <field name="model">account.invoice</field>
    <field name="inherit_id" ref="account.invoice_form"/>
    <field name="arch" type="xml">
        <field name="date_invoice" position="after">
            <field name="commitment_date"/>
        </field>
    </field>
</record>


 

0
Avatar
Discard
Avatar
Saitam
Author Best Answer

@ Art

It doesn't work like this. There is no connection between sale order and account invoice. If I add the following line to account_invoice.py I get a 500 Internal Server Error:
`commitment_date = fields.Date(related='sale_order.commitment_date')`

I am writing this as an answer and not as a comment, because I am new to this forum and I only can comment with 8 carma points but have only gotten 7 carma points with the registration here (which makes absolutely no sense!) .


This my model:

class AccountInvoice(models.Model):
    _name = "account.invoice"
    _inherit = ['mail.thread']       
    _description = "Invoice"       
    _order = "date_invoice desc, number desc, id desc"        
    
    commitment_date = fields.Date(related='sale_order.commitment_date')    
    
    ...

And here is my view code, but the Odoo server doesn't start after the modificated model, so I don't even know if the view code would work or not:

<div name="commitment_date" class="col-xs-3">                    
<strong>Date:</strong>                   
<p t-field="o.sale_order.commitment_date"/>               
</div>


0
Avatar
Discard
Art

show us your model and view code.

Art

I cant' get it working yet... trying to understand how related fields work.

Art

So here is a short info from a odoo blogger about related fields: "We have to give/add Many2one(sale.order) field in account.invoice object. We can fill up new Many2one(sale.order) field id when invoice create from Sale order or Delivery order based on our Invoice control policy or Product setups. Afterwards you can declare your new field with related like Many2one(sale.order).validity_date. If you don't want to go with related field then we can override few existing method and fill up Expiration date in account.invoice object."

=======

So I tried to add an existing field (validity_date) from sale.order to account.invoice like this:

class AddToAccountInvoice(models.Model):

_inherit = 'account.invoice'

date_id = fields.Many2one('sale.order', 'My Date')

validity_date = fields.Date(related='date_id.validity_date')

but I get "AssertionError: Document does not comply with schema." So looks like Many2one field needs to be created to deal with this issue, just need to figure out the right way.

Art

Ok, I'm stupid. I was getting this AssertionError because I didn't have <odoo> and <data> tags in my xml view.

I have edited my answer. Hope it'll help you.

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

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

Sign up
Related Posts Replies Views Activity
How to overwrite field string name?
field qweb js
Avatar
Avatar
1
Sep 19
6839
How to overwrite field name?
field qweb js backbone.js
Avatar
0
Sep 19
7
How to define a read only field
field qweb readonly odooV8
Avatar
Avatar
Avatar
5
Feb 16
9748
Odoo 18: Display image from char field containing url in qweb form
qweb
Avatar
Avatar
1
Jul 25
3010
PDF Export Option for QWeb Reports in odoo 17.0
qweb
Avatar
Avatar
1
May 25
3811
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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