mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[IMP] introduce fields in_force_same_lot and out_force_same_lot
Those fields in the rma.operation allows us to control if we want to ensure that the same lot as the one indicated in the RMA should be used in deliveries to customers and receipts from suppliers
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"name": "RMA (Return Merchandise Authorization)",
|
"name": "RMA (Return Merchandise Authorization)",
|
||||||
"version": "16.0.1.0.0",
|
"version": "16.0.1.1.0",
|
||||||
"license": "LGPL-3",
|
"license": "LGPL-3",
|
||||||
"category": "RMA",
|
"category": "RMA",
|
||||||
"summary": "Introduces the return merchandise authorization (RMA) process in odoo",
|
"summary": "Introduces the return merchandise authorization (RMA) process in odoo",
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
<field name="type">customer</field>
|
<field name="type">customer</field>
|
||||||
<field name="in_route_id" ref="rma.route_rma_customer" />
|
<field name="in_route_id" ref="rma.route_rma_customer" />
|
||||||
<field name="out_route_id" ref="rma.route_rma_customer" />
|
<field name="out_route_id" ref="rma.route_rma_customer" />
|
||||||
|
<field name="in_force_same_lot">True</field>
|
||||||
|
<field name="out_force_same_lot">False</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record id="rma_operation_supplier_replace" model="rma.operation">
|
<record id="rma_operation_supplier_replace" model="rma.operation">
|
||||||
@@ -18,6 +20,8 @@
|
|||||||
<field name="type">supplier</field>
|
<field name="type">supplier</field>
|
||||||
<field name="in_route_id" ref="rma.route_rma_supplier" />
|
<field name="in_route_id" ref="rma.route_rma_supplier" />
|
||||||
<field name="out_route_id" ref="rma.route_rma_supplier" />
|
<field name="out_route_id" ref="rma.route_rma_supplier" />
|
||||||
|
<field name="in_force_same_lot">False</field>
|
||||||
|
<field name="out_force_same_lot">True</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record id="rma_operation_ds_replace" model="rma.operation">
|
<record id="rma_operation_ds_replace" model="rma.operation">
|
||||||
|
|||||||
28
rma/migrations/16.0.1.1.0/post-migration.py
Normal file
28
rma/migrations/16.0.1.1.0/post-migration.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||||
|
import logging
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def _update_rma_operations(cr):
|
||||||
|
_logger.info(
|
||||||
|
"Updating rma operations to preset in_force_same_lot and out_force_same_lot"
|
||||||
|
)
|
||||||
|
cr.execute(
|
||||||
|
"""
|
||||||
|
UPDATE rma_operation
|
||||||
|
SET in_force_same_lot=True
|
||||||
|
WHERE type='customer';
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
cr.execute(
|
||||||
|
"""
|
||||||
|
UPDATE rma_operation
|
||||||
|
SET out_force_same_lot=True
|
||||||
|
WHERE type='supplier';
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def migrate(cr, version):
|
||||||
|
_update_rma_operations(cr)
|
||||||
@@ -94,3 +94,22 @@ class RmaOperation(models.Model):
|
|||||||
required=True,
|
required=True,
|
||||||
default=lambda self: self.env.user.company_id,
|
default=lambda self: self.env.user.company_id,
|
||||||
)
|
)
|
||||||
|
in_force_same_lot = fields.Boolean(
|
||||||
|
string="Force same lot in incoming shipments",
|
||||||
|
help="Forces the same lot to be used "
|
||||||
|
"in incoming pickings as the one indicated in the RMA",
|
||||||
|
)
|
||||||
|
out_force_same_lot = fields.Boolean(
|
||||||
|
string="Force same lot in outgoing shipments",
|
||||||
|
help="Forces the same lot to be used "
|
||||||
|
"in outgoing pickings as the one indicated in the RMA",
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.onchange("type")
|
||||||
|
def _onchange_type(self):
|
||||||
|
if self.type == "customer":
|
||||||
|
self.in_force_same_lot = True
|
||||||
|
self.out_force_same_lot = False
|
||||||
|
elif self.type == "supplier":
|
||||||
|
self.in_force_same_lot = False
|
||||||
|
self.out_force_same_lot = True
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ class StockMove(models.Model):
|
|||||||
not lot_id
|
not lot_id
|
||||||
and self.rma_line_id.lot_id
|
and self.rma_line_id.lot_id
|
||||||
and self.location_id.usage == "internal"
|
and self.location_id.usage == "internal"
|
||||||
|
and self.rma_line_id.operation_id.out_force_same_lot
|
||||||
):
|
):
|
||||||
# In supplier RMA deliveries we can only send the RMA lot/serial.
|
# In supplier RMA deliveries we can only send the RMA lot/serial.
|
||||||
lot_id = self.rma_line_id.lot_id
|
lot_id = self.rma_line_id.lot_id
|
||||||
@@ -88,6 +89,7 @@ class StockMove(models.Model):
|
|||||||
not lot_id
|
not lot_id
|
||||||
and self.rma_line_id.lot_id
|
and self.rma_line_id.lot_id
|
||||||
and self.location_id.usage == "internal"
|
and self.location_id.usage == "internal"
|
||||||
|
and self.rma_line_id.operation_id.out_force_same_lot
|
||||||
):
|
):
|
||||||
# In supplier RMA deliveries we can only send the RMA lot/serial.
|
# In supplier RMA deliveries we can only send the RMA lot/serial.
|
||||||
lot_id = self.rma_line_id.lot_id
|
lot_id = self.rma_line_id.lot_id
|
||||||
|
|||||||
@@ -53,6 +53,10 @@
|
|||||||
name="customer_to_supplier"
|
name="customer_to_supplier"
|
||||||
attrs="{'invisible':[('type', '=', 'supplier')]}"
|
attrs="{'invisible':[('type', '=', 'supplier')]}"
|
||||||
/>
|
/>
|
||||||
|
<field
|
||||||
|
name="in_force_same_lot"
|
||||||
|
groups="stock.group_production_lot"
|
||||||
|
/>
|
||||||
</group>
|
</group>
|
||||||
<group name="outbound" string="Outbound">
|
<group name="outbound" string="Outbound">
|
||||||
<field name="out_route_id" />
|
<field name="out_route_id" />
|
||||||
@@ -61,6 +65,10 @@
|
|||||||
name="supplier_to_customer"
|
name="supplier_to_customer"
|
||||||
attrs="{'invisible':[('type', '=', 'customer')]}"
|
attrs="{'invisible':[('type', '=', 'customer')]}"
|
||||||
/>
|
/>
|
||||||
|
<field
|
||||||
|
name="out_force_same_lot"
|
||||||
|
groups="stock.group_production_lot"
|
||||||
|
/>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
</sheet>
|
</sheet>
|
||||||
|
|||||||
@@ -210,15 +210,16 @@ class RmaMakePicking(models.TransientModel):
|
|||||||
else:
|
else:
|
||||||
pickings = self.mapped("item_ids.line_id")._get_in_pickings()
|
pickings = self.mapped("item_ids.line_id")._get_in_pickings()
|
||||||
action = self.item_ids.line_id.action_view_in_shipments()
|
action = self.item_ids.line_id.action_view_in_shipments()
|
||||||
# Force the reservation of the RMA specific lot for incoming shipments.
|
|
||||||
# FIXME: still needs fixing, not reserving appropriate serials.
|
|
||||||
for move in pickings.move_ids.filtered(
|
for move in pickings.move_ids.filtered(
|
||||||
lambda x: x.state not in ("draft", "cancel", "done", "waiting")
|
lambda x: x.state not in ("draft", "cancel", "done", "waiting")
|
||||||
and x.rma_line_id
|
and x.rma_line_id
|
||||||
and x.product_id.tracking in ("lot", "serial")
|
and x.product_id.tracking in ("lot", "serial")
|
||||||
and x.rma_line_id.lot_id
|
and x.rma_line_id.lot_id
|
||||||
|
and x.rma_line_id.operation_id.in_force_same_lot
|
||||||
|
and x.location_dest_id.usage == "internal"
|
||||||
):
|
):
|
||||||
# Force the reservation of the RMA specific lot for incoming shipments.
|
# Force the reservation of the RMA specific lot for incoming shipments if required.
|
||||||
move.move_line_ids.unlink()
|
move.move_line_ids.unlink()
|
||||||
if move.product_id.tracking == "serial":
|
if move.product_id.tracking == "serial":
|
||||||
move.write(
|
move.write(
|
||||||
@@ -226,14 +227,10 @@ class RmaMakePicking(models.TransientModel):
|
|||||||
"lot_ids": [(6, 0, move.rma_line_id.lot_id.ids)],
|
"lot_ids": [(6, 0, move.rma_line_id.lot_id.ids)],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
quants = self.env["stock.quant"]._gather(
|
|
||||||
move.product_id, move.location_id, lot_id=move.rma_line_id.lot_id
|
|
||||||
)
|
|
||||||
move.move_line_ids.write(
|
move.move_line_ids.write(
|
||||||
{
|
{
|
||||||
"reserved_uom_qty": 1 if picking_type == "incoming" else 0,
|
"reserved_uom_qty": 1,
|
||||||
"qty_done": 0,
|
"qty_done": 0,
|
||||||
"package_id": len(quants) == 1 and quants.package_id.id,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
elif move.product_id.tracking == "lot":
|
elif move.product_id.tracking == "lot":
|
||||||
@@ -251,10 +248,11 @@ class RmaMakePicking(models.TransientModel):
|
|||||||
"lot_id": move.rma_line_id.lot_id.id,
|
"lot_id": move.rma_line_id.lot_id.id,
|
||||||
"product_uom_id": move.product_id.uom_id.id,
|
"product_uom_id": move.product_id.uom_id.id,
|
||||||
"qty_done": 0,
|
"qty_done": 0,
|
||||||
"reserved_uom_qty": qty if picking_type == "incoming" else 0,
|
"reserved_uom_qty": qty,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
move_line_model.create(move_line_data)
|
move_line_model.create(move_line_data)
|
||||||
|
|
||||||
pickings.with_context(force_no_bypass_reservation=True).action_assign()
|
pickings.with_context(force_no_bypass_reservation=True).action_assign()
|
||||||
return action
|
return action
|
||||||
|
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ class TestRmaPutAway(common.SingleTransactionCase):
|
|||||||
"put_away_location_id": cls.put_away_loc.id,
|
"put_away_location_id": cls.put_away_loc.id,
|
||||||
"in_route_id": cls.rma_route_cust.id,
|
"in_route_id": cls.rma_route_cust.id,
|
||||||
"out_route_id": cls.rma_route_cust.id,
|
"out_route_id": cls.rma_route_cust.id,
|
||||||
|
"out_force_same_lot": True,
|
||||||
|
"in_force_same_lot": True,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
cls.operation_2 = cls.rma_op_obj.create(
|
cls.operation_2 = cls.rma_op_obj.create(
|
||||||
@@ -97,6 +99,8 @@ class TestRmaPutAway(common.SingleTransactionCase):
|
|||||||
"put_away_location_id": cls.put_away_loc.id,
|
"put_away_location_id": cls.put_away_loc.id,
|
||||||
"in_route_id": cls.rma_route_cust.id,
|
"in_route_id": cls.rma_route_cust.id,
|
||||||
"out_route_id": cls.rma_route_cust.id,
|
"out_route_id": cls.rma_route_cust.id,
|
||||||
|
"out_force_same_lot": True,
|
||||||
|
"in_force_same_lot": True,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user