Odoo Help

Welcome!

This community 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.

1

Is it possible to call a function field method from onchange function.

By
Vikram
on 6/26/14, 7:36 AM 2,397 views

i created a function field tax_amount in sale_order_line. Now i want to call my function field from existing onchange function of product uom in sale order line. How to call a function field function from onchange function and give me example

(or)

Simply i want to compute a sale order amounts(amount_untaxed, amount_tax, amount_total) for each sale order line entries. Can be a solution or idea to achieve this

 

1

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 10/12/15, 10:38 PM

Hi,

Hope you are working with v8. I don't think, you need to override the onchange function.

If your tax_amount depends only on product uom, you can define the tax_amount as a compute field which depends on product_uom. onchange is default in compute fields. If tax_amount depends on more fields, you can include that also. For eg:

class sale_order_line(models.Model):
_inherit = 'sale.order.line'

tax_amount = fields.Float(compute='_get_tax_amount', string='Tax Amount')

@api.one
@api.depends('product_uom', 'product_id')
def _get_tax_amount(self):

//Your code here that calculates the tax value
self.tax_amount = tax value
0

René Schuster

--René Schuster--
1560
| 5 5 8
Weinheim, Germany
--René Schuster--

Challenge Everything!

René Schuster
On 6/26/14, 7:43 AM

Simply call your function from within the on_change method.

Take care of the scope and use self.function_name.

An example can be found in the hr_holidays module: onchange_date_from calls _get_number_of_days

 

Regards.

Yes! You can call a function(Normal) from onchange, but need to call a function _amount_tax_line (function field defined in column of sale.order.line class). A function field column is called when you press Save button but need to call from onchange_product_id function from sale.order.line...

Vikram
on 6/26/14, 10:07 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/26/14, 7:36 AM
Seen: 2397 times
Last updated: 10/12/15, 10:49 PM