Help

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

CREATE CALCULATE FIELD WHICH USE DATA FROM ANOTHER MODEL

Avatar
odoo
1 Comment
Avatar
Discard
Avatar
odoo
-

Someone? can help me??

2 Answers
0
Avatar
odoo
Best Answer

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

2 Comments
Avatar
Discard
Avatar
odoo
-

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.

Avatar
odoo
-

Hi,

When you havé the correct code, it won’t update all your client and set the last order date in your field.

The code is only call when one Of the to field in your dépendances are updated.

So to test, you have either to change a state Of an existing order (cancel it and then confirm it) or create and confirme a new order.
If this work by updating your new field, the code is correct.

Then if you want to update all your client, you can add a third dependencies in the field, try a field you don’t use in your client.

Then export all your client with this field présent in your exported Column (it’s to save your old value).
After that, import a new/change value for this field in all your client. This will call the code because there is a change in this field. And after that ré-import your saved exported file who containe your saved value.

And now, you can delete this third field in your dependencies because, it was just to make a whole update Of your client but not needed when the solution is correct.

I’ve tried the code and it works in my database…
Hope you’l get it.

0
Avatar
odoo
Best Answer

this is what I wrote,


and the result, it doesnt calculate yet.

this is the field...




Avatar
Discard