Skip to content

Commit

Permalink
[FIX] sale_order_line_date: fix setting empty commitment date on stoc…
Browse files Browse the repository at this point in the history
…k moves

Fixes #3363:
```
TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'NoneType'
```
in stock.move's _set_date_deadline
  • Loading branch information
metaminux authored and StefanRijnhart committed Feb 3, 2025
1 parent 2acb489 commit 8faf07e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion sale_order_line_date/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)

from odoo import api, models
from odoo import models


class SaleOrder(models.Model):
Expand Down
22 changes: 13 additions & 9 deletions sale_order_line_date/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,19 @@ def _prepare_procurement_values(self, group_id=False):
return vals

def write(self, vals):
"""Propagate a new commitment date to pending stock moves"""
res = super().write(vals)
moves_to_upd = set()
if "commitment_date" in vals:
for line in self:
for move in line.move_ids:
if move.state not in ["cancel", "done"]:
moves_to_upd.add(move.id)
if moves_to_upd:
self.env["stock.move"].browse(moves_to_upd).write(
{"date_deadline": vals.get("commitment_date")}
)
if vals.get("commitment_date"):
self.move_ids.filtered(
lambda sm: sm.state not in ["cancel", "done"]
).write({"date_deadline": vals.get("commitment_date")})
else:
for line in self:
date_deadline = (
line.order_id.commitment_date or line._expected_date()
)
line.move_ids.filtered(
lambda sm: sm.state not in ["cancel", "done"]
).write({"date_deadline": date_deadline})
return res
11 changes: 11 additions & 0 deletions sale_order_line_date/tests/test_sale_order_line_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,14 @@ def test_03_line_commitment_date_picking_propagation(self):
self._assert_equal_dates(
self.sale_line1.commitment_date, self.sale_line1.move_ids.date_deadline
)

def test_04_line_commitment_date_removal(self):
self.sale1.commitment_date = False
self.sale1.action_confirm()
self._assert_equal_dates(
self.sale_line1.commitment_date, self.sale_line1.move_ids.date_deadline
)
self.sale_line1.commitment_date = False
self._assert_equal_dates(
self.sale_line1._expected_date(), self.sale_line1.move_ids.date_deadline
)

0 comments on commit 8faf07e

Please sign in to comment.