Skip to content

Commit

Permalink
[FIX] account_mass_reconcile : fix write-off with todays date
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-dacosta committed Oct 25, 2023
1 parent a0c7436 commit 792cbde
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 2 deletions.
2 changes: 1 addition & 1 deletion account_mass_reconcile/models/base_reconciliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def create_write_off(self, lines, amount, amount_curr, same_curr):

move = self.env["account.move"].create(
{
"date": lines.env.context.get("date_p"),
"date": lines.env.context.get("date_p") or fields.Date.today(),
"journal_id": journal.id,
"currency_id": currency.id,
"line_ids": [(0, 0, write_off_vals), (0, 0, counter_part)],
Expand Down
113 changes: 112 additions & 1 deletion account_mass_reconcile/tests/test_scenario_reconcile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# © 2014-2016 Camptocamp SA (Damien Crier)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from datetime import timedelta
from datetime import date, timedelta

import odoo.tests
from odoo import fields
Expand Down Expand Up @@ -243,3 +243,114 @@ def test_reconcile_with_writeoff(self):
writeoff_line.move_id.journal_id.id,
self.company_data["default_journal_misc"].id,
)

def test_reconcile_with_writeoff(self):
invoice = self.create_invoice()

receivable_account_id = invoice.partner_id.property_account_receivable_id.id
# create payment
payment = self.env["account.payment"].create(
{
"partner_type": "customer",
"payment_type": "inbound",
"partner_id": invoice.partner_id.id,
"destination_account_id": receivable_account_id,
"amount": 50.1,
"journal_id": self.bank_journal.id,
}
)
payment.action_post()

# create the mass reconcile record
mass_rec = self.mass_rec_obj.create(
{
"name": "mass_reconcile_1",
"account": invoice.partner_id.property_account_receivable_id.id,
"reconcile_method": [
(
0,
0,
{
"name": "mass.reconcile.simple.partner",
"account_lost_id": self.company_data[
"default_account_expense"
].id,
"account_profit_id": self.company_data[
"default_account_revenue"
].id,
"journal_id": self.company_data["default_journal_misc"].id,
"write_off": 0.05,
},
)
],
}
)
# call the automatic reconciliation method
mass_rec.run_reconcile()
self.assertEqual("not_paid", invoice.payment_state)
mass_rec.reconcile_method.write_off = 0.11
mass_rec.run_reconcile()
self.assertEqual("paid", invoice.payment_state)
full_reconcile = invoice.line_ids.mapped("full_reconcile_id")
writeoff_line = full_reconcile.reconciled_line_ids.filtered(
lambda l: l.debit == 0.1
)
self.assertEqual(len(writeoff_line), 1)
self.assertEqual(
writeoff_line.move_id.journal_id.id,
self.company_data["default_journal_misc"].id,
)

def test_reconcile_with_writeoff_today(self):
yesterday = date.today() - timedelta(days=1)
invoice = self._create_invoice(move_type='out_invoice', invoice_amount=50, date_invoice=yesterday, auto_validate=True)

receivable_account_id = invoice.partner_id.property_account_receivable_id.id
# create payment
payment = self.env["account.payment"].create(
{
"partner_type": "customer",
"payment_type": "inbound",
"partner_id": invoice.partner_id.id,
"destination_account_id": receivable_account_id,
"amount": 50.02,
"journal_id": self.bank_journal.id,
"date": yesterday,
}
)
payment.action_post()

# create the mass reconcile record
mass_rec = self.mass_rec_obj.create(
{
"name": "mass_reconcile_1",
"account": invoice.partner_id.property_account_receivable_id.id,
"reconcile_method": [
(
0,
0,
{
"name": "mass.reconcile.simple.partner",
"account_lost_id": self.company_data[
"default_account_expense"
].id,
"account_profit_id": self.company_data[
"default_account_revenue"
].id,
"journal_id": self.company_data["default_journal_misc"].id,
"write_off": 0.05,
"date_base_on": "actual",
},
)
],
}
)
# call the automatic reconciliation method
mass_rec.run_reconcile()
self.assertEqual("paid", invoice.payment_state)
full_reconcile = invoice.line_ids.mapped("full_reconcile_id")
writeoff_line = full_reconcile.reconciled_line_ids.filtered(
lambda l: l.debit == 0.02
)
self.assertEqual(len(writeoff_line), 1)
self.assertEqual(writeoff_line.date, fields.Date.today())

0 comments on commit 792cbde

Please sign in to comment.