Skip to content

Commit

Permalink
Merge PR #585 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by etobella
  • Loading branch information
OCA-git-bot committed Sep 6, 2023
2 parents 99fb0b5 + f28dcf7 commit 7b39b97
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 32 deletions.
2 changes: 1 addition & 1 deletion account_reconcile_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
19 changes: 19 additions & 0 deletions account_reconcile_oca/migrations/16.0.1.2.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -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
""",
)
70 changes: 42 additions & 28 deletions account_reconcile_oca/models/account_bank_statement_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@ def _compute_reconcile_data_info(self):
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
)
Expand Down Expand Up @@ -418,35 +420,44 @@ def _compute_exchange_rate(self, data, reconcile_auxiliary_id):
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
res = (
self.env["account.reconcile.model"]
.search([("rule_type", "in", ["invoice_matching", "writeoff_suggestion"])])
._apply_rules(self, self._retrieve_partner())
)
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
if not from_unreconcile:
res = (
self.env["account.reconcile.model"]
.search(
[("rule_type", "in", ["invoice_matching", "writeoff_suggestion"])]
)
amount -= line_data.get("amount")
data.append(line_data)
return self._recompute_suspense_line(
data, reconcile_auxiliary_id, self.manual_reference
._apply_rules(self, self._retrieve_partner())
)
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(
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,
)
Expand All @@ -458,9 +469,11 @@ def clean_reconcile(self):
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()
Expand Down Expand Up @@ -574,12 +587,13 @@ def unreconcile_bank_line(self):
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):
Expand Down
14 changes: 13 additions & 1 deletion account_reconcile_oca/models/account_reconcile_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -80,6 +82,16 @@ def _get_reconcile_line(self, line, kind, is_counterpart=False, max_amount=False
"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
):
Expand Down
4 changes: 2 additions & 2 deletions account_reconcile_oca/static/src/xml/reconcile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</th>
<th class="text-end">Debit</th>
<th class="text-end">Credit</th>
<th />
<th t-if="! props.record.data.is_reconciled" />
</thead>
<tbody>
<t
Expand Down Expand Up @@ -130,7 +130,7 @@
class="btn fa fa-trash-o"
role="button"
t-on-click="(ev) => this.onTrashLine(ev, reconcile_line)"
t-if="reconcile_line.kind == 'other'"
t-if="reconcile_line.kind == 'other' &amp;&amp; ! props.record.data.is_reconciled"
/>
</td>
</tr>
Expand Down

0 comments on commit 7b39b97

Please sign in to comment.