When I create a new quotation or sales order, I want to set the delivery date automatically to the next weekday based on another field named "x_studio_delivery_day". I'm using Odoo Online, I went into Studio and into "Delivery Date" properties. I see the option to "Compute" in "Advanced Properties", but not able to figure out the code to put in there. Any help?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Księgowość
- Zapasy
- PoS
- Project
- MRP
To pytanie dostało ostrzeżenie
Ok. I solved it myself.
I created a new automation rule in Settings > Automation Rules.
Trigger: State is set to: "Sales Order"
Action: "Execute Code"
And used the below code
--
weekdays = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
# Get today's date (in server time)
today = datetime.date.today()
today_name = today.strftime('%A')
target_day = record.x_studio_delivery_day
if target_day in weekdays:
days_until = (weekdays.index(target_day) - weekdays.index(today_name) + 7) % 7
days_until = days_until or 7
new_date = today + datetime.timedelta(days=days_until)
# Combine with 8:00 AM time
new_datetime = datetime.datetime.combine(new_date, datetime.time(9, 0))
else:
new_date = False
record.write({'commitment_date': new_datetime})
Podoba Ci się ta dyskusja? Dołącz do niej!
Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!
Zarejestruj sięPowiązane posty | Odpowiedzi | Widoki | Czynność | |
---|---|---|---|---|
|
3
lut 25
|
2097 | ||
|
1
gru 24
|
2168 | ||
|
2
mar 24
|
2514 | ||
Managing orders from repeat customers
Rozwiązane
|
|
2
mar 24
|
3019 | |
|
0
wrz 23
|
1582 |
Please explain more about this new field you added from studio - x_studio_delivery_day. What kind of data this field holds. After that I will be able to give you the code.
Hi Abhay,
x_studio_delivery_day is a field in the model x_delivery_route in Inventory module. It is a selection of values "Monday, Tuesday, Wednesday, Thursday, Friday".
I have connected this related field into the sales.order, so the value shows up in the sales order.