mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[IMP] rma: Added serial/lot selection on from stock move wizard on rma groups
- added restriction to approve rma with product tracking on serial, should be only one to receive
This commit is contained in:
committed by
Lois Rilo
parent
f4142e7964
commit
5684133be4
@@ -587,7 +587,19 @@ class RmaOrderLine(models.Model):
|
||||
self.reference_move_id = False
|
||||
return True
|
||||
|
||||
def _check_production_lot_assigned(self):
|
||||
for rec in self:
|
||||
if rec.product_id.tracking == "serial" and rec.product_qty != 1:
|
||||
raise ValidationError(
|
||||
_(
|
||||
"Product %s has serial tracking configuration, "
|
||||
"quantity to receive should be 1"
|
||||
)
|
||||
% (rec.product_id.display_name)
|
||||
)
|
||||
|
||||
def action_rma_to_approve(self):
|
||||
self._check_production_lot_assigned()
|
||||
self.write({"state": "to_approve"})
|
||||
for rec in self:
|
||||
if rec.product_id.rma_approval_policy == "one_step":
|
||||
|
||||
@@ -36,6 +36,27 @@ class RmaAddStockMove(models.TransientModel):
|
||||
string="Stock Moves",
|
||||
domain="[('state', '=', 'done')]",
|
||||
)
|
||||
show_lot_filter = fields.Boolean(
|
||||
string="Show lot filter?",
|
||||
compute="_compute_lot_domain",
|
||||
)
|
||||
lot_domain_ids = fields.Many2many(
|
||||
comodel_name="stock.production.lot",
|
||||
string="Lots Domain",
|
||||
compute="_compute_lot_domain",
|
||||
)
|
||||
|
||||
@api.depends(
|
||||
"move_ids.move_line_ids.lot_id",
|
||||
)
|
||||
def _compute_lot_domain(self):
|
||||
for rec in self:
|
||||
rec.lot_domain_ids = rec.mapped("move_ids.move_line_ids.lot_id").ids
|
||||
rec.show_lot_filter = bool(rec.lot_domain_ids)
|
||||
|
||||
lot_ids = fields.Many2many(
|
||||
comodel_name="stock.production.lot", string="Lots/Serials selected"
|
||||
)
|
||||
|
||||
def _prepare_rma_line_from_stock_move(self, sm, lot=False):
|
||||
if self.env.context.get("customer"):
|
||||
@@ -74,6 +95,15 @@ class RmaAddStockMove(models.TransientModel):
|
||||
raise ValidationError(
|
||||
_("Please define a warehouse with a default RMA location")
|
||||
)
|
||||
product_qty = sm.product_uom_qty
|
||||
if sm.product_id.tracking == "serial":
|
||||
product_qty = 1
|
||||
elif sm.product_id.tracking == "lot":
|
||||
product_qty = sum(
|
||||
sm.move_line_ids.filtered(lambda x: x.lot_id.id == lot.id).mapped(
|
||||
"qty_done"
|
||||
)
|
||||
)
|
||||
data = {
|
||||
"partner_id": self.partner_id.id,
|
||||
"reference_move_id": sm.id,
|
||||
@@ -82,7 +112,7 @@ class RmaAddStockMove(models.TransientModel):
|
||||
"origin": sm.picking_id.name or sm.name,
|
||||
"uom_id": sm.product_uom.id,
|
||||
"operation_id": operation.id,
|
||||
"product_qty": sm.product_uom_qty,
|
||||
"product_qty": product_qty,
|
||||
"delivery_address_id": sm.picking_id.partner_id.id,
|
||||
"rma_id": self.rma_id.id,
|
||||
"receipt_policy": operation.receipt_policy,
|
||||
@@ -110,15 +140,20 @@ class RmaAddStockMove(models.TransientModel):
|
||||
rma_line_obj = self.env["rma.order.line"]
|
||||
existing_stock_moves = self._get_existing_stock_moves()
|
||||
for sm in self.move_ids:
|
||||
if sm not in existing_stock_moves:
|
||||
tracking_move = sm.product_id.tracking in ("serial", "lot")
|
||||
if sm not in existing_stock_moves or tracking_move:
|
||||
if sm.product_id.tracking == "none":
|
||||
data = self._prepare_rma_line_from_stock_move(sm, lot=False)
|
||||
rma_line_obj.with_context(default_rma_id=self.rma_id.id).create(
|
||||
data
|
||||
)
|
||||
else:
|
||||
lot_ids = [x.lot_id.id for x in sm.move_line_ids if x.lot_id]
|
||||
data = self._prepare_rma_line_from_stock_move(sm, lot=lot_ids[0])
|
||||
for lot in sm.move_line_ids.mapped("lot_id").filtered(
|
||||
lambda x: x.id in self.lot_ids.ids
|
||||
):
|
||||
if lot.id in self.rma_id.rma_line_ids.mapped("lot_id").ids:
|
||||
continue
|
||||
data = self._prepare_rma_line_from_stock_move(sm, lot)
|
||||
rma_line_obj.with_context(default_rma_id=self.rma_id.id).create(
|
||||
data
|
||||
)
|
||||
|
||||
@@ -40,6 +40,20 @@
|
||||
<field name="state" />
|
||||
</tree>
|
||||
</field>
|
||||
<field name="show_lot_filter" invisible="1" />
|
||||
<field name="lot_domain_ids" widget="many2many_tags" invisible="1" />
|
||||
<label
|
||||
for="lot_ids"
|
||||
attrs="{'invisible': [('show_lot_filter', '=', False)]}"
|
||||
string="Create rma with lot/serials selected"
|
||||
/>
|
||||
<field
|
||||
name="lot_ids"
|
||||
widget="many2many_tags"
|
||||
domain="[('id', 'in', lot_domain_ids)]"
|
||||
attrs="{'invisible': [('show_lot_filter', '=', False)], 'required': [('show_lot_filter', '=', True)]}"
|
||||
options="{'no_create': True}"
|
||||
/>
|
||||
<footer>
|
||||
<button
|
||||
string="Confirm"
|
||||
|
||||
Reference in New Issue
Block a user