Skip to content

Commit

Permalink
[FIX] rma: Do not set 'Destination Package' if RMA package comes from…
Browse files Browse the repository at this point in the history
… 'Customers' location
  • Loading branch information
BernatPForgeFlow authored and AaronHForgeFlow committed May 8, 2024
1 parent ab02ca6 commit 6fab740
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions rma/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from . import rma_order_line
from . import rma_operation
from . import stock_move
from . import stock_quant_package
from . import stock_warehouse
from . import product
from . import product_category
Expand Down
14 changes: 14 additions & 0 deletions rma/models/stock_quant_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (C) 2023 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)

from odoo import models


class QuantPackage(models.Model):
_inherit = "stock.quant.package"

def _allowed_to_move_between_transfers(self):
res = super()._allowed_to_move_between_transfers()
return res and self.location_id != self.env.ref(
"stock.stock_location_customers"
)
11 changes: 6 additions & 5 deletions rma/wizards/rma_make_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def action_create_picking(self):
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_lines.filtered(
for move in pickings.move_ids.filtered(
lambda x: x.state not in ("draft", "cancel", "done", "waiting")
and x.rma_line_id
and x.product_id.tracking in ("lot", "serial")
Expand All @@ -232,27 +232,28 @@ def action_create_picking(self):
)
move.move_line_ids.write(
{
"product_uom_qty": 1 if picking_type == "incoming" else 0,
"reserved_uom_qty": 1 if picking_type == "incoming" else 0,
"qty_done": 0,
"package_id": len(quants) == 1 and quants.package_id.id,
}
)
elif move.product_id.tracking == "lot":
if picking_type == "incoming":
qty = self.item_ids.filtered(
lambda x: x.line_id.id == move.rma_line_id.id
lambda x, move=move: x.line_id.id == move.rma_line_id.id
).qty_to_receive

else:
qty = self.item_ids.filtered(
lambda x: x.line_id.id == move.rma_line_id.id
lambda x, move=move: x.line_id.id == move.rma_line_id.id
).qty_to_deliver
move_line_data = move._prepare_move_line_vals()
move_line_data.update(
{
"lot_id": move.rma_line_id.lot_id.id,
"product_uom_id": move.product_id.uom_id.id,
"qty_done": 0,
"product_uom_qty": qty if picking_type == "incoming" else 0,
"reserved_uom_qty": qty if picking_type == "incoming" else 0,
}
)
move_line_model.create(move_line_data)
Expand Down

0 comments on commit 6fab740

Please sign in to comment.