diff --git a/rma_account/wizards/rma_refund.py b/rma_account/wizards/rma_refund.py index 46320a113..a75856363 100644 --- a/rma_account/wizards/rma_refund.py +++ b/rma_account/wizards/rma_refund.py @@ -59,7 +59,7 @@ def default_get(self, fields_list): items = [] if active_model == "rma.order": rma = rma_obj.browse(active_ids) - lines = rma.rma_line_ids + lines = rma.rma_line_ids.filtered(lambda x: x.qty_to_refund > 0) else: lines = rma_line_obj.browse(active_ids) if len(lines.mapped("partner_id")) > 1: @@ -105,16 +105,9 @@ def compute_refund(self): return new_refund def invoice_refund(self): - rma_line_obj = self.env["rma.order.line"] - rma_obj = self.env["rma.order"] - active_ids = self.env.context.get("active_ids") or [] - active_model = self.env.context.get("active_model") - if active_model == "rma.order": - rma = rma_obj.browse(active_ids) - lines = rma.rma_line_ids - else: - lines = rma_line_obj.browse(active_ids) + lines = self.item_ids.line_id for line in lines: + if line.state != "approved": raise ValidationError(_("RMA %s is not approved") % line.name) new_invoice = self.compute_refund() diff --git a/rma_sale/wizards/rma_make_sale_order.py b/rma_sale/wizards/rma_make_sale_order.py index b2e58dab7..f8296c09e 100644 --- a/rma_sale/wizards/rma_make_sale_order.py +++ b/rma_sale/wizards/rma_make_sale_order.py @@ -61,7 +61,7 @@ def default_get(self, fields_list): items = [] if active_model == "rma.order": rma = rma_obj.browse(active_ids) - lines = rma.rma_line_ids + lines = rma.rma_line_ids.filtered(lambda x: x.qty_to_sell > 0) else: lines = rma_line_obj.browse(active_ids) for line in lines: @@ -161,9 +161,7 @@ class RmaLineMakeSaleOrderItem(models.TransientModel): _description = "RMA Line Make Sale Order Item" wiz_id = fields.Many2one(comodel_name="rma.make.sale.order", string="Wizard") - line_id = fields.Many2one( - comodel_name="rma.order.line", string="RMA Line", compute="_compute_line_id" - ) + line_id = fields.Many2one(comodel_name="rma.order.line", string="RMA Line") rma_id = fields.Many2one( comodel_name="rma.order", related="line_id.rma_id", readonly=False ) @@ -176,21 +174,6 @@ class RmaLineMakeSaleOrderItem(models.TransientModel): ) free_of_charge = fields.Boolean(string="Free of Charge") - def _compute_line_id(self): - rma_line_obj = self.env["rma.order.line"] - rma_obj = self.env["rma.order"] - active_ids = self.env.context.get("active_ids") or [] - active_model = self.env.context.get("active_model") - for rec in self: - if not active_ids: - return - if active_model == "rma.order": - rma = rma_obj.browse(active_ids) - lines = rma.rma_line_ids - else: - lines = rma_line_obj.browse(active_ids) - rec.line_id = lines[0] - @api.onchange("product_id") def onchange_product_id(self): if self.product_id: