Skip to content

Commit

Permalink
[FIX] stock_picking_group_by_partner_by_carrier_by_date: Fix timezone…
Browse files Browse the repository at this point in the history
… issue
  • Loading branch information
tuantrantg committed Mar 8, 2024
1 parent c087351 commit 8fd905d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# TODO: consider splitting the hook for `_assign_picking` defined in
# `stock_picking_group_by_partner_by_carrier`
# to avoid depending on `stock_picking_group_by_partner_by_carrier`.
"depends": ["stock_picking_group_by_partner_by_carrier"],
"depends": ["partner_tz", "stock_picking_group_by_partner_by_carrier"],
"data": ["views/stock_picking_type.xml"],
"installable": True,
"license": "AGPL-3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# Copyright 2020 Camptocamp (https://www.camptocamp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from datetime import timedelta

from odoo import models

from odoo.addons.partner_tz.tools.tz_utils import (
tz_to_utc_naive_datetime,
utc_to_tz_naive_datetime,
)


class StockMove(models.Model):
_inherit = "stock.move"
Expand All @@ -25,10 +32,22 @@ def _assign_picking_group_domain_by_date(self):
domain = []
if self._skip_assign_picking_group_domain_by_date():
return domain

Check warning on line 34 in stock_picking_group_by_partner_by_carrier_by_date/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_picking_group_by_partner_by_carrier_by_date/models/stock_move.py#L34

Added line #L34 was not covered by tests
date_planned = self.date.replace(hour=0, minute=0, second=0)
date_planned_end = date_planned.replace(hour=23, minute=59, second=59)
tz = (
self.warehouse_id.company_id.partner_id.tz
or self.env.company.partner_id.tz
or self.env.user.tz
)
date_tz = utc_to_tz_naive_datetime(tz, self.date)
dt_start_tz = date_tz.replace(
hour=0,
minute=0,
second=0,
microsecond=0,
)
dt_start = tz_to_utc_naive_datetime(tz, dt_start_tz)
dt_end = dt_start + timedelta(days=1)
domain = [
("scheduled_date", "<=", date_planned_end),
("scheduled_date", ">=", date_planned),
("scheduled_date", "<", dt_end),
("scheduled_date", ">=", dt_start),
]
return domain

0 comments on commit 8fd905d

Please sign in to comment.