Skip to content

Commit

Permalink
Added control on picking sent stage
Browse files Browse the repository at this point in the history
  • Loading branch information
louck committed Jul 3, 2023
1 parent 361d695 commit d8ed66f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 46 deletions.
4 changes: 4 additions & 0 deletions commown_devices/data/project_task.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<field name="name">Diagnostic stage</field>
</record>

<record id="picking_sent" model="project.task.type">
<field name="name">Picking sent stage</field>
</record>

<record id="sup_picking_ongoing_stage" model="project.task.type">
<field name="name">Picking ongoing stage</field>
</record>
Expand Down
7 changes: 5 additions & 2 deletions commown_devices/models/project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"commown_devices.resiliated_stage",
]

CHECK_PICKING_ASSIGNED_STAGE_XML_IDS = "commown_devices.sup_picking_ongoing_stage"
CHECK_PICKING_ASSIGNED_STAGE_XML_IDS = [
"commown_devices.sup_picking_ongoing_stage",
"commown_devices.picking_sent",
]


class ProjectTask(models.Model):
Expand Down Expand Up @@ -167,7 +170,7 @@ def onchange_stage_id_prevent_contract_resiliation_with_device(self):
)

@api.constrains("stage_id")
def onchange_stage_id_check_assigned_picking(self):
ef onchange_stage_id_check_assigned_picking(self):
picking_ongoing_stage = self.env.ref(CHECK_PICKING_ASSIGNED_STAGE_XML_IDS)
erroneous_task = self.search(
[
Expand Down
12 changes: 1 addition & 11 deletions commown_devices/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,8 @@ def adjust_stock(

return lot

def adjust_stock_notracking(self, product, qty=1.0, date="2000-01-01"):
def adjust_stock_notracking(self, product, location, qty=1.0, date="2000-01-01"):

location = self.env["stock.location"].create(
{
"name": "Test Module stock location",
"usage": "internal",
"partner_id": 1,
"location_id": self.env.ref(
"commown_devices.stock_location_new_devices"
).id,
}
)
inventory = self.env["stock.inventory"].create(
{
"name": "test stock %s" % product.name,
Expand Down
76 changes: 43 additions & 33 deletions commown_devices/tests/test_project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def setUp(self):
) # for checks on stage change tests

self.ongoing_stage = self.env.ref("commown_devices.sup_picking_ongoing_stage")
self.picking_sent_stage = self.env.ref("commown_devices.picking_sent")

# Create a unused product and an unused service
self.env["product.template"].create(
Expand All @@ -68,7 +69,19 @@ def setUp(self):
"tracking": "none",
}
)
self.adjust_stock_notracking(self.nontracked_product.product_variant_id)
location = self.env["stock.location"].create(
{
"name": "Test Module stock location",
"usage": "internal",
"partner_id": 1,
"location_id": self.env.ref(
"commown_devices.stock_location_new_devices"
).id,
}
)
self.adjust_stock_notracking(
self.nontracked_product.product_variant_id, location
)

def _create_and_send_device(self, serial, contract, product=None, do_transfer=True):
lot = self.adjust_stock(product, serial=serial)
Expand Down Expand Up @@ -382,37 +395,31 @@ def test_contract_resiliation_with_devices(self):
self.assertTrue(self.task_test_checks.stage_id == resiliated_stage)

def test_outward_inward_notracking(self):
def get_present_location(pt_variant):
return (
self.env["stock.quant"]
.search(
[
("product_id.id", "=", pt_variant.id),
("quantity", ">", "0"),
]
)
.location_id
)

self.task.contract_id = self.c1
date = datetime.datetime(2020, 1, 10, 16, 2, 34)
pt_variant = self.nontracked_product.product_variant_id

initial_location = (
self.env["stock.quant"]
.search(
[
("product_id.id", "=", pt_variant.id),
("quantity", ">", "0"),
]
)
.location_id
)
initial_location = get_present_location(pt_variant)
wizard_outward = self.env[
"project.task.notracking.outward.picking.wizard"
].create({"task_id": self.task.id, "date": date, "variant_id": pt_variant.id})

picking = wizard_outward.create_picking()
do_new_transfer(picking, date)

client_location = (
self.env["stock.quant"]
.search(
[
("product_id.id", "=", pt_variant.id),
("quantity", ">", "0"),
]
)
.location_id
)
client_location = get_present_location(pt_variant)
self.assertNotEqual(initial_location, client_location)

wizard_inward = self.env[
Expand All @@ -422,22 +429,13 @@ def test_outward_inward_notracking(self):
picking = wizard_inward.create_picking()
do_new_transfer(picking, date)

final_location = (
self.env["stock.quant"]
.search(
[
("product_id.id", "=", pt_variant.id),
("quantity", ">", "0"),
]
)
.location_id
)
final_location = get_present_location(pt_variant)
self.assertEqual(
final_location,
self.env.ref("commown_devices.stock_location_devices_to_check"),
)

def test_change_task_check(self):
def test_change_stage_check(self):
with self.assertRaises(ValidationError) as err:
self.task_test_checks.stage_id = self.ongoing_stage
self.assertEqual(
Expand All @@ -450,15 +448,22 @@ def test_change_task_check(self):
"Error while validating constraint\n\nThis task can not be moved forward. There are no picking linked to this task.\n",
err2.exception.name,
)
with self.assertRaises(ValidationError) as err3:
self.task_test_checks.stage_id = self.picking_sent_stage
self.assertEqual(
"Error while validating constraint\n\nThis task can not be moved forward. There are no picking linked to this task.\n",
err3.exception.name,
)

module = self.nontracked_product.product_variant_id
lot = self.storable_product.product_variant_id

stock_location = self.env.ref("stock.stock_location_stock")
quant = self.env["stock.quant"].search(
[
("product_id", "=", lot.id),
("quantity", ">", 0),
("location_id.complete_name", "ilike", "WH/STOCK/"),
("location_id", "child_of", stock_location.id),
]
)[0]

Expand All @@ -467,9 +472,14 @@ def test_change_task_check(self):
origin=self.task_test_checks.get_id_name(),
)
self.task_test_checks.stage_id = self.ongoing_stage
self.assertTrue(self.task_test_checks.stage_id == self.ongoing_stage)

self.task_test_checks2.contract_id.send_device(
quant,
origin=self.task_test_checks2.get_id_name(),
)
self.task_test_checks2.stage_id = self.ongoing_stage
self.assertTrue(self.task_test_checks2.stage_id == self.ongoing_stage)

self.task_test_checks.stage_id = self.picking_sent_stage
self.assertTrue(self.task_test_checks.stage_id == self.picking_sent_stage)

0 comments on commit d8ed66f

Please sign in to comment.