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 get value from another function?

By
kitcle
on 4/18/15, 9:27 AM 522 views

def _get_commitment_date(self, cr, uid, ids, name, arg, context=None):

    """Compute the commitment date"""

    res = {}

    dates_list = []

    for order in self.browse(cr, uid, ids, context=context):

        dates_list = []

        order_datetime = datetime.strptime(order.date_order, DEFAULT_SERVER_DATETIME_FORMAT)

        for line in order.order_line:

            dt = order_datetime + timedelta(days=line.delay or 0.0)

            dt_s = dt.strftime(DEFAULT_SERVER_DATETIME_FORMAT)

            dates_list.append(dt_s)

        if dates_list:

            res[order.id] = min(dates_list)

    return res

*********************************************************************************************


def on_change_date_order(self, cr, uid, ids, order_date, arg,context=None):

    result = {}

    if order_date is not False:

        result['delivery_date'] =self._get_commitment_date(cr, uid, ids, field_name, arg, context=context)  **ERROR !!

    return {'value': result}

**********************************************************

xml file :

<field name="date_order" on_change="on_change_date_order(order_date,context)"/>

0

Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
3577
| 5 4 9
Pondicherry, India
--Dhinesh - Technical Consultant, Sodexis Inc--

Passionate coder in Python/OpenERP. Knows Django/Flask MVC frameworks. Did code in Java, PHP.

Contact me at: dvdhinesh.mail@gmail.com

Dhinesh - Technical Consultant, Sodexis Inc
On 4/20/15, 3:33 AM

I hope your first method is a functional field method ("""Compute the commitment date""" ). You don't need to call the method directly. You can call the "commitment date" field. Obviously it will call the method and return the data you expected.

Because computed/functional fields require, some signature which is not provided correctly.

In order to get the field value you have to know the ids to browse. Since it is a onchange you won't get the ids. So you can't directly call the field itself. You need to do a work around in the onchange by rewriting all the computation you done in the functional field method also in onchange method.

Or define the real computation in separate method and use that method in both because the final result which going to save is the functional method result.

 def on_change_date_order(self, cr, uid, ids, order_date, arg,context=None): 
    result = {}
     if order_date is not False:
        result['delivery_date'] = commitment_field_name #will not work (so compute again)
return {'value': result}

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: 4/18/15, 9:27 AM
Seen: 522 times
Last updated: 4/20/15, 3:57 AM