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 a delta between the two contract transfer's pickings #331

Merged
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
8 changes: 6 additions & 2 deletions commown_devices/models/wizard_project_task_picking.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import timedelta

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

Expand Down Expand Up @@ -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!"))

Expand All @@ -307,15 +311,15 @@ def create_transfer(self):
[self.task_id.lot_id],
{},
transfer_location,
date=self.date,
date=date,
do_transfer=True,
)

self.contract_id.send_devices(
[self.task_id.lot_id],
{},
send_lots_from=transfer_location,
date=self.date,
date=date + timedelta(seconds=1),
do_transfer=True,
)

Expand Down
15 changes: 15 additions & 0 deletions commown_devices/tests/test_project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading