Override _order on stock.move.line with stored Char fields so the server returns records in the correct order on initial load (default_order in the view only applies to interactive client-side sorting, not the initial fetch). Add product_name and partner_name stored related fields to avoid SQL JOINs in ORDER BY. Use the same fields in the view's default_order for consistency. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
78 lines
1.9 KiB
Python
78 lines
1.9 KiB
Python
# Copyright 2026 Criptomart
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
from odoo import api
|
|
from odoo import fields
|
|
from odoo import models
|
|
|
|
|
|
class StockMoveLine(models.Model):
|
|
_inherit = "stock.move.line"
|
|
_order = "product_categ_complete_name, product_name, partner_name, id"
|
|
|
|
product_categ_id = fields.Many2one(
|
|
comodel_name="product.category",
|
|
string="Product Category (Batch)",
|
|
related="product_id.categ_id",
|
|
store=True,
|
|
readonly=True,
|
|
)
|
|
|
|
product_categ_complete_name = fields.Char(
|
|
string="Product Category Path",
|
|
related="product_id.categ_id.complete_name",
|
|
store=True,
|
|
readonly=True,
|
|
)
|
|
|
|
product_name = fields.Char(
|
|
string="Product Name",
|
|
related="product_id.name",
|
|
store=True,
|
|
readonly=True,
|
|
)
|
|
|
|
partner_name = fields.Char(
|
|
string="Partner Name",
|
|
related="picking_id.partner_id.name",
|
|
store=True,
|
|
readonly=True,
|
|
)
|
|
|
|
product_default_code = fields.Char(
|
|
string="Product Code",
|
|
related="product_id.default_code",
|
|
readonly=True,
|
|
)
|
|
|
|
picking_partner_id = fields.Many2one(
|
|
related="picking_id.partner_id",
|
|
store=True,
|
|
readonly=True,
|
|
)
|
|
|
|
is_collected = fields.Boolean(
|
|
string="Collected",
|
|
default=False,
|
|
copy=False,
|
|
)
|
|
|
|
home_delivery = fields.Boolean(
|
|
related="picking_id.home_delivery",
|
|
readonly=True,
|
|
)
|
|
|
|
consumer_group_id = fields.Many2one(
|
|
comodel_name="res.partner",
|
|
compute="_compute_consumer_group_id",
|
|
readonly=True,
|
|
)
|
|
|
|
@api.depends("picking_id")
|
|
def _compute_consumer_group_id(self):
|
|
for line in self:
|
|
picking = line.picking_id
|
|
if picking:
|
|
line.consumer_group_id = picking.batch_consumer_group_id
|
|
else:
|
|
line.consumer_group_id = False
|