Fix timezones printing in UTC instead of client`s timezone in FSM work orders

This commit is contained in:
mathis 2025-06-17 10:26:24 -04:00
parent b90466786d
commit 8775cec248
2 changed files with 10 additions and 34 deletions

View file

@ -3,30 +3,10 @@ from odoo.addons.project.models.project_task import CLOSED_STATES
import re
import pytz
class Task(models.Model):
_inherit = ["project.task", "durpro.tag.inheritance.mixin"]
_name = "project.task"
planned_date_begin_est = fields.Datetime(compute="_compute_est_dates", string="Planned Start (EST)")
date_deadline_est = fields.Datetime(compute="_compute_est_dates", string="Planned End (EST)")
def _get_est_datetime(self, dt):
if not dt:
return False
user_tz = pytz.timezone('America/Toronto')
if not dt.tzinfo:
dt = fields.Datetime.from_string(str(dt))
dt = fields.Datetime.context_timestamp(self, dt)
dt_est = dt.astimezone(user_tz)
# Return naive datetime in EST (strip tzinfo)
return dt_est.replace(tzinfo=None)
def _compute_est_dates(self):
for rec in self:
rec.planned_date_begin_est = rec._get_est_datetime(rec.planned_date_begin)
rec.date_deadline_est = rec._get_est_datetime(rec.date_deadline)
_inherit = "project.task"
work_order_contacts = fields.Many2many(
comodel_name="res.partner",

View file

@ -361,17 +361,13 @@
t-if="doc.planned_date_begin or doc.date_deadline"
>
<div t-if="doc.planned_date_begin"><h6>Planned start: </h6></div>
<div class="mb-3">
<div>
<span t-esc="doc.planned_date_begin_est and doc.planned_date_begin_est.strftime('%Y-%m-%d %H:%M')" />
</div>
</div>
<div t-if="doc.date_deadline"><h6>Planned end: </h6></div>
<div class="mb-3">
<div>
<span t-esc="doc.date_deadline_est and doc.date_deadline_est.strftime('%Y-%m-%d %H:%M')" />
</div>
</div>
<div class="mb-3">
<div t-esc="context_timestamp(doc.planned_date_begin).strftime('%Y-%m-%d %H:%M')" />
</div>
<div t-if="doc.date_deadline"><h6>Planned end: </h6></div>
<div class="mb-3">
<div t-out="context_timestamp(doc.date_deadline).strftime('%Y-%m-%d %H:%M')" />
</div>
</div>
</div>
<div class="row" name="site_and_work_order_contacts">
@ -568,7 +564,7 @@
<template id="work_order">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="doc">
<t t-set="doc" t-value="doc.root_ancestor" t-if="doc.parent_id"/>
<t t-set="doc" t-value="doc.root_ancestor.with_context(tz=doc.partner_id.tz)" t-if="doc.parent_id"/>
<t t-call="web.external_layout">
<t t-call="bemade_fsm.work_order_page"/>
</t>