콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
3818 화면

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)"/>

아바타
취소
베스트 답변

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}

아바타
취소