Skip to content

Commit

Permalink
[MIG] stock_picking_group_by_partner_by_carrier_by_date: Migration to…
Browse files Browse the repository at this point in the history
… 16.0
  • Loading branch information
tuantrantg committed Mar 7, 2024
1 parent 1c5b5af commit 34fcfad
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 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,18 @@ 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.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
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from freezegun import freeze_time

from odoo.tests import SavepointCase, tagged
from odoo.tests import TransactionCase, tagged


class TestGroupByDateBase(SavepointCase):
class TestGroupByDateBase(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down

0 comments on commit 34fcfad

Please sign in to comment.