diff --git a/rma_lot/models/rma.py b/rma_lot/models/rma.py index faa7d7cb4..55d18a984 100644 --- a/rma_lot/models/rma.py +++ b/rma_lot/models/rma.py @@ -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") @@ -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}) diff --git a/rma_lot/tests/test_rma_lot.py b/rma_lot/tests/test_rma_lot.py index 5cd033e8a..7f16241b9 100644 --- a/rma_lot/tests/test_rma_lot.py +++ b/rma_lot/tests/test_rma_lot.py @@ -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) diff --git a/rma_sale_lot/wizards/__init__.py b/rma_sale_lot/wizards/__init__.py index dca5a8b16..8efcbacda 100644 --- a/rma_sale_lot/wizards/__init__.py +++ b/rma_sale_lot/wizards/__init__.py @@ -1,2 +1 @@ -from . import sale_order_rma_wizard from . import sale_order_line_rma_wizard diff --git a/rma_sale_lot/wizards/sale_order_rma_wizard.py b/rma_sale_lot/wizards/sale_order_rma_wizard.py deleted file mode 100644 index bdbf914ef..000000000 --- a/rma_sale_lot/wizards/sale_order_rma_wizard.py +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright 2024 ACSONE SA/NV -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - -from odoo import models - - -class SaleOrderRmaWizard(models.TransientModel): - - _inherit = "sale.order.rma.wizard"