Odoo Help

1

How to define onchange method ? odooV8

By
Ajeng Shilvie
on 12/11/14, 11:37 PM 1,260 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"/>
              </group>
           </group>
        </form>
    </field>
</record>

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

1

@Ajeng

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)

@api.onchange('invoice_id')
def onchange_invoice_id(self):
    if self.invoice_id:
    """Your code goes here"""
    """finally"""
    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)]" />

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

@Emipro

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.

Register

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)

Stats

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