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

HELLO,

I need to calculate a field which shows the last order date from each customers.

The field I created in customer model its call "x_studio_fecha_ultima_compra"

Whereas the formula max was right aplied, the depedence field it did not work and its drive me crazy.

please, help me how to have to call the field date order from sale order model, and how to have to calculate the maximum value of date order field for each customer.


regards,






아바타
취소
작성자

Someone? can help me??

작성자 베스트 답변

this is what I wrote,


and the result, it doesnt calculate yet.

this is the field...




아바타
취소
베스트 답변

Hi,

  • dependancies : sale_order_ids.date_order,sale_order_ids.state
    • sale_order_ids.date_order : when this date change, we want update our field
    • sale_order_ids.state : when the state change too. Because if a client change his mind and cancel an order/sale, we must change the date.
  • calculate :
for record in self:
    confirmed_client_orders = record.sale_order_ids.filtered(lambda o: o.state == 'sale')
    if confirmed_client_orders:
        # Obtenir la date de la dernière commande
        record['x_studio_fecha_ultima_compra'] = max(confirmed_client_orders.mapped('date_order'))
    else:
        # Pas de commandes confirmées
        record['x_studio_fecha_ultima_compra'] = False

아바타
취소
작성자

Hi, Thanks.
I changed the code and It solved the windows error about dependences fields, but it doesnt show any date in the calculate fields yet.