Skip to content

Commit 11510fa

Browse files
adjust
1 parent 6303ae2 commit 11510fa

2 files changed

Lines changed: 60 additions & 3 deletions

File tree

website_blog_scheduled_publication/models/blog_post.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77

88

99
def _to_datetime(value):
10-
"""Convert string to datetime if needed."""
10+
"""Convert string to datetime if needed.
11+
12+
Note: When accessing a Datetime field from a record (e.g.,
13+
post.scheduled_publication_date), Odoo automatically returns a Python
14+
datetime object. However, when working with vals dictionaries (from forms,
15+
wizards, or API calls), the value may come as a string and needs to be
16+
converted to datetime for proper comparison operations.
17+
"""
1118
if not value:
1219
return False
1320
if isinstance(value, str):
@@ -91,7 +98,12 @@ def _check_for_publication(self, vals):
9198
return super(BlogPost, posts_to_notify.sudo())._check_for_publication(vals)
9299

93100
def _has_future_scheduled_date(self, post, vals, now):
94-
"""Check if post has a future scheduled date."""
101+
"""Check if post has a future scheduled date.
102+
103+
Note: post.scheduled_publication_date is already a datetime object
104+
(Odoo converts it automatically), but vals.get() may return a string
105+
that needs conversion via _to_datetime().
106+
"""
95107
if post.scheduled_publication_date and post.scheduled_publication_date > now:
96108
return True
97109
scheduled_date = _to_datetime(vals.get("scheduled_publication_date"))
@@ -150,7 +162,12 @@ def _process_write_vals(self, record, vals, now):
150162
return record_vals
151163

152164
def _get_effective_scheduled_date(self, record, vals):
153-
"""Get the scheduled date that will be effective after write."""
165+
"""Get the scheduled date that will be effective after write.
166+
167+
Note: Uses _to_datetime() for both cases to ensure consistent
168+
datetime objects, even though record.scheduled_publication_date
169+
is already a datetime (defensive programming).
170+
"""
154171
if "scheduled_publication_date" in vals:
155172
return _to_datetime(vals.get("scheduled_publication_date"))
156173
return _to_datetime(record.scheduled_publication_date)

website_blog_scheduled_publication/views/blog_post_views.xml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@
8181
name="not_published"
8282
domain="[('website_published', '=', False)]"
8383
/>
84+
<filter
85+
string="Scheduled"
86+
name="scheduled"
87+
domain="[('scheduled_publication_date', '!=', False)]"
88+
/>
8489
</filter>
8590
<filter name="last_contributor" position="after">
8691
<filter
@@ -98,4 +103,39 @@
98103
</filter>
99104
</field>
100105
</record>
106+
107+
<record id="view_blog_post_calendar_scheduled" model="ir.ui.view">
108+
<field name="name">blog.post.calendar.scheduled</field>
109+
<field name="model">blog.post</field>
110+
<field name="arch" type="xml">
111+
<calendar
112+
string="Scheduled Blog Posts"
113+
date_start="scheduled_publication_date"
114+
color="blog_id"
115+
mode="month"
116+
>
117+
<field name="name" />
118+
<field name="scheduled_publication_date" />
119+
<field name="blog_id" />
120+
<field name="website_published" />
121+
</calendar>
122+
</field>
123+
</record>
124+
125+
<record id="action_blog_post_calendar_scheduled" model="ir.actions.act_window">
126+
<field name="name">Scheduled Blog Posts</field>
127+
<field name="res_model">blog.post</field>
128+
<field name="view_mode">calendar,tree,form</field>
129+
<field name="view_id" ref="view_blog_post_calendar_scheduled" />
130+
<field name="domain">[('scheduled_publication_date', '!=', False)]</field>
131+
<field name="context">{}</field>
132+
<field name="help" type="html">
133+
<p class="o_view_nocontent_smiling_face">
134+
No scheduled posts found
135+
</p>
136+
<p>
137+
Schedule blog posts to see them in the calendar view.
138+
</p>
139+
</field>
140+
</record>
101141
</odoo>

0 commit comments

Comments
 (0)