Skip to content

Commit

Permalink
[FIX] fieldservice: edge-case NoneType + datetime.timedelta
Browse files Browse the repository at this point in the history
  • Loading branch information
PicchiSeba committed Oct 10, 2023
1 parent 7e6a8c9 commit 7e77896
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions fieldservice/models/fsm_order.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Copyright (C) 2018 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import logging
from datetime import datetime, timedelta

from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError

from . import fsm_stage

_logger = logging.getLogger(__name__)


class FSMOrder(models.Model):
_name = "fsm.order"
Expand Down Expand Up @@ -311,20 +314,23 @@ def _calc_scheduled_dates(self, vals):
) - timedelta(hours=hrs)
vals["scheduled_date_start"] = str(date_to_with_delta)

elif (
vals.get("scheduled_duration", False) is not None
and vals.get("scheduled_date_start", self.scheduled_date_start)
and (
self.scheduled_date_start != vals.get("scheduled_date_start", False)
)
):
elif vals.get(
"scheduled_date_start", self.scheduled_date_start
) and self.scheduled_date_start != vals.get("scheduled_date_start", False):
hours = vals.get("scheduled_duration", False)
start_date_val = vals.get(
"scheduled_date_start", self.scheduled_date_start
)
start_date = fields.Datetime.from_string(start_date_val)
date_to_with_delta = start_date + timedelta(hours=hours)
vals["scheduled_date_end"] = str(date_to_with_delta)
if not start_date:
_logger.error(

Check warning on line 326 in fieldservice/models/fsm_order.py

View check run for this annotation

Codecov / codecov/patch

fieldservice/models/fsm_order.py#L326

Added line #L326 was not covered by tests
"The value of Scheduled End is invalid."
+ ", new: {}".format(vals.get("scheduled_date_start"))
+ ", old: {}".format(self.scheduled_date_start)
)
else:
date_to_with_delta = start_date + timedelta(hours=hours)
vals["scheduled_date_end"] = str(date_to_with_delta)
elif vals.get("scheduled_date_start") is not None:
vals["scheduled_date_end"] = False

Expand Down

0 comments on commit 7e77896

Please sign in to comment.