@@ -499,38 +499,45 @@ def payfit2pivot(self, fileobj):
499499 }
500500 res .append (vals )
501501 return res
502-
502+
503503 def cpt195txt2pivot (self , fileobj ):
504504 res = []
505505 i = 0
506506 file_content = base64 .decodebytes (self .file_to_import )
507507 file_content = file_content .decode ("latin1" )
508- file_lines = file_content [:- 4 ].split ("\r \n " )
508+ file_lines = file_content [:- 4 ].split ("\r \n " )
509509 for line in file_lines :
510510 i += 1
511- # Skip line that is not a detail of the account
511+ # Skip empty line
512+ if not line :
513+ continue
514+ # Skip line that is not a detail of the account
512515 if line [21 ] != 'D' :
513516 continue
514517 vals = {
515518 'journal' : line [16 :19 ],
516519 'account' : line [24 :36 ],
517- 'date' : datetime .strptime (line [22 :24 ] + line [12 :14 ] + line [158 :160 ] + line [14 :16 ], '%d%m%Y' ),
520+ "analytic" : line [36 :38 ] != "99" and line [36 :38 ],
521+ 'date' : datelib (
522+ year = int (line [158 :160 ] + line [14 :16 ]),
523+ month = int (line [12 :14 ]),
524+ day = int (line [22 :24 ]),
525+ ),
518526 'name' : line [80 :100 ],
519527 'ref' : line [140 :143 ],
520528 'line' : i ,
521529 }
522- if float (line [67 :80 ]) != 0.0 and float ( line [ 54 : 67 ]) != 0.0 :
523- vals_credit = vals_debit = vals
524- vals_debit [ ' credit' ] = 0.0
525- vals_debit [ 'debit' ] = float ( line [ 54 : 65 ] + '.' + line [ 65 : 67 ] )
526- res .append (vals_debit )
527- vals_credit [ 'credit' ] = float ( line [ 67 : 78 ] + '.' + line [ 78 : 80 ] )
528- vals_credit [ 'debit' ] = 0.0
529- res .append (vals_credit )
530+ credit = int (line [67 :80 ]) / 100.
531+ debit = int ( line [ 54 : 67 ]) / 100.
532+ if credit and debit :
533+ vals . update ({ "credit" : credit , "debit" : 0 } )
534+ res .append (vals )
535+ vals2 = vals . copy ( )
536+ vals2 . update ({ "credit" : 0 , "debit" : debit })
537+ res .append (vals2 )
530538 else :
531- vals ['debit' ] = float (line [54 :65 ] + '.' + line [65 :67 ])
532- vals ['credit' ] = float (line [67 :78 ] + '.' + line [78 :80 ])
533- res .append (vals )
539+ vals .update ({"credit" : credit , "debit" : debit })
540+ res .append (vals )
534541 return res
535542
536543 def _prepare_partner_speeddict (self , company_id ):
0 commit comments