تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
13479 أدوات العرض

Hello all,

I'm in odoo 8.

I use this line in a report template to sort products by default code :

<t t-foreach="docs.sorted(key=lambda x: x.default_code)" t-as="product">


It works well, but products are sorted like this (product with first letter in lowercase at the end...) :

AA0001
BB0001
WW0009
aa0002

bb0001

But I would want products sorted like this instead :

AA0001

aa0002
BB0001
bb0001
WW0009


or like this :

AA0001

aa0002
bb0001

BB0001
WW0009


Thanks to help!


EDIT #1

I have tried many ways to include the lower() function in my qweb line, no success. How should I use the lower() function?

For example :

 <t t-foreach="docs.sorted(key=lambda x: (x.default_code).lower())" t-as="product">
<t t-foreach="docs.sorted(key=lambda x: x.default_code.lower)" t-as="product">
<t t-foreach="docs.sorted(key=lambda x: lower(x.default_code))" t-as="product">
<t t-foreach="docs.sorted(key=lambda x: x.default_code.lower())" t-as="product">

etc...


الصورة الرمزية
إهمال
الكاتب أفضل إجابة

I managed to fix this problem!

The problem was that the default_code field on product.template model is a not stored related field. So, sorting records according to this field didn't work properly.

So, I have overrided the default_code field to store it in the database :

from openerp import models, fields, api
class product_template(models.Model):
    _inherit = "product.template"
      
    default_code = fields.Char(related='product_variant_ids.default_code',
        string='Internal Reference of the first variant of this product', store=True)


After this, my qweb line works properly! Even with the lower() function in it!

<t t-foreach="docs.sorted(key=lambda x: x.default_code.lower())" t-as="product">


Thanks all!


الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يناير 19
8020
0
ديسمبر 24
594
0
ديسمبر 24
539
2
يوليو 24
2000
2
مارس 22
11286