Skip to content

Commit

Permalink
[FIX] repair_stock_move: Assign lot on stock move creation. Otherwise…
Browse files Browse the repository at this point in the history
… in the

_action_assign it may reserve the incorrect quant and then and error is raised
when unreserving the quant: https://github.com/odoo/odoo/blob/15.0/addons/stock/models/stock_move_line.py#L388
  • Loading branch information
AaronHForgeFlow committed Dec 13, 2024
1 parent 5a872c5 commit 8c18c88
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 13 deletions.
2 changes: 1 addition & 1 deletion repair_stock_move/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"summary": "Ongoing Repair Stock Moves Definition in odoo",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/repair",
"depends": ["repair"],
"depends": ["repair", "stock_restrict_lot"],
"data": [
"views/repair_order_views.xml",
],
Expand Down
5 changes: 4 additions & 1 deletion repair_stock_move/models/repair_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _compute_show_check_availability(self):
)

def _prepare_repair_stock_move(self):
return {
vals = {
"name": self.name,
"product_id": self.product_id.id,
"product_uom": self.product_uom.id or self.product_id.uom_id.id,
Expand All @@ -71,6 +71,9 @@ def _prepare_repair_stock_move(self):
"origin": self.name,
"company_id": self.company_id.id,
}
if self.lot_id:
vals["restrict_lot_id"] = self.lot_id.id
return vals

def _create_repair_stock_move(self):
self.ensure_one()
Expand Down
88 changes: 77 additions & 11 deletions repair_stock_move/tests/test_repair_stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class TestRepairStockMove(common.TransactionCase):
@classmethod
def setUpClass(cls):
super(TestRepairStockMove, cls).setUpClass()
# Models
cls.StockProductionLot = cls.env["stock.production.lot"]
cls.StockQuant = cls.env["stock.quant"]
# Partners
cls.res_partner_1 = cls.env["res.partner"].create({"name": "Wood Corner"})
cls.res_partner_address_1 = cls.env["res.partner"].create(
Expand Down Expand Up @@ -104,6 +107,64 @@ def setUpClass(cls):

cls.env.user.groups_id |= cls.env.ref("stock.group_stock_user")

# setup for the tests with lots
# we create several lots qith qty
# we want to check the system will get the correct lot
cls.product_lot = cls.env["product.product"].create(
{
"name": "Acoustic Magic Bloc",
"list_price": 2950.0,
"type": "product",
"tracking": "serial",
}
)
cls.lot = cls.StockProductionLot.create(
{
"product_id": cls.product_lot.id,
"name": "Lot A",
"company_id": cls.env.company.id,
}
)
cls.lot2 = cls.lot.copy({"name": "Lot B"})
cls.lot3 = cls.lot.copy({"name": "Lot C"})
cls.stock_location_stock = cls.env.ref("stock.stock_location_stock")
cls.StockQuant.create(
{
"location_id": cls.stock_location_stock.id,
"product_id": cls.product_lot.id,
"lot_id": cls.lot.id,
"inventory_quantity": 1,
}
).action_apply_inventory()
cls.StockQuant.create(
{
"location_id": cls.stock_location_stock.id,
"product_id": cls.product_lot.id,
"lot_id": cls.lot2.id,
"inventory_quantity": 1,
}
).action_apply_inventory()
cls.StockQuant.create(
{
"location_id": cls.stock_location_stock.id,
"product_id": cls.product_lot.id,
"lot_id": cls.lot3.id,
"inventory_quantity": 1,
}
).action_apply_inventory()
cls.repair_with_lot = cls.env["repair.order"].create(
{
"invoice_method": "none",
"user_id": False,
"product_id": cls.product_lot.id,
"product_uom": cls.env.ref("uom.product_uom_unit").id,
"partner_invoice_id": cls.res_partner_address_1.id,
"location_id": cls.stock_location_stock.id,
"lot_id": cls.lot3.id,
"partner_id": cls.res_partner_12.id,
}
)

def test_stock_move_state(self):
# Validate Repair Order
self.repair1.action_validate()
Expand Down Expand Up @@ -177,14 +238,19 @@ def _create_simple_operation(self, repair_id=False, qty=0.0, price_unit=0.0):
}
)

# def _create_simple_fee(self, repair_id=False, qty=0.0, price_unit=0.0):
# service = self.product_1
# return self.env['repair.fee'].create({
# 'name': 'PC Assemble + Custom (PC on Demand)',
# 'product_id': service.id,
# 'product_uom_qty': qty,
# 'product_uom': service.uom_id.id,
# 'price_unit': price_unit,
# 'repair_id': repair_id,
# 'company_id': self.env.company.id,
# })
def test_stock_move_lot_reservation(self):
self.repair_with_lot.action_validate()
# Start Repair
self.repair_with_lot.action_repair_start()
# check stock move status and lot_id
for move in self.repair_with_lot.mapped("stock_move_ids"):
self.assertEqual(
move.state,
"assigned",
"Generated stock move state should be assigned",
)
self.assertEqual(
move.move_line_ids.lot_id,
self.repair_with_lot.lot_id,
"Generated stock move lot_id should be the same as repair order",
)

0 comments on commit 8c18c88

Please sign in to comment.