Skip to Content
Odoo Menu
  • Prijavi
  • 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
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

How to transfer data from sale order to invoice when clicking on 'Create Invoice'?

Naroči se

Get notified when there's activity on this post

This question has been flagged
wizardinvoicequotationact_windowodoo8.0
3 Odgovori
15830 Prikazi
Avatar
Yenthe Van Ginneken (Mainframe Monkey)

Hi guys,

I'm extending the sale and account module and added my custom fields in a custom module. I've added fields in both the sale.order.line model and the account.invoice.line model:

class custom_sale_order_line_fields(models.Model):
    _inherit = 'sale.order.line'
    hoogte = fields.Integer()
    breedte = fields.Integer()
    aantal = fields.Integer()
    #Checkboxes
    links = fields.Boolean()
    rechts = fields.Boolean()
    boven = fields.Boolean()
    onder = fields.Boolean()
    kleur = fields.Selection((('w','Wit'), ('z','Zwart'), ('g','Groen'),('r','Rood')))

class aa_invoice_custom_lines(models.Model):
    _inherit = 'account.invoice.line'
    hoogte = fields.Integer()
    breedte = fields.Integer()
    aantal = fields.Integer()
    #Checkboxes
    links = fields.Boolean()
    rechts = fields.Boolean()
    boven = fields.Boolean()
    onder = fields.Boolean()
    kleur = fields.Selection((('w','wit'), ('z','zwart'), ('g','groen'),('r','rood')))

The fields are added in both the view for a new sale order and the view for an invoice:

 <openerp>
    <data>
        <record id="sale.view_order_form_inherit" model="ir.ui.view">
            <field name="name">sale.order.form.inherit</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
 	    <field name="arch" type="xml">
	        <xpath expr="//tree[@string='Sales Order Lines']/field[@name='name']" position="after">
		    <field name="links"/>
		    <field name="rechts"/>
		    <field name="boven"/>
		    <field name="onder"/>
		    <field name="kleur"/>
                    <field name="hoogte" on_change="on_change_hoeveelheid_berekenen(hoogte,breedte,aantal)"/>
		    <field name="breedte" on_change="on_change_hoeveelheid_berekenen(hoogte,breedte,aantal)"/>
                    <field name="aantal" on_change="on_change_hoeveelheid_berekenen(hoogte,breedte,aantal)"/>
		</xpath>
	    </field>
        </record>

        <record id="account.invoice_form_inherit3" model="ir.ui.view">
            <field name="name">account.invoice.form.inherit3</field>
            <field name="model">account.invoice</field>
            <field name="inherit_id" ref="account.invoice_form"/>
 	    <field name="arch" type="xml">
	        <xpath expr="//tree[@string='Invoice Lines']/field[@name='name']" position="after">
		    <field name="links"/>
		    <field name="rechts"/>
		    <field name="boven"/>
		    <field name="onder"/>
		    <field name="kleur"/>
                    <field name="hoogte" on_change="on_change_hoeveelheid_factuur_berekenen(hoogte,breedte,aantal)"/>
		    <field name="breedte" on_change="on_change_hoeveelheid_factuur_berekenen(hoogte,breedte,aantal)"/>
                    <field name="aantal" on_change="on_change_hoeveelheid_factuur_berekenen(hoogte,breedte,aantal)"/>
		</xpath>
	    </field>
        </record>
    </data>
</openerp>

The next thing that I need is that when the user opens up a sales order and clicks on the button 'Create Invoice' that the filled in data from the sales order gets passed on to the invoice that is automatically generated.
The button 'Create Invoice' seems to come from /sale/wizard/sale_line_invoice.xml from this record:

 <record id="action_view_sale_order_line_make_invoice" model="ir.actions.act_window">
            <field name="name">Create Invoice</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">sale.order.line.make.invoice</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="view_id" ref="view_sale_order_line_make_invoice"/>
            <field name="target">new</field>
        </record>

What I don't understand now is where I should add the logic to transfer data from my custom fields from a sales order to an invoice. How do I know which code this action triggers and how should I transfer the data from the sale order to the invoice? It looks like the data is transferred in the method make_invoice (addons/sale/wizard/sale_line_invoice.py in the following lines:

 #TODO: merge with sale.py/make_invoice
        def make_invoice(order, lines):
            """
                 To make invoices.

                 @param order:
                 @param lines:

                 @return:

            """
            a = order.partner_id.property_account_receivable.id
            if order.partner_id and order.partner_id.property_payment_term.id:
                pay_term = order.partner_id.property_payment_term.id
            else:
                pay_term = False
            inv = {
                'name': order.client_order_ref or '',
                'origin': order.name,
                'type': 'out_invoice',
                'reference': "P%dSO%d" % (order.partner_id.id, order.id),
                'account_id': a,
                'partner_id': order.partner_invoice_id.id,
                'invoice_line': [(6, 0, lines)],
                'currency_id' : order.pricelist_id.currency_id.id,
                'comment': order.note,
                'payment_term': pay_term,
          
                'fiscal_position': order.fiscal_position.id or order.partner_id.property_account_position.id,
                'user_id': order.user_id and order.user_id.id or False,
                'company_id': order.company_id and order.company_id.id or False,
                'date_invoice': fields.date.today(),
            }
            inv_id = self.pool.get('account.invoice').create(cr, uid, inv)
            return inv_id
But how can I add my custom fields to be added on the invoice lines too?

Thanks,
Yenthe
1
Avatar
Opusti
Avatar
Peter Alabaster
Best Answer

I have done this before when adding lots to all sale, purchase, and invoice lines. I had to pipe the data across all these forms.

You have to do a certain amount of rooting around in the source code to find the right place to hook in, but for your situation this should work:

class sale_order_line_your_extension(osv.osv):
_inherit = "sale.order.line"

def _prepare_order_line_invoice_line(self, cr, uid, line, account_id=False, context=None):
    ret = super(sale_order_line_your_extension, self)._prepare_order_line_invoice_line(cr, uid, line, account_id=False, context=context)
    if line.product_id:
        if line.field_name:
            ret['field_name'] = line.field_name
    return ret

Note: super has been used here to reduce impact on source code.

All we are doing is assigning all the default returned values in the source code to the variable `ret`.

We are then checking if line.product_id exists on the sale order.

Then checking if anything has been set on your field, and then appending your field name (as defined in account.invoice.line) to ret, and assigning the value stored in the field to it.

Finally the appended value is returned, along with all other values.

This can be used in many places when piping data across forms, and can be quite a useful template.

You can easily add more than one value:

ret['field_name2'] = line.field_name2

ret['field_name3'] = line.field_name3

Hope this helps

6
Avatar
Opusti
Yenthe Van Ginneken (Mainframe Monkey)
Avtor

Thanks Peter! This is a really great answer which is also usuable for other cases. Upvoted & accepted, again thanks! :)

Avatar
Tintumon
Best Answer

 For creating "account.invoice" from "sale.order" there is four selection option

  • delivered

  • all

  • percentage

  • fixed

I tried a function "def action_invoice_create(self, grouped=False, final=False): " using super in inherited sale.order.

It works fine for sending a field value from sale.order to account.invoice, when the selection field is "delivered" or "all".

But it doesn't work for "percentage" and "fixed" selections.

So I used another function "def _create_invoice(self, order, so_line, amount):"  using super in inherited wizard/sale_make_invoice_advance.py

It propagated the field value from sale.order to account.invoice successfully.

I have tested it in debug also.

Does it right way to achieve? or any other way?

Note: I worked on ODOO9

0
Avatar
Opusti
Coralie Cardon

Hello ! I did exactely what you say :-) but i have a problem So, I have a rate in my sale order and i would like take it to multiply to the amount of my invoice. (I put it in a field) But the amount doesn't take the down payment

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

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Enlarge or change width of text in invoice/quotation reports Solved
invoice quotation
Avatar
Avatar
2
feb. 23
3425
Change invoice footer per country
invoice odoo8.0
Avatar
Avatar
Avatar
3
jul. 17
5196
How to make a new field and being integrated in 2 modules
invoice quotation
Avatar
Avatar
1
maj 16
4226
How can modify the N° or the source of document for the quotation Solved
invoice quotation
Avatar
Avatar
2
apr. 16
4999
How can I edit Sales Tax so that it doesn't show the rate, just the word "Tax"? Solved
invoice tax quotation
Avatar
Avatar
1
okt. 25
3739
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