跳至内容
菜单
此问题已终结
2 回复
2061 查看

Hi,

I am working with Odoo Web Enterprise 17.0+e.

As shown in the image below, I have 2 fields with type of Date: Last Inspect and Next Inspect. Currently I input those manually and what I want to do is when I input date of Last Inspect, the date of Next Inspect will be automatically filled with date of 3 months range from the date of Last Inspect. So Next Inspect will be a read only field. I tried with automations but still fruitless.

Is this possible to achieve?

Thanks in advance!

形象
丢弃
最佳答案

Hello zulsani

You can actually do it using the Settings => Technical => Automation => Automation Rules

you have to enable debug mode first or the menu will be hidden

1- create a new automation rule and assign it any name e.g(Set Next Inspect Date)

2- Select the model the fields exist in ( if you dont know the name of the model you can search by model technical name and i will explain it in the end of the answer how to get this technical name)

3- Set Trigger to On UI Change

4- Set when Updating to Last Inspect

5- Add action

6- select the action type Execute Code


Set the following code

record.update({
​"next_inspect_field_technical_name" : record.last_inspect_field_technical_name+dateutil.relativedelta.relativedelta(months=3)
})


You can know the next_inspect_field_technical_name and the last_inspect_field_technical_name by activating debug mode then hover by the mouse on the question mark next to the field, the field name will be written in front of Field

see the example below the field technical name is ref and the model technical name is (account.move which is journal entry)

形象
丢弃
编写者

works perfectly. thank you so much!

最佳答案

Hello

Add the Compute method for the field Next Inspect, inside the Compute Method, Add your calculation After 3 days of Last Inspect.

In the field Advanced Properties you can add dependencies and Compute function. Here add dependency as the Last Inspect field and apply your condition.

Define Compute Method For A Field-Studio


Regards


形象
丢弃
相关帖文 回复 查看 活动
4
4月 23
3332
1
12月 21
3135
1
4月 25
4266
1
7月 24
2574
3
3月 24
1789