Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
1426 มุมมอง

I have a float field called "price". I want to import the data from spreadsheet. the data is from user. assume the data is not clean and need to be handled first, how can I handle if there is foreign symbol in the data?


for example. in the first row, the price should be empty. but the user fill it with "-". then this error should appear "Column price contains incorrect values (value: -)"


before it tries to test, I want to handle it first by replacing all characters into either empty or numeric


I already tried this


    @api.model
    def create(self, vals_list):
        for val in vals_list:
            for v in val:
                if val[v] in ['-', ' ']:
                    val[v] = ''

but the error when importing still appear



อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

It is a float field so try to update it with 0.0

you can re-write the code like this


@api.model

    def create(self, vals_list):

        for val in vals_list:

            for v in val:

                if val[v] in ['-', ' ']:

                    val[v] = 0.0


or try to update the spreadsheet value as 0.0 ie replace the - value with 0.0


Hope it helps

อวตาร
ละทิ้ง
ผู้เขียน

Thanks for the reply. Your answer is indeed working and I tested it. But after several days, I found that I only need to change from @api.model to @api.model_create_multi. And it's working as well.

Both is working. I don't know which is more proper

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.ค. 25
1857
4
เม.ย. 25
7846
8
ม.ค. 25
6848
bug saving on spreadsheet document แก้ไขแล้ว
9
เม.ย. 25
3995
Multiple Vendor lines after imports แก้ไขแล้ว
1
เม.ย. 25
1533