From 1fbbf0f1e0abe3267a485f89308b50c061b7d1e8 Mon Sep 17 00:00:00 2001 From: AaronHForgeFlow Date: Mon, 6 May 2024 18:32:05 +0200 Subject: [PATCH] [FIX] rma_sale: name_search migration & convert name_get to compute_diplay_name --- rma_sale/models/sale_order_line.py | 57 +++++++++++++----------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/rma_sale/models/sale_order_line.py b/rma_sale/models/sale_order_line.py index 60665dd94..61574dbb9 100644 --- a/rma_sale/models/sale_order_line.py +++ b/rma_sale/models/sale_order_line.py @@ -1,35 +1,30 @@ # Copyright 2020 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import api, fields, models +from odoo.osv import expression class SaleOrderLine(models.Model): _inherit = "sale.order.line" + _rec_names_search = ["name", "order_id"] @api.model - def name_search(self, name="", args=None, operator="ilike", limit=100): - """Allows to search by SO reference.""" - if not args: - args = [] - args += [ - "|", - (self._rec_name, operator, name), - ("order_id.name", operator, name), - ] - return super().name_search(name=name, args=args, operator=operator, limit=limit) - - @api.model - def _name_search( - self, name="", args=None, operator="ilike", limit=100, name_get_uid=None - ): - """Typed text is cleared here for better extensibility.""" - return super()._name_search( - name="", - args=args, - operator=operator, - limit=limit, - name_get_uid=name_get_uid, - ) + def _name_search(self, name, domain=None, operator="ilike", limit=None, order=None): + domain = domain or [] + if self.env.context.get("rma"): + domain = expression.AND([domain, [("display_type", "=", False)]]) + lines = self.search([("order_id.name", operator, name)] + domain, limit=limit) + if limit: + limit_rest = limit - len(lines) + else: + # limit can be 0 or None representing infinite + limit_rest = limit + if limit_rest or not limit: + domain += [("id", "in", lines.ids)] + return super()._name_search( + name, domain=domain, operator=operator, limit=limit_rest, order=order + ) + return self._search(domain, limit=limit, order=order) def _get_sale_line_rma_name_get_label(self): self.ensure_one() @@ -40,19 +35,17 @@ def _get_sale_line_rma_name_get_label(self): self.product_uom_qty, ) - def name_get(self): - res = [] - if self.env.context.get("rma"): + def _compute_display_name(self): + if not self.env.context.get("rma"): + return super()._compute_display_name() + for sale_line in self: for sale_line in self: if sale_line.order_id.name: - res.append( - (sale_line.id, sale_line._get_sale_line_rma_name_get_label()) + sale_line.display_name = ( + sale_line._get_sale_line_rma_name_get_label() ) else: - res.append(super(SaleOrderLine, sale_line).name_get()[0]) - return res - else: - return super().name_get() + return super(SaleOrderLine, sale_line)._compute_display_name() rma_line_id = fields.Many2one( comodel_name="rma.order.line", string="RMA", ondelete="restrict", copy=False