[IMP] account_reconcile_oca: only store info on unreconciled items
parent
d601faf7b4
commit
3d6a561180
|
@ -5,7 +5,7 @@
|
||||||
"name": "Account Reconcile Oca",
|
"name": "Account Reconcile Oca",
|
||||||
"summary": """
|
"summary": """
|
||||||
Reconcile addons for Odoo CE accounting""",
|
Reconcile addons for Odoo CE accounting""",
|
||||||
"version": "16.0.1.1.0",
|
"version": "16.0.1.2.0",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"author": "CreuBlanca,Odoo Community Association (OCA)",
|
"author": "CreuBlanca,Odoo Community Association (OCA)",
|
||||||
"maintainers": ["etobella"],
|
"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:
|
if record.reconcile_data:
|
||||||
record.reconcile_data_info = record.reconcile_data
|
record.reconcile_data_info = record.reconcile_data
|
||||||
else:
|
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(
|
record.can_reconcile = record.reconcile_data_info.get(
|
||||||
"can_reconcile", False
|
"can_reconcile", False
|
||||||
)
|
)
|
||||||
|
@ -418,35 +420,44 @@ class AccountBankStatementLine(models.Model):
|
||||||
reconcile_auxiliary_id += 1
|
reconcile_auxiliary_id += 1
|
||||||
return reconcile_auxiliary_id
|
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()
|
liquidity_lines, suspense_lines, other_lines = self._seek_for_lines()
|
||||||
data = [self._get_reconcile_line(line, "liquidity") for line in liquidity_lines]
|
data = [self._get_reconcile_line(line, "liquidity") for line in liquidity_lines]
|
||||||
reconcile_auxiliary_id = 1
|
reconcile_auxiliary_id = 1
|
||||||
res = (
|
if not from_unreconcile:
|
||||||
self.env["account.reconcile.model"]
|
res = (
|
||||||
.search([("rule_type", "in", ["invoice_matching", "writeoff_suggestion"])])
|
self.env["account.reconcile.model"]
|
||||||
._apply_rules(self, self._retrieve_partner())
|
.search(
|
||||||
)
|
[("rule_type", "in", ["invoice_matching", "writeoff_suggestion"])]
|
||||||
if res and res.get("status", "") == "write_off":
|
|
||||||
return self._recompute_suspense_line(
|
|
||||||
*self._reconcile_data_by_model(
|
|
||||||
data, res["model"], reconcile_auxiliary_id
|
|
||||||
),
|
|
||||||
self.manual_reference
|
|
||||||
)
|
|
||||||
elif res and res.get("amls"):
|
|
||||||
amount = self.amount_total_signed
|
|
||||||
for line in res.get("amls", []):
|
|
||||||
line_data = self._get_reconcile_line(
|
|
||||||
line, "other", is_counterpart=True, max_amount=amount
|
|
||||||
)
|
)
|
||||||
amount -= line_data.get("amount")
|
._apply_rules(self, self._retrieve_partner())
|
||||||
data.append(line_data)
|
|
||||||
return self._recompute_suspense_line(
|
|
||||||
data, reconcile_auxiliary_id, self.manual_reference
|
|
||||||
)
|
)
|
||||||
|
if res and res.get("status", "") == "write_off":
|
||||||
|
return self._recompute_suspense_line(
|
||||||
|
*self._reconcile_data_by_model(
|
||||||
|
data, res["model"], reconcile_auxiliary_id
|
||||||
|
),
|
||||||
|
self.manual_reference
|
||||||
|
)
|
||||||
|
elif res and res.get("amls"):
|
||||||
|
amount = self.amount_total_signed
|
||||||
|
for line in res.get("amls", []):
|
||||||
|
line_data = self._get_reconcile_line(
|
||||||
|
line, "other", is_counterpart=True, max_amount=amount
|
||||||
|
)
|
||||||
|
amount -= line_data.get("amount")
|
||||||
|
data.append(line_data)
|
||||||
|
return self._recompute_suspense_line(
|
||||||
|
data, reconcile_auxiliary_id, self.manual_reference
|
||||||
|
)
|
||||||
return self._recompute_suspense_line(
|
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,
|
reconcile_auxiliary_id,
|
||||||
self.manual_reference,
|
self.manual_reference,
|
||||||
)
|
)
|
||||||
|
@ -458,9 +469,11 @@ class AccountBankStatementLine(models.Model):
|
||||||
def reconcile_bank_line(self):
|
def reconcile_bank_line(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
self.reconcile_mode = self.journal_id.reconcile_mode
|
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["data"]
|
||||||
)
|
)
|
||||||
|
self.reconcile_data_info = False
|
||||||
|
return result
|
||||||
|
|
||||||
def _reconcile_bank_line_edit(self, data):
|
def _reconcile_bank_line_edit(self, data):
|
||||||
_liquidity_lines, suspense_lines, other_lines = self._seek_for_lines()
|
_liquidity_lines, suspense_lines, other_lines = self._seek_for_lines()
|
||||||
|
@ -574,12 +587,13 @@ class AccountBankStatementLine(models.Model):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
return getattr(
|
return getattr(
|
||||||
self, "_unreconcile_bank_line_%s" % (self.reconcile_mode or "edit")
|
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()
|
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"))
|
raise UserError(_("Keep suspense move lines mode cannot be unreconciled"))
|
||||||
|
|
||||||
def _reconcile_move_line_vals(self, line, move_id=False):
|
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"
|
"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
|
date = self.date if "date" in self._fields else line.date
|
||||||
original_amount = amount = net_amount = line.debit - line.credit
|
original_amount = amount = net_amount = line.debit - line.credit
|
||||||
amount_currency = self.company_id.currency_id
|
amount_currency = self.company_id.currency_id
|
||||||
|
@ -80,6 +82,16 @@ class AccountReconcileAbstract(models.AbstractModel):
|
||||||
"analytic_distribution": line.analytic_distribution,
|
"analytic_distribution": line.analytic_distribution,
|
||||||
"kind": kind,
|
"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(
|
if not float_is_zero(
|
||||||
amount - original_amount, precision_digits=line.currency_id.decimal_places
|
amount - original_amount, precision_digits=line.currency_id.decimal_places
|
||||||
):
|
):
|
||||||
|
|
Loading…
Reference in New Issue