@@ -186,29 +186,21 @@ def create_invoices(self, from_date, to_date, groupby=['partner_id']):
186
186
'yearly' : 360 ,
187
187
}
188
188
189
- # calculamos intereses de facturas
189
+ # calculamos intereses de facturas del ultimo periodo
190
190
last_period_lines = move_line .search (self ._get_move_line_domains () + [('amount_residual' , '>' , 0 ), ('date_maturity' , '>=' , from_date ), ('date_maturity' , '<' , to_date )])
191
191
for partner , amls in last_period_lines .grouped ('partner_id' ).items ():
192
192
interest = 0
193
193
for move , lines in amls .grouped ('move_id' ).items ():
194
194
days = (to_date - move .invoice_date_due ).days
195
195
interest += move .amount_residual * days * (self .rate / interest_rate [self .rule_type ])
196
- # dias de vencimiento
197
- # TODO completar y tmb sumar a las grouped lines
198
- # hacer que se acumulan
199
- # (to_date - move_line.date_maturity) * rate de vencimiento
200
-
201
- # agregamos a la deuda antigua
202
196
if partner in deuda :
203
197
deuda [partner ]['Deuda último periodo' ] = interest
204
198
else :
205
199
deuda [partner ] = {'Deuda último periodo' : interest }
206
200
207
201
208
202
# Feature de intereses por pago tardio (periodo actual)
209
- # ToDo comentar esta funcionalidad
210
203
if self .late_payment_interest :
211
- # #last_period_lines_domain = self._get_move_line_domains() + [('date_maturity', '>=', to_date)]
212
204
213
205
partials = self .env ['account.partial.reconcile' ].search ([
214
206
('debit_move_id.partner_id.active' , '=' , True ),
@@ -243,14 +235,14 @@ def create_invoices(self, from_date, to_date, groupby=['partner_id']):
243
235
244
236
total_items = len (deuda )
245
237
_logger .info ('%s interest invoices will be generated' , total_items )
246
- for idx , lines in enumerate (deuda ):
247
- move_vals = self ._prepare_interest_invoice (
248
- lines , to_date , journal )
238
+ for idx , partner in enumerate (deuda ):
239
+ move_vals = self ._prepare_interest_invoice (partner ,
240
+ deuda [ partner ] , to_date , journal )
249
241
250
242
if not move_vals :
251
243
continue
252
244
253
- _logger .info ('Creating Interest Invoice (%s of %s) with values:\n %s' , idx + 1 , total_items , line )
245
+ _logger .info ('Creating Interest Invoice (%s of %s) with values:\n %s' , idx + 1 , total_items , partner )
254
246
255
247
move = self .env ['account.move' ].create (move_vals )
256
248
@@ -264,7 +256,7 @@ def create_invoices(self, from_date, to_date, groupby=['partner_id']):
264
256
265
257
266
258
267
- def prepare_info (self , to_date , debt ):
259
+ def prepare_info (self , to_date ):
268
260
self .ensure_one ()
269
261
270
262
# Format date to customer language
@@ -274,25 +266,15 @@ def prepare_info(self, to_date, debt):
274
266
to_date_format = to_date .strftime (date_format )
275
267
276
268
res = _ (
277
- 'Deuda Vencida al %s: %s\n '
278
- 'Tasa de interés: %s' ) % (
279
- to_date_format , debt , self .rate )
269
+ 'Deuda Vencida al %s con tasa de interés de %s' ) % (
270
+ to_date_format , self .rate )
280
271
281
272
return res
282
273
283
- def _prepare_interest_invoice (self , lines , to_date , journal , forced_interest_amount = False ):
274
+ def _prepare_interest_invoice (self , partner , debt , to_date , journal ):
284
275
self .ensure_one ()
285
- # ADAPTAR LINES
286
- line = lines
287
- debt = line [2 ]
288
-
289
- if (not debt or debt <= 0.0 ) and not forced_interest_amount :
290
- _logger .info ("Debt is negative, skipping..." )
291
- return
292
276
293
- partner_id = line [0 ].id
294
- partner = self .env ['res.partner' ].browse (partner_id )
295
- comment = self .prepare_info (to_date , debt ) if not forced_interest_amount else 'Deuda Vencida por Pago Atrasado'
277
+ comment = self .prepare_info (to_date )
296
278
fpos = partner .property_account_position_id
297
279
taxes = self .interest_product_id .taxes_id .filtered (
298
280
lambda r : r .company_id == self .company_id )
@@ -308,15 +290,16 @@ def _prepare_interest_invoice(self, lines, to_date, journal, forced_interest_amo
308
290
'invoice_origin' : "Interests Invoice" ,
309
291
'invoice_payment_term_id' : False ,
310
292
'narration' : self .interest_product_id .name + '.\n ' + comment ,
311
- 'invoice_line_ids' : [(0 , 0 , {
293
+ 'invoice_line_ids' : [(0 , 0 ,
294
+ {
312
295
"product_id" : self .interest_product_id .id ,
313
296
"quantity" : 1.0 ,
314
- "price_unit" : self . rate * debt if not forced_interest_amount else forced_interest_amount ,
297
+ "price_unit" : value ,
315
298
"partner_id" : partner .id ,
316
- "name" : self .interest_product_id .name + '.\n ' + comment ,
299
+ "name" : self .interest_product_id .name + '.\n ' + key ,
317
300
"analytic_distribution" : {self .analytic_account_id .id : 100.0 } if self .analytic_account_id .id else False ,
318
301
"tax_ids" : [(6 , 0 , tax_id .ids )]
319
- })],
302
+ }) for key , value in debt . items () if value > 0 ],
320
303
}
321
304
322
305
# hack para evitar modulo glue con l10n_latam_document
0 commit comments