mirror of
https://github.com/OCA/rma.git
synced 2025-02-16 17:11:47 +02:00
[IMP] rma_lot: add onchange lot&product
This commit is contained in:
@@ -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 @@ class Rma(models.Model):
|
||||
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})
|
||||
|
||||
@@ -93,3 +93,11 @@ class TestRMALot(TransactionCase):
|
||||
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,2 +1 @@
|
||||
from . import sale_order_rma_wizard
|
||||
from . import sale_order_line_rma_wizard
|
||||
|
||||
@@ -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"
|
||||
Reference in New Issue
Block a user