This question has been flagged
1 Reply
3397 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)"/>

Avatar
Discard
Best Answer

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}

Avatar
Discard