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

function fields not getting updated

By
Sam path
on 6/17/14, 4:05 AM 736 views

Hi all,

I've created a field Transport charges in sale order which fetches the amount from delivery method field in sale order. This field is used in the computation of margin. 

Margin now is "Selling price - Cost price". but I've altered it as "Selling price - Cost price - Transport Charges" and it is working fine when i create the order freshly but if I edit the transport charges amount in a already created order the margin is not getting updated, It remains the old margin. The margin is not getting computed and updated again.

Can anyone help me how to update or where am I going wrong

The code to compute is

_inherit = "sale.order"
    def _product_margin(self, cr, uid, ids, field_name, arg, context=None):
        result = {}
        for sale in self.browse(cr, uid, ids, context=context):
            result[sale.id] = 0.0
            for line in sale.order_line:
                result[sale.id] += line.margin or 0.0
            result[sale.id] = result[sale.id] - sale.transport
        return result

_columns = {
        'transport':fields.float('transport charges', digits=(16,2)),            
    }

Yeah donelli i know we have to put a onchange trigger but i dont know how to trigger the function from that onchange method

Sam path
on 6/17/14, 8:10 AM
2

Leonardo Donelli

--Leonardo Donelli--
1040
| 5 4 8
Cave, Italy
--Leonardo Donelli--

Physics student and part-time developer.

Leonardo Donelli
On 6/17/14, 5:18 AM

You omitted the most important part of the code, the definition of the field `margin`.

My guess is that margin is a function field with a `store` parameter, that tells OpenERP to store the value in the database the first time it's calculated instead of recomputing it every time. With the store parameter you can also specify some fields that, when changed, will trigger a recalculation of your field. What you wanna do is add your `transport` field to this list of "trigger" fields, so that when `transport` is changed `margin` will be recomputed.

Function fields and store parameter.

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/17/14, 4:05 AM
Seen: 736 times
Last updated: 3/16/15, 8:10 AM