Skip to content

Commit

Permalink
[FIX] rma_sale: name_search migration
Browse files Browse the repository at this point in the history
& convert name_get to compute_diplay_name
  • Loading branch information
AaronHForgeFlow committed Aug 8, 2024
1 parent 3452b4f commit 3b903d8
Showing 1 changed file with 25 additions and 32 deletions.
57 changes: 25 additions & 32 deletions rma_sale/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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
Expand Down

0 comments on commit 3b903d8

Please sign in to comment.