Skip to content

Commit f51fa1a

Browse files
committed
[WIP] entrega tentativa
Part-of: #608
1 parent 1bde019 commit f51fa1a

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

account_interests/models/res_company_interest.py

+15-32
Original file line numberDiff line numberDiff line change
@@ -186,29 +186,21 @@ def create_invoices(self, from_date, to_date, groupby=['partner_id']):
186186
'yearly': 360,
187187
}
188188

189-
# calculamos intereses de facturas
189+
# calculamos intereses de facturas del ultimo periodo
190190
last_period_lines = move_line.search(self._get_move_line_domains() + [('amount_residual', '>', 0), ('date_maturity', '>=', from_date), ('date_maturity', '<', to_date)])
191191
for partner, amls in last_period_lines.grouped('partner_id').items():
192192
interest = 0
193193
for move, lines in amls.grouped('move_id').items():
194194
days = (to_date - move.invoice_date_due).days
195195
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
202196
if partner in deuda:
203197
deuda[partner]['Deuda último periodo'] = interest
204198
else:
205199
deuda[partner] = {'Deuda último periodo': interest}
206200

207201

208202
# Feature de intereses por pago tardio (periodo actual)
209-
# ToDo comentar esta funcionalidad
210203
if self.late_payment_interest:
211-
# #last_period_lines_domain = self._get_move_line_domains() + [('date_maturity', '>=', to_date)]
212204

213205
partials = self.env['account.partial.reconcile'].search([
214206
('debit_move_id.partner_id.active', '=', True),
@@ -243,14 +235,14 @@ def create_invoices(self, from_date, to_date, groupby=['partner_id']):
243235

244236
total_items = len(deuda)
245237
_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)
249241

250242
if not move_vals:
251243
continue
252244

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)
254246

255247
move = self.env['account.move'].create(move_vals)
256248

@@ -264,7 +256,7 @@ def create_invoices(self, from_date, to_date, groupby=['partner_id']):
264256

265257

266258

267-
def prepare_info(self, to_date, debt):
259+
def prepare_info(self, to_date):
268260
self.ensure_one()
269261

270262
# Format date to customer language
@@ -274,25 +266,15 @@ def prepare_info(self, to_date, debt):
274266
to_date_format = to_date.strftime(date_format)
275267

276268
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)
280271

281272
return res
282273

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):
284275
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
292276

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)
296278
fpos = partner.property_account_position_id
297279
taxes = self.interest_product_id.taxes_id.filtered(
298280
lambda r: r.company_id == self.company_id)
@@ -308,15 +290,16 @@ def _prepare_interest_invoice(self, lines, to_date, journal, forced_interest_amo
308290
'invoice_origin': "Interests Invoice",
309291
'invoice_payment_term_id': False,
310292
'narration': self.interest_product_id.name + '.\n' + comment,
311-
'invoice_line_ids': [(0, 0, {
293+
'invoice_line_ids': [(0, 0,
294+
{
312295
"product_id": self.interest_product_id.id,
313296
"quantity": 1.0,
314-
"price_unit": self.rate * debt if not forced_interest_amount else forced_interest_amount,
297+
"price_unit": value,
315298
"partner_id": partner.id,
316-
"name": self.interest_product_id.name + '.\n' + comment,
299+
"name": self.interest_product_id.name + '.\n' + key,
317300
"analytic_distribution": {self.analytic_account_id.id: 100.0} if self.analytic_account_id.id else False,
318301
"tax_ids": [(6, 0, tax_id.ids)]
319-
})],
302+
}) for key, value in debt.items() if value > 0],
320303
}
321304

322305
# hack para evitar modulo glue con l10n_latam_document

0 commit comments

Comments
 (0)