forked from OCA/stock-logistics-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_stock_lot_scrap.py
68 lines (63 loc) · 2.47 KB
/
test_stock_lot_scrap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright 2016 Carlos Dauden <[email protected]>
# Copyright 2016 Pedro M. Baeza <[email protected]>
# Copyright 2017 David Vidal <[email protected]>
# Copyright 2024 Tecnativa - Carolina Fernandez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.exceptions import ValidationError
from odoo.tests import common, tagged
from odoo.tools.safe_eval import safe_eval
@tagged("post_install", "-at_install")
class TestStockLotScrap(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.product = cls.env["product.product"].create(
{"name": "Test product", "type": "product"}
)
cls.company = cls.env.ref("base.main_company")
cls.lot010 = cls.env["stock.lot"].create(
{
"name": "0000010",
"product_id": cls.product.id,
"company_id": cls.company.id,
}
)
cls.quant1 = cls.env["stock.quant"].create(
{
"quantity": 5000.0,
"location_id": cls.env.ref("stock.stock_location_stock").id,
"product_id": cls.product.id,
"lot_id": cls.lot010.id,
}
)
cls.quant2 = cls.env["stock.quant"].create(
{
"quantity": 325.0,
"location_id": cls.env.ref("stock.stock_location_stock").id,
"product_id": cls.product.id,
"lot_id": cls.lot010.id,
}
)
# Make sure the user is in English
cls.env.user.lang = "en_US"
def test_picking_created(self):
res = self.lot010.action_scrap_lot()
self.assertIn("domain", res)
scrap = self.env["stock.scrap"].search(safe_eval(res["domain"]))
self.assertAlmostEqual(sum(scrap.mapped("scrap_qty")), 5325)
self.assertTrue(
all(scrap.mapped("move_id").mapped(lambda x: x.state == "done"))
)
scrap[:1].action_validate()
self.assertIn("Lot was scrapped by", self.lot010.message_ids[:1].body)
def test_warning(self):
product_new = self.product.create({"name": "Test product 040"})
self.lot040 = self.env["stock.lot"].create(
{
"name": "0000040",
"product_id": product_new.id,
"company_id": self.company.id,
}
)
with self.assertRaises(ValidationError):
self.lot040.action_scrap_lot()