@@ -22,26 +22,17 @@ class DatevExportDtvfExport(models.Model):
2222 fiscalyear_id = fields .Many2one (
2323 "date.range" ,
2424 string = "Fiscal year" ,
25- states = {"draft" : [("required" , True ), ("readonly" , False )]},
26- readonly = True ,
27- )
28- name = fields .Char (
29- states = {"draft" : [("required" , True ), ("readonly" , False )]},
30- readonly = True ,
3125 )
26+ name = fields .Char ()
3227 fiscalyear_start = fields .Date (related = "fiscalyear_id.date_start" )
3328 fiscalyear_end = fields .Date (related = "fiscalyear_id.date_end" )
3429 period_ids = fields .Many2many (
3530 "date.range" ,
3631 string = "Periods" ,
37- states = {"draft" : [("required" , True ), ("readonly" , False )]},
38- readonly = True ,
3932 )
4033 journal_ids = fields .Many2many (
4134 "account.journal" ,
4235 string = "Journals" ,
43- states = {"draft" : [("readonly" , False )]},
44- readonly = True ,
4536 )
4637 date_generated = fields .Datetime ("Generated at" , readonly = True , copy = False )
4738 file_data = fields .Binary ("Data" , readonly = True , copy = False )
@@ -123,9 +114,8 @@ def action_generate(self):
123114 for move in moves :
124115 writer .writerows (this ._get_data_transaction (move ))
125116
126- filename = (
127- "EXTF_Buchungsstapel_%s.csv"
128- % date_range .date_start .strftime ("%Y%m%d" )
117+ filename = "EXTF_Buchungsstapel_{}.csv" .format (
118+ date_range .date_start .strftime ("%Y%m%d" )
129119 )
130120 zip_file .writestr (filename , writer .buffer .getvalue ())
131121
@@ -146,7 +136,7 @@ def action_generate(self):
146136
147137 accounts = self .env ["account.account" ].search (
148138 [
149- ("company_id " , "=" , this .company_id .id ),
139+ ("company_ids " , "=" , this .company_id .id ),
150140 ]
151141 )
152142 writer = DatevAccountWriter (
@@ -178,7 +168,8 @@ def _get_data_transaction(self, move):
178168 move_line2amount = {
179169 move_line : move_line .credit or move_line .debit
180170 for move_line in move .line_ids
181- if not move_line .display_type and (move_line .debit or move_line .credit )
171+ if not move_line .display_type .startswith ("line_" )
172+ and (move_line .debit or move_line .credit )
182173 }
183174 currency = move .currency_id or move .company_id .currency_id
184175 code_length = move .company_id .datev_account_code_length
@@ -199,10 +190,13 @@ def _get_data_transaction(self, move):
199190 if currency .is_zero (move_line2amount [move_line2 ]):
200191 move_line2amount .pop (move_line2 )
201192 break
202- if move_line .account_id .internal_type not in (
203- "receivable" ,
204- "payable" ,
205- ) and move_line2 .account_id .internal_type in ("receivable" , "payable" ):
193+ if move_line .account_id .account_type not in (
194+ "asset_receivable" ,
195+ "liability_payable" ,
196+ ) and move_line2 .account_id .account_type in (
197+ "asset_receivable" ,
198+ "liability_payable" ,
199+ ):
206200 move_line , move_line2 = move_line2 , move_line
207201 if move_line .account_id .datev_export_nonautomatic :
208202 move_line , move_line2 = move_line2 , move_line
@@ -215,10 +209,10 @@ def _get_data_transaction(self, move):
215209 )
216210 number_type = (
217211 "customer"
218- if ml .account_id .internal_type == "receivable "
212+ if ml .account_id .account_type == "asset_receivable "
219213 else (
220214 "supplier"
221- if ml .account_id .internal_type == "payable "
215+ if ml .account_id .account_type == "liability_payable "
222216 else None
223217 )
224218 )
@@ -231,7 +225,7 @@ def _get_data_transaction(self, move):
231225 else :
232226 offset_account_number = number
233227 data = {
234- "Umsatz (ohne Soll/Haben-Kz)" : ( "%.2f" % abs (amount )) .replace ("." , "," ),
228+ "Umsatz (ohne Soll/Haben-Kz)" : f" { abs (amount ):.2f } " .replace ("." , "," ),
235229 "Soll/Haben-Kennzeichen" : move_line .debit and "S" or "H" ,
236230 "Konto" : account_number ,
237231 "Gegenkonto (ohne BU-Schlüssel)" : offset_account_number ,
@@ -259,33 +253,28 @@ def _get_data_transaction(self, move):
259253 )[:1 ].name
260254 or move .name ,
261255 "Belegfeld 2" : move_line2 .name ,
262- "KOST1 - Kostenstelle" : move_line .analytic_account_id .code
263- or move_line .analytic_account_id .name
264- or move_line2 .analytic_account_id .code
265- or move_line2 .analytic_account_id .name ,
256+ "KOST1 - Kostenstelle" : move_line .analytic_line_ids [: 1 ]. account_id .code
257+ or move_line .analytic_line_ids [: 1 ]. account_id .name
258+ or move_line2 .analytic_line_ids [: 1 ]. account_id .code
259+ or move_line2 .analytic_line_ids [: 1 ]. account_id .name ,
266260 "KOST-Datum" : move .date .strftime ("%d%m%Y" ),
267261 }
268262 if move_line .amount_currency :
269263 factor = abs (amount / (move_line .debit or move_line .credit ))
264+ rate = 1 / currency ._get_conversion_rate (
265+ move_line .currency_id ,
266+ currency ,
267+ move .company_id ,
268+ move .date ,
269+ )
270270 data .update (
271271 {
272272 "Umsatz (ohne Soll/Haben-Kz)" : (
273- "%.2f" % abs (move_line .amount_currency * factor )
273+ f" { abs (move_line .amount_currency * factor ):.2f } "
274274 ).replace ("." , "," ),
275275 "WKZ Umsatz" : move_line .currency_id .name ,
276- "Kurs" : (
277- "%.6f"
278- % (
279- 1
280- / currency ._get_conversion_rate (
281- move_line .currency_id ,
282- currency ,
283- move .company_id ,
284- move .date ,
285- )
286- )
287- ).replace ("." , "," ),
288- "Basis-Umsatz" : ("%.2f" % abs (amount )).replace ("." , "," ),
276+ "Kurs" : f"{ rate :.6f} " .replace ("." , "," ),
277+ "Basis-Umsatz" : f"{ abs (amount ):.2f} " .replace ("." , "," ),
289278 "WKZ Basis-Umsatz" : currency .name ,
290279 }
291280 )
@@ -337,26 +326,27 @@ def _get_data_partner(self, partner):
337326 def _get_data_account (self , account ):
338327 yield {
339328 "Konto" : account .datev_code
340- or account .code [- account .company_id .datev_account_code_length :],
329+ or account .code [- self .company_id .datev_account_code_length :],
341330 "Kontobeschriftung" : account .name ,
342331 "SprachId" : self .env .user .lang .replace ("_" , "-" ),
343332 "Kontenbeschriftung lang" : account .name ,
344333 }
345334
346335 def _get_partner_number (self , partner , number_type , generate = False ):
347336 if self .company_id .datev_partner_numbering == "sequence" :
348- field_name = "l10n_de_datev_export_identifier_%s" % number_type
337+ field_name = f "l10n_de_datev_export_identifier_{ number_type } "
349338 if not partner [field_name ] and generate :
350339 getattr (
351340 partner ,
352- "action_l10n_de_datev_export_identifier_%s" % number_type ,
341+ f "action_l10n_de_datev_export_identifier_{ number_type } " ,
353342 )()
354343 return partner [field_name ]
355344 elif self .company_id .datev_partner_numbering == "ee" :
356345 account_length = self .env ["account.general.ledger" ]._get_account_length ()
357346 return partner [
358- "l10n_de_datev_identifier%s"
359- % ("_customer" if number_type == "customer" else "" )
347+ "l10n_de_datev_identifier{}" .format (
348+ "_customer" if number_type == "customer" else ""
349+ )
360350 ] or str (
361351 (1 if number_type == "customer" else 7 ) * 10 ** account_length
362352 + partner .id
0 commit comments