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.

0

how to call a fields.function from another object function?

By
vadivel
on 7/13/16, 7:28 AM 326 views

Hi friends,

I have to call sale_order fields.function names _amount_all from another button function for less the discount amount from total amount when validating sale order.Please help me in this situation.

1

deep

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

deep
On 7/14/16, 2:41 AM

In Odoo 8 and above.

One cannot trigger the computational fields without the change in values of its dependent fields.

Say in case of SaleOrder,  "_amount_all" method is depended on the field value price_subtotal present in its child class i.e. in SaleOrderLine, So unless and until the value of price_subtotal is changed, the function will not be triggered. which is actually a good functionality, because it avoids unnecessary triggers and writing values into the database.


Now coming to your requirement, if am not wrong you have a discount_field in SaleOrder and upon specifying a value you want the same to be reflected in Total Amount of SaleOrder.

So why not inherit _amount_all in your custom module and concatenate the discount_field into @api.depends as shown below.

    @api.depends('discount_field')
    def _amount_all(self):
        super(SaleOrder, self)._amount_all()
        for order in self:
            order.amount_total -= order.discount_field


Am sure this way you can achieve your requirement, but if you still wanted to trigger the computation field, and if you using Odoo 8 then all you need to do is add recompute = True in the context while calling write method as below.

context = dict(self._context, recompute=True)

 Note: In Odoo 9, recompute doesn't work.

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: 7/13/16, 7:28 AM
Seen: 326 times
Last updated: 7/18/16, 6:29 AM