Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4768 Lượt xem

Hello All,

I try to applied domain for many2one type field. But i find following Error:

TypeError: district.district(11,) is not JSON serializable

My Onchange function code is here:

@api.onchange('district_table_case')

    def _onchange_district_table(self):

        print "A:", self.district_table_case.district_mainn

        print "B:", self.district_table_case.district_ss

        #print "C:", self.district_table_case.district_ss.district

        rec = self.district_table_case.district_ss

        res = self.district_table_case.district_mainn

        print "res:", res

        for vals in rec:

            print "C:", vals

            print "D:", vals.district

            if vals.district:

                return {'domain': {'district_table': [('id', 'in', vals)]}}

            else:

                return {'domain': {'district_table': []}}


district_table_case = fields.Many2one('district.districe.code', change_default=True, default=_onchange_district_table)

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Instead of browsable record make them vals in [1,2,3,4]
Now your code evaluates like vals in [district.district(11,), district.district(12,), district.district(13,)]
so make the vals as vals = [v.id for v in vals]

so you should  return {'domain': {'district_table': [('id', 'in', [v.id for v in vals])]}}

Ảnh đại diện
Huỷ bỏ
Tác giả

Hello Hilar,

I have a problem related to return value. Here is the link for problem.

https://www.odoo.com/forum/help-1/question/how-to-add-multiple-fields-values-in-single-many2many-field-in-odoov10-125028

Thanks in advance.

Tác giả Câu trả lời hay nhất

Hello Hilar,

My domain code work well for English Language. But, When i select Chinese Language then it shows error.

Here i attach screenshot of Error:

Ảnh đại diện
Huỷ bỏ

try to print the chinese words by typecasting to unicode,

Tác giả

Sorry, How i do this? any suggestions?

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 19
3899
0
thg 10 17
2918
2
thg 7 25
599
0
thg 12 24
1185
2
thg 10 24
1325