Skip to content

Commit

Permalink
[IMP] rma_lot: add onchange lot&product
Browse files Browse the repository at this point in the history
  • Loading branch information
sbejaoui committed Oct 17, 2024
1 parent c44de13 commit 3a71bc9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
21 changes: 20 additions & 1 deletion rma_lot/models/rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ class Rma(models.Model):

_inherit = "rma"

lot_id = fields.Many2one(comodel_name="stock.lot", string="Lot/Serial Number")
lot_id = fields.Many2one(
comodel_name="stock.lot",
string="Lot/Serial Number",
domain="[('product_id', '=?', product_id)]",
compute="_compute_lot_id",
store=True,
readonly=False,
)
lots_visible = fields.Boolean(compute="_compute_lots_visible")

@api.depends("product_id.tracking")
Expand All @@ -20,3 +27,15 @@ def _prepare_reception_procurement_vals(self, group=None):
vals = super()._prepare_reception_procurement_vals(group=group)
vals["restrict_lot_id"] = self.lot_id.id
return vals

@api.depends("move_id", "lot_id")
def _compute_product_id(self):
res = super()._compute_product_id()
for rec in self:
if not rec.move_id and rec.lot_id:
self.product_id = rec.lot_id.product_id
return res

@api.depends("product_id")
def _compute_lot_id(self):
self.update({"lot_id": False})
8 changes: 8 additions & 0 deletions rma_lot/tests/test_rma_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,11 @@ def test_00(self):
self.assertEqual(rma_lot_2.reception_move_id.restrict_lot_id, self.lot_2)
self.assertEqual(rma_lot_2.reception_move_id.state, "assigned")
self.assertEqual(rma_lot_2.reception_move_id.move_line_ids.lot_id, self.lot_2)

def test_rma_form(self):
rma_form = Form(self.env["rma"])
self.assertFalse(rma_form.product_id)
rma_form.lot_id = self.lot_1
self.assertEqual(rma_form.product_id, self.product)
rma_form.product_id = self.env.ref("product.product_product_4")
self.assertFalse(rma_form.lot_id)
1 change: 0 additions & 1 deletion rma_sale_lot/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import sale_order_rma_wizard
from . import sale_order_line_rma_wizard
9 changes: 0 additions & 9 deletions rma_sale_lot/wizards/sale_order_rma_wizard.py

This file was deleted.

0 comments on commit 3a71bc9

Please sign in to comment.