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 820190c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 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,18 +314,16 @@ 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)
if not start_date:
raise ValueError(_("The value of Scheduled End is invalid."))

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
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:
Expand Down

0 comments on commit 820190c

Please sign in to comment.