From 93663ec5bb4fe798801b4de0d8a5d9fe0fd9fc07 Mon Sep 17 00:00:00 2001 From: louck Date: Wed, 6 Nov 2024 10:16:09 +0100 Subject: [PATCH] Add a delta between the two contract transfer's pickings --- .../models/wizard_project_task_picking.py | 8 ++++++-- commown_devices/tests/test_project_task.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/commown_devices/models/wizard_project_task_picking.py b/commown_devices/models/wizard_project_task_picking.py index d0f2035a3..a02a1f62c 100644 --- a/commown_devices/models/wizard_project_task_picking.py +++ b/commown_devices/models/wizard_project_task_picking.py @@ -1,3 +1,5 @@ +from datetime import timedelta + from odoo import _, api, fields, models from odoo.exceptions import UserError, Warning @@ -296,6 +298,8 @@ class ProjectTaskContractTransferWizard(models.TransientModel): def create_transfer(self): lot = self.task_id.lot_id + date = self.date or fields.Datetime.now() + if not lot: raise UserError(_("Can't move device: no device set on this task!")) @@ -307,7 +311,7 @@ def create_transfer(self): [self.task_id.lot_id], {}, transfer_location, - date=self.date, + date=date, do_transfer=True, ) @@ -315,7 +319,7 @@ def create_transfer(self): [self.task_id.lot_id], {}, send_lots_from=transfer_location, - date=self.date, + date=date + timedelta(seconds=1), do_transfer=True, ) diff --git a/commown_devices/tests/test_project_task.py b/commown_devices/tests/test_project_task.py index 0657b6b28..092e3ff73 100644 --- a/commown_devices/tests/test_project_task.py +++ b/commown_devices/tests/test_project_task.py @@ -455,6 +455,21 @@ def test_wizard_contract_transfer(self): self.assertNotIn(self.task.lot_id, self.c1.lot_ids) self.assertIn(self.task.lot_id, self.c2.lot_ids[0]) + lot_pickings = self.env["stock.picking"].search( + [("move_line_ids.lot_id", "=", self.task.lot_id.id)] + ) + transfer_location = self.env.ref( + "commown_devices.stock_location_contract_transfer" + ) + p1 = lot_pickings.filtered( + lambda p, loc=transfer_location: p.location_dest_id == loc + ) + p2 = lot_pickings.filtered( + lambda p, loc=transfer_location: p.location_id == loc + ) + self.assertTrue( + p2.move_lines.date - p1.move_lines.date == datetime.timedelta(seconds=1) + ) def test_contract_resiliation_with_devices(self): diagnostic_stage = self.env.ref("commown_devices.diagnostic_stage")