[IMP] account_reconcile_oca: only store info on unreconciled items
parent
d601faf7b4
commit
3d6a561180
|
@ -5,7 +5,7 @@
|
|||
"name": "Account Reconcile Oca",
|
||||
"summary": """
|
||||
Reconcile addons for Odoo CE accounting""",
|
||||
"version": "16.0.1.1.0",
|
||||
"version": "16.0.1.2.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "CreuBlanca,Odoo Community Association (OCA)",
|
||||
"maintainers": ["etobella"],
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
from openupgradelib import openupgrade
|
||||
|
||||
|
||||
@openupgrade.migrate()
|
||||
def migrate(env, version):
|
||||
# Due to the big change we did, we need to loose how data is stored
|
||||
openupgrade.logged_query(
|
||||
env.cr,
|
||||
"""
|
||||
UPDATE account_bank_statement_line
|
||||
SET reconcile_data = NULL
|
||||
""",
|
||||
)
|
||||
openupgrade.logged_query(
|
||||
env.cr,
|
||||
"""
|
||||
DELETE FROM account_account_reconcile_data
|
||||
""",
|
||||
)
|
|
@ -323,7 +323,9 @@ class AccountBankStatementLine(models.Model):
|
|||
if record.reconcile_data:
|
||||
record.reconcile_data_info = record.reconcile_data
|
||||
else:
|
||||
record.reconcile_data_info = record._default_reconcile_data()
|
||||
record.reconcile_data_info = record._default_reconcile_data(
|
||||
from_unreconcile=record.is_reconciled
|
||||
)
|
||||
record.can_reconcile = record.reconcile_data_info.get(
|
||||
"can_reconcile", False
|
||||
)
|
||||
|
@ -418,13 +420,16 @@ class AccountBankStatementLine(models.Model):
|
|||
reconcile_auxiliary_id += 1
|
||||
return reconcile_auxiliary_id
|
||||
|
||||
def _default_reconcile_data(self):
|
||||
def _default_reconcile_data(self, from_unreconcile=False):
|
||||
liquidity_lines, suspense_lines, other_lines = self._seek_for_lines()
|
||||
data = [self._get_reconcile_line(line, "liquidity") for line in liquidity_lines]
|
||||
reconcile_auxiliary_id = 1
|
||||
if not from_unreconcile:
|
||||
res = (
|
||||
self.env["account.reconcile.model"]
|
||||
.search([("rule_type", "in", ["invoice_matching", "writeoff_suggestion"])])
|
||||
.search(
|
||||
[("rule_type", "in", ["invoice_matching", "writeoff_suggestion"])]
|
||||
)
|
||||
._apply_rules(self, self._retrieve_partner())
|
||||
)
|
||||
if res and res.get("status", "") == "write_off":
|
||||
|
@ -446,7 +451,13 @@ class AccountBankStatementLine(models.Model):
|
|||
data, reconcile_auxiliary_id, self.manual_reference
|
||||
)
|
||||
return self._recompute_suspense_line(
|
||||
data + [self._get_reconcile_line(line, "other") for line in other_lines],
|
||||
data
|
||||
+ [
|
||||
self._get_reconcile_line(
|
||||
line, "other", from_unreconcile=from_unreconcile
|
||||
)
|
||||
for line in other_lines
|
||||
],
|
||||
reconcile_auxiliary_id,
|
||||
self.manual_reference,
|
||||
)
|
||||
|
@ -458,9 +469,11 @@ class AccountBankStatementLine(models.Model):
|
|||
def reconcile_bank_line(self):
|
||||
self.ensure_one()
|
||||
self.reconcile_mode = self.journal_id.reconcile_mode
|
||||
return getattr(self, "_reconcile_bank_line_%s" % self.reconcile_mode)(
|
||||
result = getattr(self, "_reconcile_bank_line_%s" % self.reconcile_mode)(
|
||||
self.reconcile_data_info["data"]
|
||||
)
|
||||
self.reconcile_data_info = False
|
||||
return result
|
||||
|
||||
def _reconcile_bank_line_edit(self, data):
|
||||
_liquidity_lines, suspense_lines, other_lines = self._seek_for_lines()
|
||||
|
@ -574,12 +587,13 @@ class AccountBankStatementLine(models.Model):
|
|||
self.ensure_one()
|
||||
return getattr(
|
||||
self, "_unreconcile_bank_line_%s" % (self.reconcile_mode or "edit")
|
||||
)(self.reconcile_data_info["data"])
|
||||
)()
|
||||
|
||||
def _unreconcile_bank_line_edit(self, data):
|
||||
def _unreconcile_bank_line_edit(self):
|
||||
self.reconcile_data_info = self._default_reconcile_data(from_unreconcile=True)
|
||||
self.action_undo_reconciliation()
|
||||
|
||||
def _unreconcile_bank_line_keep(self, data):
|
||||
def _unreconcile_bank_line_keep(self):
|
||||
raise UserError(_("Keep suspense move lines mode cannot be unreconciled"))
|
||||
|
||||
def _reconcile_move_line_vals(self, line, move_id=False):
|
||||
|
|
|
@ -33,7 +33,9 @@ class AccountReconcileAbstract(models.AbstractModel):
|
|||
"res.currency", related="company_id.currency_id"
|
||||
)
|
||||
|
||||
def _get_reconcile_line(self, line, kind, is_counterpart=False, max_amount=False):
|
||||
def _get_reconcile_line(
|
||||
self, line, kind, is_counterpart=False, max_amount=False, from_unreconcile=False
|
||||
):
|
||||
date = self.date if "date" in self._fields else line.date
|
||||
original_amount = amount = net_amount = line.debit - line.credit
|
||||
amount_currency = self.company_id.currency_id
|
||||
|
@ -80,6 +82,16 @@ class AccountReconcileAbstract(models.AbstractModel):
|
|||
"analytic_distribution": line.analytic_distribution,
|
||||
"kind": kind,
|
||||
}
|
||||
if from_unreconcile:
|
||||
vals.update(
|
||||
{
|
||||
"id": False,
|
||||
"counterpart_line_id": (
|
||||
line.matched_debit_ids.mapped("debit_move_id")
|
||||
| line.matched_credit_ids.mapped("credit_move_id")
|
||||
).id,
|
||||
}
|
||||
)
|
||||
if not float_is_zero(
|
||||
amount - original_amount, precision_digits=line.currency_id.decimal_places
|
||||
):
|
||||
|
|
Loading…
Reference in New Issue