如何按Odoo OCA小部件web_widget_x2many_2d_matrix中的名称序列排序记录?

Mar*_*elo 11 javascript python odoo

我已经尝试没有成功按顺序排序jquery的记录字典我不知道在哪里再次按名称排序.

我问社区git但没有人回答我,我试图按照odoo序列排序.使用模块web_widget_x2many_2d_matrix和sale_order_variant_mgmt

我修改python代码,如果我调试记录列表排序是预期的,但是当加载javascript代码时,它按名称排序并且无法调试问题所在的位置

@api.onchange('product_tmpl_id')
    def _onchange_product_tmpl_id(self):
        self.variant_line_ids = [(6, 0, [])]
        template = self.product_tmpl_id
        context = self.env.context
        record = self.env[context['active_model']].browse(context['active_id'])
        if context['active_model'] == 'sale.order.line' or context['active_model'] == 'sale.order.line_group': #TODO check this modify for lentex group_sale_lines module
            sale_order = record.order_id
        else:
            sale_order = record

        num_attrs = len(template.attribute_line_ids)
        if not template or not num_attrs:
            return
        line_x = template.attribute_line_ids[0]
        line_y = False if num_attrs == 1 else template.attribute_line_ids[1]
        lines = []

        for value_x in line_x.value_ids.sorted(key=lambda r: r.sequence):  
            for value_y in line_y and line_y.value_ids.sorted(key=lambda r: r.sequence) or [False]: #I modify this and in python the sort is the intended, but not in JS
                # Filter the corresponding product for that values
                values = value_x
                if value_y:
                    values += value_y
                product = template.product_variant_ids.filtered(lambda x: not(values - x.attribute_value_ids))[:1]
                order_line = sale_order.order_line.filtered(lambda x: x.product_id == product)[:1]
                lines.append((0, 0, {
                    'product_id': product,
                    'disabled': not bool(product),
                    'value_x': value_x,
                    'value_y': value_y,
                    'product_uom_qty': order_line.product_uom_qty,
                }))
        self.variant_line_ids = lines
Run Code Online (Sandbox Code Playgroud)

我认为问题出在这里

 // get x axis values in the correct order
        get_x_axis_values: function()
        {
            return _.keys(this.by_x_axis); //I think here is where the order is defined
        },
        // get y axis values in the correct order
        get_y_axis_values: function()
        {
            return _.keys(this.by_y_axis); //I think here is where the order is defined
        },
Run Code Online (Sandbox Code Playgroud)

Sch*_*ton 1

看起来就像您对字典进行排序,但字典没有或不维护顺序。

创建一个临时列表以根据值按顺序保存键值,然后迭代该列表以按所需顺序处理字典值。

或者你可以在 python 中使用“OrderedDict” from collections import OrderedDict