[16.0][ADD] website_blog_scheduled_publication: add new module#1159
[16.0][ADD] website_blog_scheduled_publication: add new module#1159marcelsavegnago wants to merge 1 commit intoOCA:16.0from
Conversation
|
@marcelsavegnago I guess you could take a similar approach as https://github.com/OCA/e-commerce/blob/15.0/website_sale_product_publish_date/models/product_template.py? I think there could even be a generic module with a mixin model which can be inherited by regular models if it fits the core architecture (I haven't taken a thorough look on it). |
bb858c1 to
90b624b
Compare
@yostashiro You’re right — that approach looks like a solid reference point. For now I’m handling a very specific case to solve the immediate need, but once I have a bit more time I’ll take a closer look and see if we can support a more generic solution (like a mixin / small reusable module) that fits well with the core architecture. |
aa545a8 to
faa9210
Compare
c4dce31 to
d06c485
Compare
e03ecbc to
6303ae2
Compare
ivs-cetmix
left a comment
There was a problem hiding this comment.
Thank you for you contribution!
Some note - not an issue - how about adding a calendar view for the blog.post model so it would be easier to see the scheduled posts?
| """Check if post has a future scheduled date.""" | ||
| if post.scheduled_publication_date and post.scheduled_publication_date > now: | ||
| return True | ||
| scheduled_date = _to_datetime(vals.get("scheduled_publication_date")) |
There was a problem hiding this comment.
Question: isn't scheduled_publication_date a Python datetime object already?
There was a problem hiding this comment.
Good point. When accessed from a record (post.scheduled_publication_date), it's already a datetime object. However, vals.get("scheduled_publication_date") can be a string when values come from forms, wizards, or API calls.
The _to_datetime() helper handles both cases safely — it converts strings to datetime and passes through datetime objects unchanged.
We're open to suggestions if you have a better approach.
There was a problem hiding this comment.
Noted, let's leave as is for now. Would be good to add some comment in the code though to avoid same question in the future.
11510fa to
ec379a3
Compare
|
what's the point of this module given Odoo already supports setting |
| def _to_datetime(value): | ||
| """Convert string to datetime if needed. | ||
|
|
||
| Note: When accessing a Datetime field from a record (e.g., | ||
| post.scheduled_publication_date), Odoo automatically returns a Python | ||
| datetime object. However, when working with vals dictionaries (from forms, | ||
| wizards, or API calls), the value may come as a string and needs to be | ||
| converted to datetime for proper comparison operations. | ||
| """ | ||
| if not value: | ||
| return False | ||
| if isinstance(value, str): | ||
| return fields.Datetime.from_string(value) | ||
| return value |
There was a problem hiding this comment.
Perfect example of AI slop. This method has the exact same resilience as from_string itself! https://github.com/odoo/odoo/blob/16.0/odoo/fields.py#L2216-L2239
Summary
This PR adds a new module
website_blog_scheduled_publicationthat allows users to schedule blog posts for automatic publication at a specific date and time.Features
Technical Details
blog.postmodel with new fields (scheduled_publication_date,schedule_type,next_departure) and methodsblog.post.schedule.datefor the scheduling wizardwebsite_blogDependencies
website_blogTest Plan
pytest website_blog_scheduled_publication/tests/