跳至内容
菜单
此问题已终结

Hello everyone,

I'm working on a website where users can order specific food items from a shop page, with each item being available on certain days of the week. I want to add a condition on the shop page that allows users to place an order only if it's at least 48 hours or more in advance. If there are less than 48 hours left for a specific food item, it should not be possible to add it to the cart.

Could anyone advise how to implement this? Would a scheduled action be the right approach? 

Any suggestions?

Thanks in advance for your help!

形象
丢弃
编写者

Every Oder will be place via the Website app in the shop page:

Sandwich: Available to order: ( Tuesday, Wednesday, Thursday, Friday and Saturday) not Available to order: (Sunday and Monday)

Pasta Salad: Available to order: ( Wednesday, Thursday, Friday Saturday and Sunday) not Available to order: (Monday and Tuesday)

Mini Pizza: Available to order: (Thursday, Friday, Saturday, Sunday and Monday) not Available to order: ( Tuesday and Wednesday)

Chicken Nuggets: Available to order: (Friday, Saturday, Sunday, Monday and Tuesday) Not Available to Order ( Wednesday and Thursday)

Fish and Chips: Available to order: (Saturday, Sunday, Monday, Tuesday and Wednesday Not Available to Order: ( Thursday and Friday)

( >>> Making the menu unavailable doesn't seem quite right. Today is Monday, user can't order for tomorrow (Tuesday), can the user not order for a week Monday or Tuesday? If Monday & Tuesday's menu isn't published they wouldn't be able to place that order.<<<)

What approach do you propose?

I tried this approach because of preparations. so that I have the number of a specific new that need to be prepared for a specific day 48 hours in advance.

If you have a better solution let me know please.

( >>> Not sure how you plan to capture the date of delivery. I would have used the extra step at checkout option. Settings > Website > Shop checkout section

Configure the form to include delivery date and probably have some automation here to not accept order less than 48 hrs.<<<)

or this part is it possible in Odoo V17.4 online? Can you give more details please.

Thanks

Yes, it is possible to have a form input at checkout.
1 Navigate to Website > Configuration > Settings and enable extra step at checkout
2 You would then have the option to configure the form Or navigate to a cart and click 'checkout'. While on the form, click edit top right of the page.
3. Click a field and change type or add a new field and set type to 'Delivery date'.
Once this field is set, it updated the delivery date on the order (other info tab) as well as updates the delivery order's 'Scheduled date'.

If your business model is to only accept orders between 48hr and 7 days (effective 5 days), then you should follow your method since it does not require any input from customer as to when they wish the delivery as it is possible only on a certain day of the week within 7 days

最佳答案

1 Making the menu unavailable doesn't seem quite right. Today is Monday, user can't order for tomorrow (Tuesday), can the user not order for a week Monday or Tuesday? If Monday & Tuesday's menu isn't published they wouldn't be able to place that order.

Unless I have misunderstood your ordering timelines. ( >>> 1. Ordering Restriction and Availability: The goal is for customers to place orders at least 48 hours in advance. For instance, if a user wants to order a sandwich for Monday, they should not be able to do so on the same Monday. However, the same sandwich should still be available for ordering on any day from Tuesday to Saturday for the next Monday<<<)

From what you describe it seems you want the orders deliveries to be limited between 48 hrs to 5 days

2 Not sure how you plan to capture the date of delivery. I would have used the extra step at checkout option. Settings > Website > Shop checkout section

Configure the form to include delivery date and probably have some automation here to not accept order less than 48 hrs.


3. You might be able to organize your menu with ecommerce categories and even banners to highlight which day the product is available.

形象
丢弃
编写者

Okay I will try it. thank you

编写者 最佳答案

Hello,

But I want to make it available for each week. For example i want Noodle to be available on each Monday. With the scheduled active date I can only insert one date at a time. Unless I am not doing it the right way.

Thanks

形象
丢弃

I see,
Maybe you can replace it with column `Scheduled Active Day` with the column type is `Selection`. You can put selection for days name of `Sunday until Monday`. But this approach will only work if only one product active in one certain day only (not multiple days). If you want to do multiple days, you will need a table to store the days name and use a column type `many2many`.

编写者

Can you help me how to set up the table to store the data?

编写者

I tried the selection then i created an scheduled action but it is not working. i am getting this error:

RPC_ERROR
Odoo Server Error
Traceback (most recent call last):
File "/home/odoo/src/odoo/17.0/odoo/tools/safe_eval.py", line 391, in safe_eval
return unsafe_eval(c, globals_dict, locals_dict)
File "ir.actions.server(822,)", line 2, in <module>
AttributeError: 'product.template' object has no attribute 'fields'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/odoo/src/odoo/17.0/odoo/http.py", line 1783, in _serve_db
return service_model.retrying(self._serve_ir_http, self.env)
File "/home/odoo/src/odoo/17.0/odoo/service/model.py", line 133, in retrying
result = func()
File "/home/odoo/src/odoo/17.0/odoo/http.py", line 1810, in _serve_ir_http
response = self.dispatcher.dispatch(rule.endpoint, args)
File "/home/odoo/src/odoo/17.0/odoo/http.py", line 2014, in dispatch
result = self.request.registry['ir.http']._dispatch(endpoint)
File "/home/odoo/src/odoo/17.0/addons/website/models/ir_http.py", line 235, in _dispatch
response = super()._dispatch(endpoint)
File "/home/odoo/src/odoo/17.0/odoo/addons/base/models/ir_http.py", line 222, in _dispatch
result = endpoint(**request.params)
File "/home/odoo/src/odoo/17.0/odoo/http.py", line 759, in route_wrapper
result = endpoint(self, *args, **params_ok)
File "/home/odoo/src/odoo/17.0/addons/web/controllers/dataset.py", line 28, in call_button
action = self._call_kw(model, method, args, kwargs)
File "/home/odoo/src/odoo/17.0/addons/web/controllers/dataset.py", line 20, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/odoo/src/odoo/17.0/odoo/api.py", line 468, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/home/odoo/src/odoo/17.0/odoo/api.py", line 453, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "/home/odoo/src/odoo/17.0/odoo/addons/base/models/ir_cron.py", line 107, in method_direct_trigger
cron.with_user(cron.user_id).with_context({'lastcall': cron.lastcall}).ir_actions_server_id.run()
File "/home/odoo/src/odoo/17.0/odoo/addons/base/models/ir_actions.py", line 939, in run
res = runner(run_self, eval_context=eval_context)
File "/home/odoo/src/odoo/17.0/addons/website/models/ir_actions_server.py", line 61, in _run_action_code_multi
res = super(ServerAction, self)._run_action_code_multi(eval_context)
File "/home/odoo/src/odoo/17.0/odoo/addons/base/models/ir_actions.py", line 771, in _run_action_code_multi
safe_eval(self.code.strip(), eval_context, mode="exec", nocopy=True, filename=str(self)) # nocopy allows to return 'action'
File "/home/odoo/src/odoo/17.0/odoo/tools/safe_eval.py", line 405, in safe_eval
raise ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr))
ValueError: <class 'AttributeError'>: "'product.template' object has no attribute 'fields'" while evaluating
"# Get the current date using Odoo's fields safely\ncurrent_date = env['product.template'].fields.Date.today()\ncurrent_day = current_date.weekday() # Get the current day of the week (Monday = 0, ..., Sunday = 6)\n\n# Search for all products that have a preparation day set\nproducts = env['product.template'].search([\n ('x_studio_preparation_day', '!=', False) # Replace with your field's actual technical name\n])\n\nfor product in products:\n # Get the preparation day from the product's field\n preparation_day = int(product.x_studio_preparation_day)\n \n # Calculate the difference in days between the current day and the preparation day\n day_difference = (preparation_day - current_day + 7) % 7\n \n # Publish the product on its preparation day each week\n if day_difference == 0:\n product.write({'website_published': True})\n \n # Unpublish the product if it's within 48 hours of the preparation day\n elif day_difference < 2:\n product.write({'website_published': False})"

The above server error caused the following client error:
RPC_ERROR: Odoo Server Error
RPCError@https://test-food-service.odoo.com/web/assets/0d9bfb7/web.assets_web.min.js:2885:319
makeErrorFromResponse@https://test-food-service.odoo.com/web/assets/0d9bfb7/web.assets_web.min.js:2888:163
jsonrpc/promise</<@https://test-food-service.odoo.com/web/assets/0d9bfb7/web.assets_web.min.js:2892:34

replace this line
`current_date = env['product.template'].fields.Date.today()`

with this
`current_date = datetime.datetime.today()`

编写者

Thank You.

I have been able to do it but when I run the scheduled action manually. all the dishes remain on the screen as published.

Python code:

# Map days of the week to their numeric values
day_map = {
'Monday': 0,
'Tuesday': 1,
'Wednesday': 2,
'Thursday': 3,
'Friday': 4,
'Saturday': 5,
'Sunday': 6
}

# Get the current date from the Odoo environment using today() safely
current_date = env['res.partner']._fields['create_date'].today()
current_day = current_date.weekday() # Get the current day of the week (Monday = 0, ..., Sunday = 6)

# Search for all products that have a preparation day set
products = env['product.template'].search([
('x_studio_preparation_day', '!=', False) # Replace with your field's actual technical name
])

for product in products:
# Get the preparation day from the product's field and map it to a numeric value
preparation_day_name = product.x_studio_preparation_day # Assuming this is the day name as a string
preparation_day = day_map.get(preparation_day_name)

# If preparation day is None (not in the map), skip this product
if preparation_day is None:
continue

# Calculate the difference in days between the current day and the preparation day
day_difference = (preparation_day - current_day + 7) % 7

# Debugging output
print(f"Product: {product.name}, Preparation Day: {preparation_day_name}, Day Difference: {day_difference}, Website Published: {product.website_published}")

# Publish the product on its preparation day each week
if day_difference == 0:
product.write({'website_published': True})

# Unpublish the product if it's within 48 hours of the preparation day
elif day_difference < 2:
product.write({'website_published': False})

change the column to be activated or deactivated:

from `website_published`

to `is_published`

Would you not want all the dishes to be published?

There is a 48hrs + order leadtime, so some might want to order 5-7 days in advance.

Or is your order limited to ONLY 48hrs?

编写者

Hello,

I'm currently trying on setting up a food ordering system in Odoo. The menu is the same every week, with different items available each day. The weekly menu looks like this:

Monday: Sandwich
Tuesday: Pasta Salad
Wednesday: Mini Pizza
Thursday: Chicken Nuggets
Friday: Fish and Chips

To place an order, users must do so at least 48 hours in advance. For example, they should not be able to order the Monday menu on Monday itself. If they try, the system should prevent them from making that order.

What I've tried so far:

I've added a custom field on the product form that specifies the "available day" for each food item.
I attempted to use a Scheduled Action to automatically "unpublish" any menu items that do not meet the 48-hour rule, while keeping those that do meet the rule published.

Unfortunately, my approach hasn't worked as expected as all menu are still published.

Do you know a better way to implement this 48-hour rule within Odoo? I'd like v17 enterprise saas any suggestions this effectively.

This is the code i have used in the scheduled action:

# Map days of the week to their numeric values
day_map = {
'Monday': 0,
'Tuesday': 1,
'Wednesday': 2,
'Thursday': 3,
'Friday': 4,
'Saturday': 5,
'Sunday': 6
}

# Safely get the current datetime using Odoo's environment
current_datetime = env['ir.cron']._fields['nextcall'].now()
current_day = current_datetime.weekday() # Get the current day of the week (Monday = 0, ..., Sunday = 6)

# Search for all products that have a preparation day set
products = env['product.template'].search([
('x_studio_preparation_day', '!=', False) # Replace with your actual field name
])

for product in products:
# Get the preparation day from the product's field and map it to a numeric value
preparation_day_name = product.x_studio_preparation_day # Assuming this is the day name as a string
preparation_day = day_map.get(preparation_day_name)

# If preparation day is not found in day_map, skip the product
if preparation_day is None:
continue

# Calculate the difference in days to the next preparation day
day_difference = (preparation_day - current_day + 7) % 7

# Calculate the next preparation date by adding `day_difference` days to the current datetime
next_preparation_date = current_datetime + timedelta(days=day_difference)

# Calculate the cutoff datetime for 48 hours before the preparation day
cutoff_datetime = next_preparation_date - timedelta(hours=48)

# Log publication status changes
if current_datetime >= cutoff_datetime:
product.write({'website_published': False})
env['ir.logging'].create({
'name': 'Product Unpublished',
'type': 'server',
'level': 'info',
'dbname': env.cr.dbname,
'message': f"Unpublished product: {product.name}",
'path': 'scheduled_action',
'func': 'action_code',
'line': '69',
})
else:
product.write({'website_published': True})
env['ir.logging'].create({
'name': 'Product Published',
'type': 'server',
'level': 'info',
'dbname': env.cr.dbname,
'message': f"Published product: {product.name}",
'path': 'scheduled_action',
'func': 'action_code',
'line': '77',
})

Note i tried to change from

`website_published`

to `is_published`

as Nazzun suggested but for some reason it is still not working.

Thank you.

Your comment
>>>I attempted to use a Scheduled Action to automatically "unpublish" any menu items that do not meet the 48-hour rule, while keeping those that do meet the rule published.<<<

My question was precisely this, can a customer NOT place an order on a Wednesday for the following Monday? Or for that matter a week Wednesday.

If your actions unpublish the available menu how will they be able to select? Additionally, how are you capturing the date for which the customer is placing the order?

编写者

My Approach:

1. Ordering Restriction and Availability: The goal is for customers to place orders at least 48 hours in advance. For instance, if a user wants to order a sandwich for Monday, they should not be able to do so on the same Monday. However, the same sandwich should still be available for ordering on any day from Tuesday to Saturday for the next Monday. This rule should apply consistently across all menu items based on their preparation day.

My approach was to unpublished the menu items from the website only 48 hours before their preparation day. Once the preparation day passes, the items should be republished and available again for the next week’s ordering.

The challenge here is to ensure that the products are only temporarily unavailable during the 48-hour cutoff period but otherwise available for pre-order for all other future dates.

2. Capturing the Order Date: For capturing the date, I plan to have the system take the actual date on which the order is placed. The customer’s choice of preparation day will determine when the item is available for fulfillment.

3. Request for Help:

Is this the right? Or is there a better way to implement this 48-hour ordering restriction while maintaining the smooth availability of menu items for future orders? I am especially concerned about ensuring that the temporary unpublishing and republishing of menu items is handled correctly without affecting the customer’s ability to place future orders.

Thank you.

最佳答案

Hello,

i think you can approach it using Odoo Studio and Scheduled Action.

  1. First create a column using Odoo Studio for the scheduled active date​ for the product available in the chart
  2. Second create a Scheduled Action to run every 5 menit, to check if the product hit scheduled active date​, then change the product state from archive into active
形象
丢弃
相关帖文 回复 查看 活动
0
2月 25
897
3
12月 20
4317
1
12月 24
1863
1
12月 24
1283
1
6月 25
1786