mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[FIX] rma_scrap: minor lint error
[FIX] rma_scrap: ensure scrapping serials will scrap just 1 unit & ensure scrapped quantity is always positve [FIX] rma_scrap: scrap quantity should consider the quantity in the stock moves not the product_uom_qty [IMP] rma_scrap: test serial case
This commit is contained in:
@@ -19,5 +19,6 @@ class RmaOperation(models.Model):
|
|||||||
scrap_location_id = fields.Many2one(
|
scrap_location_id = fields.Many2one(
|
||||||
comodel_name="stock.location",
|
comodel_name="stock.location",
|
||||||
string="Scrap Destination Location",
|
string="Scrap Destination Location",
|
||||||
domain="[('scrap_location', '=', True), ('company_id', 'in', [company_id, False])]",
|
domain="[('scrap_location', '=', True),"
|
||||||
|
"('company_id', 'in', [company_id, False])]",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class RmaOrderLine(models.Model):
|
|||||||
for move in rec.move_ids.filtered(
|
for move in rec.move_ids.filtered(
|
||||||
lambda m: m.state in ["done"] and m.is_rma_scrap
|
lambda m: m.state in ["done"] and m.is_rma_scrap
|
||||||
):
|
):
|
||||||
qty += product_obj._compute_quantity(move.product_uom_qty, rec.uom_id)
|
qty += product_obj._compute_quantity(move.quantity, rec.uom_id)
|
||||||
rec.qty_scrap = qty
|
rec.qty_scrap = qty
|
||||||
|
|
||||||
def _compute_scrap_count(self):
|
def _compute_scrap_count(self):
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from odoo.exceptions import ValidationError
|
||||||
from odoo.tests import common
|
from odoo.tests import common
|
||||||
|
|
||||||
|
|
||||||
@@ -32,7 +33,14 @@ class TestRmaScrap(common.SingleTransactionCase):
|
|||||||
"tracking": "lot",
|
"tracking": "lot",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
cls.product_3 = cls.product_obj.create(
|
||||||
|
{
|
||||||
|
"name": "Test Product 3",
|
||||||
|
"type": "product",
|
||||||
|
"list_price": 150.0,
|
||||||
|
"tracking": "serial",
|
||||||
|
}
|
||||||
|
)
|
||||||
cls.lot = cls.env["stock.lot"].create(
|
cls.lot = cls.env["stock.lot"].create(
|
||||||
{
|
{
|
||||||
"name": "Lot for tests",
|
"name": "Lot for tests",
|
||||||
@@ -40,6 +48,13 @@ class TestRmaScrap(common.SingleTransactionCase):
|
|||||||
"company_id": cls.env.ref("base.main_company").id,
|
"company_id": cls.env.ref("base.main_company").id,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
cls.serial_p3 = cls.env["stock.lot"].create(
|
||||||
|
{
|
||||||
|
"name": "Serial for tests",
|
||||||
|
"product_id": cls.product_3.id,
|
||||||
|
"company_id": cls.env.ref("base.main_company").id,
|
||||||
|
}
|
||||||
|
)
|
||||||
cls.wh = cls.env.ref("stock.warehouse0")
|
cls.wh = cls.env.ref("stock.warehouse0")
|
||||||
cls.stock_rma_location = cls.wh.lot_rma_id
|
cls.stock_rma_location = cls.wh.lot_rma_id
|
||||||
cls.scrap_loc = cls.env["stock.location"].create(
|
cls.scrap_loc = cls.env["stock.location"].create(
|
||||||
@@ -77,6 +92,14 @@ class TestRmaScrap(common.SingleTransactionCase):
|
|||||||
"out_route_id": cls.rma_route_cust.id,
|
"out_route_id": cls.rma_route_cust.id,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
# add somne qty or we cannot scrap
|
||||||
|
cls.env["stock.quant"].create(
|
||||||
|
{
|
||||||
|
"product_id": cls.product_1.id,
|
||||||
|
"location_id": cls.stock_rma_location.id,
|
||||||
|
"inventory_quantity": 1,
|
||||||
|
}
|
||||||
|
).action_apply_inventory()
|
||||||
|
|
||||||
def test_01_rma_scrap_received(self):
|
def test_01_rma_scrap_received(self):
|
||||||
rma = self.rma_line_obj.create(
|
rma = self.rma_line_obj.create(
|
||||||
@@ -184,12 +207,78 @@ class TestRmaScrap(common.SingleTransactionCase):
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
).create({})
|
).create({})
|
||||||
|
wizard.item_ids[0].qty_to_scrap = 1
|
||||||
action = wizard.action_create_scrap()
|
action = wizard.action_create_scrap()
|
||||||
scrap = self.env["stock.scrap"].browse([action["res_id"]])
|
scrap = self.env["stock.scrap"].browse([action["res_id"]])
|
||||||
self.assertEqual(scrap.location_id.id, self.stock_rma_location.id)
|
self.assertEqual(scrap.location_id.id, self.stock_rma_location.id)
|
||||||
self.assertEqual(scrap.move_ids.id, False)
|
self.assertEqual(scrap.move_ids.id, False)
|
||||||
self.assertEqual(rma.qty_in_scrap, 1.00)
|
self.assertEqual(rma.qty_in_scrap, 1.00)
|
||||||
res = scrap.action_validate()
|
res = scrap.action_validate()
|
||||||
scrap.do_scrap()
|
|
||||||
self.assertTrue(res)
|
self.assertTrue(res)
|
||||||
self.assertEqual(rma.qty_scrap, 1.00)
|
self.assertEqual(rma.qty_scrap, 1.00)
|
||||||
|
|
||||||
|
def test_03_rma_scrap_lot(self):
|
||||||
|
rma = self.rma_line_obj.create(
|
||||||
|
{
|
||||||
|
"partner_id": self.customer1.id,
|
||||||
|
"product_id": self.product_3.id,
|
||||||
|
"operation_id": self.operation_1.id,
|
||||||
|
"uom_id": self.product_1.uom_id.id,
|
||||||
|
"in_route_id": self.operation_1.in_route_id.id,
|
||||||
|
"out_route_id": self.operation_1.out_route_id.id,
|
||||||
|
"in_warehouse_id": self.operation_1.in_warehouse_id.id,
|
||||||
|
"out_warehouse_id": self.operation_1.out_warehouse_id.id,
|
||||||
|
"location_id": self.stock_rma_location.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
rma._onchange_operation_id()
|
||||||
|
rma.action_rma_to_approve()
|
||||||
|
wizard = self.rma_make_picking.with_context(
|
||||||
|
**{
|
||||||
|
"active_ids": rma.id,
|
||||||
|
"active_model": "rma.order.line",
|
||||||
|
"picking_type": "incoming",
|
||||||
|
"active_id": 1,
|
||||||
|
}
|
||||||
|
).create({})
|
||||||
|
|
||||||
|
self.assertEqual(rma.qty_to_receive, 1.00)
|
||||||
|
self.assertFalse(rma.qty_to_scrap)
|
||||||
|
|
||||||
|
action_picking = wizard.action_create_picking()
|
||||||
|
picking = self.env["stock.picking"].browse([action_picking["res_id"]])
|
||||||
|
picking.move_line_ids[0].quantity = rma.qty_to_receive
|
||||||
|
picking.move_line_ids[0].lot_id = self.serial_p3
|
||||||
|
|
||||||
|
picking.button_validate()
|
||||||
|
rma._compute_qty_to_scrap()
|
||||||
|
|
||||||
|
self.assertFalse(rma.qty_to_receive)
|
||||||
|
self.assertEqual(rma.qty_received, 1.00)
|
||||||
|
self.assertEqual(rma.qty_to_scrap, 1.00)
|
||||||
|
wizard = self.rma_make_scrap_wiz.with_context(
|
||||||
|
**{
|
||||||
|
"active_ids": rma.id,
|
||||||
|
"active_model": "rma.order.line",
|
||||||
|
"item_ids": [
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
{
|
||||||
|
"line_id": rma.id,
|
||||||
|
"product_id": rma.product_id.id,
|
||||||
|
"product_qty": rma.product_qty,
|
||||||
|
"location_id": rma.location_id,
|
||||||
|
"qty_to_scrap": rma.qty_to_scrap,
|
||||||
|
"uom_id": rma.uom_id.id,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
).create({})
|
||||||
|
with self.assertRaises(ValidationError):
|
||||||
|
wizard.item_ids[0].qty_to_scrap = 0
|
||||||
|
action = wizard.action_create_scrap()
|
||||||
|
# now try to put more qty and check it is scrapped 1 anyway
|
||||||
|
wizard.item_ids[0].qty_to_scrap = 2
|
||||||
|
action = wizard.action_create_scrap()
|
||||||
|
scrap = self.env["stock.scrap"].browse([action["res_id"]])
|
||||||
|
self.assertEqual(scrap.scrap_qty, 1)
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ class RmaMakeScrap(models.TransientModel):
|
|||||||
def _create_scrap(self):
|
def _create_scrap(self):
|
||||||
scraps = []
|
scraps = []
|
||||||
for item in self.item_ids:
|
for item in self.item_ids:
|
||||||
|
if item.qty_to_scrap <= 0:
|
||||||
|
raise ValidationError(_("Quantity to scrap must be positive"))
|
||||||
line = item.line_id
|
line = item.line_id
|
||||||
if line.state != "approved":
|
if line.state != "approved":
|
||||||
raise ValidationError(_("RMA %s is not approved") % line.name)
|
raise ValidationError(_("RMA %s is not approved") % line.name)
|
||||||
@@ -68,12 +70,16 @@ class RmaMakeScrap(models.TransientModel):
|
|||||||
@api.model
|
@api.model
|
||||||
def _prepare_scrap(self, item):
|
def _prepare_scrap(self, item):
|
||||||
line = item.line_id
|
line = item.line_id
|
||||||
|
if item.line_id.product_id.tracking == "serial":
|
||||||
|
scrap_qty = 1
|
||||||
|
else:
|
||||||
|
scrap_qty = item.qty_to_scrap
|
||||||
scrap = self.env["stock.scrap"].create(
|
scrap = self.env["stock.scrap"].create(
|
||||||
{
|
{
|
||||||
"name": line.rma_id.id and line.rma_id.name or line.name,
|
"name": line.rma_id.id and line.rma_id.name or line.name,
|
||||||
"origin": line.name,
|
"origin": line.name,
|
||||||
"product_id": item.line_id.product_id.id,
|
"product_id": item.line_id.product_id.id,
|
||||||
"scrap_qty": item.qty_to_scrap,
|
"scrap_qty": scrap_qty,
|
||||||
"product_uom_id": item.line_id.product_id.product_tmpl_id.uom_id.id,
|
"product_uom_id": item.line_id.product_id.product_tmpl_id.uom_id.id,
|
||||||
"location_id": item.location_id.id,
|
"location_id": item.location_id.id,
|
||||||
"scrap_location_id": item.scrap_location_id.id,
|
"scrap_location_id": item.scrap_location_id.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user