Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] sale_order_line_date : add test for commitment date removal on … #3364

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions sale_order_line_date/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ def _prepare_procurement_values(self, group_id=False):

def write(self, vals):
res = super().write(vals)
moves_to_upd = set()
if "commitment_date" in vals:
for move in self.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})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@metaminux Here, try to build ids set as before to write just once

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to loop on lines because _expected_date calls ensure_one at first and we could call the write method on lines that don't belong to the same order, so date_deadline wont be the same for each line...

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
)
Loading