mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
@@ -98,10 +98,6 @@ class AccountBankStatementLine(models.Model):
|
|||||||
new_aml_dicts = new_aml_dicts or []
|
new_aml_dicts = new_aml_dicts or []
|
||||||
|
|
||||||
aml_obj = self.env["account.move.line"]
|
aml_obj = self.env["account.move.line"]
|
||||||
|
|
||||||
company_currency = self.journal_id.company_id.currency_id
|
|
||||||
statement_currency = self.journal_id.currency_id or company_currency
|
|
||||||
|
|
||||||
counterpart_moves = self.env["account.move"]
|
counterpart_moves = self.env["account.move"]
|
||||||
|
|
||||||
# Check and prepare received data
|
# Check and prepare received data
|
||||||
@@ -130,55 +126,22 @@ class AccountBankStatementLine(models.Model):
|
|||||||
and user_type_id not in account_types
|
and user_type_id not in account_types
|
||||||
):
|
):
|
||||||
account_types |= user_type_id
|
account_types |= user_type_id
|
||||||
# FIXME: review
|
# Fully reconciled moves are just linked to the bank statement (blue lines),
|
||||||
# if suspense_moves_mode:
|
# but the generated move on statement post should be removed and link the
|
||||||
# if any(not line.journal_entry_ids for line in self):
|
# payment one for not having double entry
|
||||||
# raise UserError(
|
# TODO: To mix already done payments with new ones. Not sure if possible.
|
||||||
# _(
|
old_move = self.move_id.with_context(force_delete=True)
|
||||||
# "Some selected statement line were not already "
|
|
||||||
# "reconciled with an account move."
|
|
||||||
# )
|
|
||||||
# )
|
|
||||||
# else:
|
|
||||||
# if any(line.journal_entry_ids for line in self):
|
|
||||||
# raise UserError(
|
|
||||||
# _(
|
|
||||||
# "A selected statement line was already reconciled with "
|
|
||||||
# "an account move."
|
|
||||||
# )
|
|
||||||
# )
|
|
||||||
|
|
||||||
# Fully reconciled moves are just linked to the bank statement
|
|
||||||
total = self.amount
|
|
||||||
currency = self.foreign_currency_id or statement_currency
|
|
||||||
for aml_rec in payment_aml_rec:
|
for aml_rec in payment_aml_rec:
|
||||||
balance = (
|
|
||||||
aml_rec.amount_currency if aml_rec.currency_id else aml_rec.balance
|
|
||||||
)
|
|
||||||
aml_currency = aml_rec.currency_id or aml_rec.company_currency_id
|
|
||||||
total -= aml_currency._convert(
|
|
||||||
balance, currency, aml_rec.company_id, aml_rec.date
|
|
||||||
)
|
|
||||||
aml_rec.with_context(check_move_validity=False).write(
|
aml_rec.with_context(check_move_validity=False).write(
|
||||||
{"statement_line_id": self.id}
|
{"statement_line_id": self.id}
|
||||||
)
|
)
|
||||||
counterpart_moves = counterpart_moves | aml_rec.move_id
|
# This overwrites the value on each loop, so only one will be linked, but
|
||||||
if (
|
# there's no better solution in this case
|
||||||
aml_rec.journal_id.post_at == "bank_rec"
|
self.move_id = aml_rec.move_id.id
|
||||||
and aml_rec.payment_id
|
counterpart_moves |= aml_rec.move_id
|
||||||
and aml_rec.move_id.state == "draft"
|
if payment_aml_rec:
|
||||||
):
|
old_move.button_draft()
|
||||||
# In case the journal is set to only post payments when
|
old_move.unlink()
|
||||||
# performing bank reconciliation, we modify its date and post
|
|
||||||
# it.
|
|
||||||
aml_rec.move_id.date = self.date
|
|
||||||
aml_rec.payment_id.payment_date = self.date
|
|
||||||
aml_rec.move_id.action_post()
|
|
||||||
# We check the paid status of the invoices reconciled with this
|
|
||||||
# payment
|
|
||||||
for invoice in aml_rec.payment_id.reconciled_invoice_ids:
|
|
||||||
self._check_invoice_state(invoice)
|
|
||||||
|
|
||||||
# Create move line(s). Either matching an existing journal entry
|
# Create move line(s). Either matching an existing journal entry
|
||||||
# (eg. invoice), in which case we reconcile the existing and the new
|
# (eg. invoice), in which case we reconcile the existing and the new
|
||||||
# move lines together, or being a write-off.
|
# move lines together, or being a write-off.
|
||||||
@@ -343,3 +306,39 @@ class AccountBankStatementLine(models.Model):
|
|||||||
def _check_invoice_state(self, invoice):
|
def _check_invoice_state(self, invoice):
|
||||||
if invoice.is_invoice(include_receipts=True):
|
if invoice.is_invoice(include_receipts=True):
|
||||||
invoice._compute_amount()
|
invoice._compute_amount()
|
||||||
|
|
||||||
|
def button_undo_reconciliation(self):
|
||||||
|
"""Handle the case when the reconciliation was done against a direct payment
|
||||||
|
with the bank account as counterpart. This may be the case for payments made
|
||||||
|
in previous versions of Odoo.
|
||||||
|
"""
|
||||||
|
handled = self.env[self._name]
|
||||||
|
for record in self:
|
||||||
|
if record.move_id.payment_id:
|
||||||
|
# The reconciliation was done against a blue line (existing move)
|
||||||
|
# We remove the link on the current existing move, preserving it,
|
||||||
|
# and recreate a new move as if the statement line was new
|
||||||
|
record.move_id.line_ids.statement_line_id = False
|
||||||
|
statement = record.statement_id
|
||||||
|
journal = statement.journal_id
|
||||||
|
line_vals_list = record._prepare_move_line_default_vals()
|
||||||
|
new_move = self.env["account.move"].create(
|
||||||
|
{
|
||||||
|
"move_type": "entry",
|
||||||
|
"statement_line_id": record.id,
|
||||||
|
"ref": statement.name,
|
||||||
|
"date": record.date,
|
||||||
|
"journal_id": journal.id,
|
||||||
|
"partner_id": record.partner_id.id,
|
||||||
|
"currency_id": (
|
||||||
|
journal.currency_id or journal.company_id.currency_id
|
||||||
|
).id,
|
||||||
|
"line_ids": [(0, 0, line_vals) for line_vals in line_vals_list],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
new_move.action_post()
|
||||||
|
record.move_id = new_move.id
|
||||||
|
handled += record
|
||||||
|
return super(
|
||||||
|
AccountBankStatementLine, self - handled
|
||||||
|
).button_undo_reconciliation()
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ odoo.define("account.ReconciliationModel", function (require) {
|
|||||||
* label: string
|
* label: string
|
||||||
* amount: number - real amount
|
* amount: number - real amount
|
||||||
* amount_str: string - formated amount
|
* amount_str: string - formated amount
|
||||||
* [is_liquidity_line]: boolean
|
* [already_paid]: boolean
|
||||||
* [partner_id]: integer
|
* [partner_id]: integer
|
||||||
* [partner_name]: string
|
* [partner_name]: string
|
||||||
* [account_code]: string
|
* [account_code]: string
|
||||||
@@ -995,13 +995,13 @@ odoo.define("account.ReconciliationModel", function (require) {
|
|||||||
ref: line.st_line.ref,
|
ref: line.st_line.ref,
|
||||||
counterpart_aml_dicts: _.map(
|
counterpart_aml_dicts: _.map(
|
||||||
_.filter(props, function (prop) {
|
_.filter(props, function (prop) {
|
||||||
return !isNaN(prop.id) && !prop.is_liquidity_line;
|
return !isNaN(prop.id) && !prop.already_paid;
|
||||||
}),
|
}),
|
||||||
self._formatToProcessReconciliation.bind(self, line)
|
self._formatToProcessReconciliation.bind(self, line)
|
||||||
),
|
),
|
||||||
payment_aml_ids: _.pluck(
|
payment_aml_ids: _.pluck(
|
||||||
_.filter(props, function (prop) {
|
_.filter(props, function (prop) {
|
||||||
return !isNaN(prop.id) && prop.is_liquidity_line;
|
return !isNaN(prop.id) && prop.already_paid;
|
||||||
}),
|
}),
|
||||||
"id"
|
"id"
|
||||||
),
|
),
|
||||||
@@ -1168,7 +1168,7 @@ odoo.define("account.ReconciliationModel", function (require) {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!prop.is_liquidity_line && parseInt(prop.id)) {
|
if (!prop.already_paid && parseInt(prop.id)) {
|
||||||
prop.is_move_line = true;
|
prop.is_move_line = true;
|
||||||
}
|
}
|
||||||
reconciliation_proposition.push(prop);
|
reconciliation_proposition.push(prop);
|
||||||
|
|||||||
Reference in New Issue
Block a user