diff --git a/account_reconcile_oca/models/account_account_reconcile.py b/account_reconcile_oca/models/account_account_reconcile.py index 5129f53856..c13a0efef5 100644 --- a/account_reconcile_oca/models/account_account_reconcile.py +++ b/account_reconcile_oca/models/account_account_reconcile.py @@ -21,7 +21,6 @@ class AccountAccountReconcile(models.Model): account_id = fields.Many2one("account.account", readonly=True) name = fields.Char(readonly=True) is_reconciled = fields.Boolean(readonly=True) - currency_id = fields.Many2one("res.currency", readonly=True) @property def _table_query(self): diff --git a/account_reconcile_oca/models/account_bank_statement_line.py b/account_reconcile_oca/models/account_bank_statement_line.py index 17eda9dc6c..2e453308b3 100644 --- a/account_reconcile_oca/models/account_bank_statement_line.py +++ b/account_reconcile_oca/models/account_bank_statement_line.py @@ -144,6 +144,9 @@ def _onchange_add_account_move_line_id(self): self.add_account_move_line_id = False def _recompute_suspense_line(self, data, reconcile_auxiliary_id, manual_reference): + reconcile_auxiliary_id = self._compute_exchange_rate( + data, reconcile_auxiliary_id + ) can_reconcile = True total_amount = 0 new_data = [] @@ -189,6 +192,8 @@ def _recompute_suspense_line(self, data, reconcile_auxiliary_id, manual_referenc "debit": -total_amount if total_amount < 0 else 0.0, "kind": "suspense", "currency_id": self.currency_id.id, + "line_currency_id": self.currency_id.id, + "currency_amount": -total_amount, } reconcile_auxiliary_id += 1 new_data.append(suspense_line) @@ -366,6 +371,8 @@ def _reconcile_data_by_model(self, data, reconcile_model, reconcile_auxiliary_id .browse(line["account_id"]) .name_get()[0], "date": fields.Date.to_string(self.date), + "line_currency_id": self.currency_id.id, + "currency_amount": amount, } ) reconcile_auxiliary_id += 1 @@ -376,15 +383,11 @@ def _reconcile_data_by_model(self, data, reconcile_model, reconcile_auxiliary_id new_data.append(new_line) return new_data, reconcile_auxiliary_id - def _compute_exchange_rate(self, data): - reconcile_auxiliary_id = 1 + def _compute_exchange_rate(self, data, reconcile_auxiliary_id): if not self.foreign_currency_id or self.is_reconciled: return reconcile_auxiliary_id currency = self.journal_id.currency_id or self.company_id.currency_id - currency_amount = self.foreign_currency_id._convert( - self.amount_currency, currency, self.company_id, self.date - ) - amount = sum(d["amount"] for d in data) - currency_amount + amount = sum(d.get("net_amount", 0) for d in data) if not currency.is_zero(amount): account = self.company_id.expense_currency_exchange_account_id if amount > 0: @@ -402,6 +405,8 @@ def _compute_exchange_rate(self, data): "debit": -amount if amount < 0 else 0.0, "kind": "other", "currency_id": self.currency_id.id, + "line_currency_id": self.currency_id.id, + "currency_amount": -amount, } ) reconcile_auxiliary_id += 1 @@ -410,7 +415,7 @@ def _compute_exchange_rate(self, data): def _default_reconcile_data(self): 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 = self._compute_exchange_rate(data) + reconcile_auxiliary_id = 1 res = ( self.env["account.reconcile.model"] .search([("rule_type", "in", ["invoice_matching", "writeoff_suggestion"])]) @@ -605,7 +610,7 @@ def create(self, mvals): record._get_reconcile_line(line, "liquidity") for line in liquidity_lines ] - reconcile_auxiliary_id = record._compute_exchange_rate(data) + reconcile_auxiliary_id = 1 if res.get("status", "") == "write_off": data = record._recompute_suspense_line( *record._reconcile_data_by_model( @@ -664,6 +669,8 @@ def button_manual_reference_full_paid(self): "debit": -total_amount if total_amount < 0 else 0.0, "kind": "other", "currency_id": line["currency_id"], + "line_currency_id": line["currency_id"], + "currency_amount": -total_amount, } ) reconcile_auxiliary_id += 1 diff --git a/account_reconcile_oca/models/account_reconcile_abstract.py b/account_reconcile_oca/models/account_reconcile_abstract.py index 59fdc03f76..4b1f61eb06 100644 --- a/account_reconcile_oca/models/account_reconcile_abstract.py +++ b/account_reconcile_oca/models/account_reconcile_abstract.py @@ -27,21 +27,33 @@ class AccountReconcileAbstract(models.AbstractModel): default=False, prefetch=False, ) + currency_id = fields.Many2one("res.currency", readonly=True) def _get_reconcile_line(self, line, kind, is_counterpart=False, max_amount=False): - original_amount = amount = line.debit - line.credit + original_amount = amount = net_amount = line.debit - line.credit if is_counterpart: - original_amount = amount = ( - line.amount_residual_currency or line.amount_residual - ) + amount = line.amount_residual_currency or line.amount_residual + original_amount = net_amount = line.amount_residual + if max_amount: + currency_max_amount = self.currency_id._convert( + max_amount, line.currency_id, self.company_id, line.date + ) if max_amount: - if amount > max_amount > 0: - amount = max_amount - if amount < max_amount < 0: - amount = max_amount + if amount > currency_max_amount > 0: + amount = currency_max_amount + net_amount = max_amount + if amount < currency_max_amount < 0: + amount = currency_max_amount + net_amount = max_amount if is_counterpart: amount = -amount original_amount = -original_amount + net_amount = -net_amount + currency_amount = amount + date = self.date if "date" in self._fields else line.date + amount = line.currency_id._convert( + amount, self.currency_id, self.company_id, date + ) vals = { "reference": "account.move.line;%s" % line.id, "id": line.id, @@ -52,7 +64,10 @@ def _get_reconcile_line(self, line, kind, is_counterpart=False, max_amount=False "debit": amount if amount > 0 else 0.0, "credit": -amount if amount < 0 else 0.0, "amount": amount, - "currency_id": line.currency_id.id, + "net_amount": amount - net_amount, + "currency_id": self.currency_id.id, + "line_currency_id": line.currency_id.id, + "currency_amount": currency_amount, "analytic_distribution": line.analytic_distribution, "kind": kind, } diff --git a/account_reconcile_oca/static/src/js/widgets/reconcile_data_widget.esm.js b/account_reconcile_oca/static/src/js/widgets/reconcile_data_widget.esm.js index 177f51a332..af0406c41f 100644 --- a/account_reconcile_oca/static/src/js/widgets/reconcile_data_widget.esm.js +++ b/account_reconcile_oca/static/src/js/widgets/reconcile_data_widget.esm.js @@ -31,6 +31,13 @@ export class AccountReconcileDataWidget extends Component { currency: session.get_currency(data[line].currency_id), } ); + data[line].amount_currency_format = fieldUtils.format.monetary( + data[line].currency_amount, + undefined, + { + currency: session.get_currency(data[line].line_currency_id), + } + ); if (data[line].original_amount) { data[line].original_amount_format = fieldUtils.format.monetary( data[line].original_amount, diff --git a/account_reconcile_oca/static/src/xml/reconcile.xml b/account_reconcile_oca/static/src/xml/reconcile.xml index 9da79bdee5..149c7842e1 100644 --- a/account_reconcile_oca/static/src/xml/reconcile.xml +++ b/account_reconcile_oca/static/src/xml/reconcile.xml @@ -62,6 +62,12 @@ Partner Date Label + + Amount in currency + Debit Credit @@ -90,6 +96,12 @@ t-if="reconcile_line.name" /> + + +