mirror of
https://github.com/OCA/rma.git
synced 2025-02-16 17:11:47 +02:00
[IMP] rma_sale: Domains performance
For avoiding a big list of IDs being transferred when no sales order is selected on the RMA, we have changed domains to make use of the possibility of pyjs expressions allowed in the domains. No ternary operators nor list sums are allowed in pyjs, but using a combination of allowed IDs with a controlled length of values + and/or operators to switch domains is enough for having the right performance and avoid to depend on other modules like web_domain_field.
This commit is contained in:
@@ -21,7 +21,10 @@ class Rma(models.Model):
|
|||||||
comodel_name="stock.picking",
|
comodel_name="stock.picking",
|
||||||
compute="_compute_allowed_picking_ids",
|
compute="_compute_allowed_picking_ids",
|
||||||
)
|
)
|
||||||
picking_id = fields.Many2one(domain="[('id', 'in', allowed_picking_ids)]")
|
picking_id = fields.Many2one(
|
||||||
|
domain="(order_id or partner_id) and [('id', 'in', allowed_picking_ids)] or "
|
||||||
|
"[('state', '=', 'done'), ('picking_type_id.code', '=', 'outgoing')] "
|
||||||
|
)
|
||||||
allowed_move_ids = fields.Many2many(
|
allowed_move_ids = fields.Many2many(
|
||||||
comodel_name="sale.order.line",
|
comodel_name="sale.order.line",
|
||||||
compute="_compute_allowed_move_ids",
|
compute="_compute_allowed_move_ids",
|
||||||
@@ -34,18 +37,25 @@ class Rma(models.Model):
|
|||||||
comodel_name="product.product",
|
comodel_name="product.product",
|
||||||
compute="_compute_allowed_product_ids",
|
compute="_compute_allowed_product_ids",
|
||||||
)
|
)
|
||||||
product_id = fields.Many2one(domain="[('id', 'in', allowed_product_ids)]")
|
product_id = fields.Many2one(
|
||||||
|
domain="order_id and [('id', 'in', allowed_product_ids)] or "
|
||||||
|
"[('type', 'in', ['consu', 'product'])]"
|
||||||
|
)
|
||||||
|
|
||||||
@api.depends("partner_id", "order_id")
|
@api.depends("partner_id", "order_id")
|
||||||
def _compute_allowed_picking_ids(self):
|
def _compute_allowed_picking_ids(self):
|
||||||
domain = [("state", "=", "done"), ("picking_type_id.code", "=", "outgoing")]
|
domain = [("state", "=", "done"), ("picking_type_id.code", "=", "outgoing")]
|
||||||
for rec in self:
|
for rec in self:
|
||||||
|
domain2 = domain.copy()
|
||||||
if rec.partner_id:
|
if rec.partner_id:
|
||||||
commercial_partner = rec.partner_id.commercial_partner_id
|
commercial_partner = rec.partner_id.commercial_partner_id
|
||||||
domain.append(("partner_id", "child_of", commercial_partner.id))
|
domain2.append(("partner_id", "child_of", commercial_partner.id))
|
||||||
if rec.order_id:
|
if rec.order_id:
|
||||||
domain.append(("sale_id", "=", rec.order_id.id))
|
domain2.append(("sale_id", "=", rec.order_id.id))
|
||||||
rec.allowed_picking_ids = self.env["stock.picking"].search(domain)
|
if domain2 != domain:
|
||||||
|
rec.allowed_picking_ids = self.env["stock.picking"].search(domain2)
|
||||||
|
else:
|
||||||
|
rec.allowed_picking_ids = False # don't populate a big list
|
||||||
|
|
||||||
@api.depends("order_id", "picking_id")
|
@api.depends("order_id", "picking_id")
|
||||||
def _compute_allowed_move_ids(self):
|
def _compute_allowed_move_ids(self):
|
||||||
@@ -67,11 +77,7 @@ class Rma(models.Model):
|
|||||||
lambda r: r.type in ["consu", "product"]
|
lambda r: r.type in ["consu", "product"]
|
||||||
).ids
|
).ids
|
||||||
else:
|
else:
|
||||||
rec.allowed_product_ids = (
|
rec.allowed_product_ids = False # don't populate a big list
|
||||||
self.env["product.product"]
|
|
||||||
.search([("type", "in", ["consu", "product"])])
|
|
||||||
.ids
|
|
||||||
)
|
|
||||||
|
|
||||||
@api.onchange("partner_id")
|
@api.onchange("partner_id")
|
||||||
def _onchange_partner_id(self):
|
def _onchange_partner_id(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user