Odoo Help


How to define onchange method ? odooV8

Ajeng Shilvie
on 12/11/14, 11:37 PM 1,394 views

How can i make it ?

i make a custome module , the fields are :

many2one invoice_id(refer to customer invoice number), 

many2one order_line (refer to account.invoice.line, the invoice number same as selected invoice_id)

many2one customer_id(refer to partner_id in customer invoice that has the same number as selected item in invoice_id field),and

address field(refer to customer's address in selected invoice_id too)

here's the code :

class faktur(osv.osv):
    _name = 'permohonan.faktur'
    _columns = {

        ''invoice_id': fields.many2one('account.invoice',string='Invoice',domain=[('state','=','paid'),('type','=','out_invoice')],required=True),

        'order_line': fields.many2one('account.invoice.line', string='Order Line', required=True),
        'customer_id': fields.many2one('res.partner', string='Customer',required=True),
        'address': fields.char('Address',23),

here is xml code :

record model="ir.ui.view" id="permohonan_faktur_form_view">
    <field name="name">permohonan.faktur.form</field>
    <field name="model">permohonan.faktur</field>
    <field name="arch" type="xml">
        <form string="Form Permohonan Faktur STNK" version="7.0">
        <group col="2" string="Permohonan Faktur STNK">
            <group >
                <field name="invoice_id" context="{'form_view_ref':'account.invoice_form'}"/>
                <field name="order_line" />
                <field name="customer_id"/>
                <field name="address"/>

i want address and customer_id field onchange when i select invoice_id , i want order_line value defend on selected invoice number..


Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.


Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 


We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :


  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 12/12/14, 12:15 AM


You can try the following for onchange method in odoov8

To use the following way.. you need import the following and inherit it

from openerp import models,fields,api

class faktur (models.Model)

def onchange_invoice_id(self):
    if self.invoice_id:
    """Your code goes here"""
    self.customer_id = <some partner id based on your code>
    self.address= <some address id based on your code>

Note: I don't understand why are you using "many2one" for "order_line", because there could be more than one invoice line against an invoice.

But in case you want to load only those invoice line based on the selected invoice_id than you can apply the following domain in your view:

<field name="order_line" domain="[('invoice_id','=',invoice_id)]" />

Ajeng Shilvie
On 12/12/14, 1:08 AM


the domain for "order_line" it worked, thank you.

but i am sorry, i am new in odoo.. i don't understand using @api, do i have to use class faktur (models.Model) instead class faktur(osv.osv) ??


About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 12/11/14, 11:37 PM
Seen: 1394 times
Last updated: 3/16/15, 8:10 AM