From 5e6eed71be8e206e13e93ba7ea07a39e739185ef Mon Sep 17 00:00:00 2001 From: Enric Tobella Date: Tue, 11 Feb 2025 23:05:41 +0100 Subject: [PATCH] [IMP] account_reconcile_oca: Allow to select all lines at once --- .../models/account_account_reconcile.py | 24 ++++--- .../models/account_bank_statement_line.py | 66 +++++++++++-------- .../models/account_reconcile_abstract.py | 3 + .../reconcile_move_line_controller.esm.js | 9 +++ .../reconcile_move_line_view.esm.js | 1 + .../widgets/reconcile_move_line_widget.esm.js | 3 +- .../static/src/xml/reconcile.xml | 10 +++ 7 files changed, 79 insertions(+), 37 deletions(-) diff --git a/account_reconcile_oca/models/account_account_reconcile.py b/account_reconcile_oca/models/account_account_reconcile.py index 590fe0bf98..a96327c328 100644 --- a/account_reconcile_oca/models/account_account_reconcile.py +++ b/account_reconcile_oca/models/account_account_reconcile.py @@ -132,16 +132,17 @@ def _inverse_reconcile_data_info(self): @api.onchange("add_account_move_line_id") def _onchange_add_account_move_line(self): if self.add_account_move_line_id: - data = self.reconcile_data_info - if self.add_account_move_line_id.id not in data["counterparts"]: - data["counterparts"].append(self.add_account_move_line_id.id) - else: - del data["counterparts"][ - data["counterparts"].index(self.add_account_move_line_id.id) - ] - self.reconcile_data_info = self._recompute_data(data) + self._add_account_move_line(self.add_account_move_line_id) self.add_account_move_line_id = False + def _add_account_move_line(self, move_line, keep_current=False): + data = self.reconcile_data_info + if move_line.id not in data["counterparts"]: + data["counterparts"].append(move_line.id) + elif not keep_current: + del data["counterparts"][data["counterparts"].index(move_line.id)] + self.reconcile_data_info = self._recompute_data(data) + @api.onchange("manual_reference", "manual_delete") def _onchange_manual_reconcile_reference(self): self.ensure_one() @@ -188,6 +189,13 @@ def reconcile(self): ) data_record.unlink() + def add_multiple_lines(self, domain): + res = super().add_multiple_lines(domain) + lines = self.env["account.move.line"].search(domain) + for line in lines: + self._add_account_move_line(line, keep_current=True) + return res + class AccountAccountReconcileData(models.TransientModel): _name = "account.account.reconcile.data" diff --git a/account_reconcile_oca/models/account_bank_statement_line.py b/account_reconcile_oca/models/account_bank_statement_line.py index 350714cdb7..3f1e03005f 100644 --- a/account_reconcile_oca/models/account_bank_statement_line.py +++ b/account_reconcile_oca/models/account_bank_statement_line.py @@ -210,36 +210,39 @@ def _get_amount_currency(self, line, dest_curr): @api.onchange("add_account_move_line_id") def _onchange_add_account_move_line_id(self): if self.add_account_move_line_id: - data = self.reconcile_data_info["data"] - new_data = [] - is_new_line = True - pending_amount = 0.0 - currency = self._get_reconcile_currency() - for line in data: - if line["kind"] != "suspense": - pending_amount += self._get_amount_currency(line, currency) - if self.add_account_move_line_id.id in line.get( - "counterpart_line_ids", [] - ): - is_new_line = False - else: + self._add_account_move_line(self.add_account_move_line_id) + self.add_account_move_line_id = False + + def _add_account_move_line(self, move_line, keep_current=False): + data = self.reconcile_data_info["data"] + new_data = [] + is_new_line = True + pending_amount = 0.0 + currency = self._get_reconcile_currency() + for line in data: + if line["kind"] != "suspense": + pending_amount += self._get_amount_currency(line, currency) + if move_line.id in line.get("counterpart_line_ids", []): + is_new_line = False + if keep_current: new_data.append(line) - if is_new_line: - reconcile_auxiliary_id, lines = self._get_reconcile_line( - self.add_account_move_line_id, - "other", - is_counterpart=True, - max_amount=currency.round(pending_amount), - move=True, - ) - new_data += lines - self.reconcile_data_info = self._recompute_suspense_line( - new_data, - self.reconcile_data_info["reconcile_auxiliary_id"], - self.manual_reference, + else: + new_data.append(line) + if is_new_line: + reconcile_auxiliary_id, lines = self._get_reconcile_line( + move_line, + "other", + is_counterpart=True, + max_amount=currency.round(pending_amount), + move=True, ) - self.can_reconcile = self.reconcile_data_info.get("can_reconcile", False) - self.add_account_move_line_id = False + new_data += lines + self.reconcile_data_info = self._recompute_suspense_line( + new_data, + self.reconcile_data_info["reconcile_auxiliary_id"], + self.manual_reference, + ) + self.can_reconcile = self.reconcile_data_info.get("can_reconcile", False) def _recompute_suspense_line(self, data, reconcile_auxiliary_id, manual_reference): can_reconcile = True @@ -1253,3 +1256,10 @@ def _get_reconcile_currency(self): or self.journal_id.currency_id or self.company_id.currency_id ) + + def add_multiple_lines(self, domain): + res = super().add_multiple_lines(domain) + lines = self.env["account.move.line"].search(domain) + for line in lines: + self._add_account_move_line(line, keep_current=True) + return res diff --git a/account_reconcile_oca/models/account_reconcile_abstract.py b/account_reconcile_oca/models/account_reconcile_abstract.py index 3a77ff284b..51ae083b33 100644 --- a/account_reconcile_oca/models/account_reconcile_abstract.py +++ b/account_reconcile_oca/models/account_reconcile_abstract.py @@ -122,3 +122,6 @@ def _get_reconcile_line( if is_counterpart: vals["counterpart_line_ids"] = line.ids return [vals] + + def add_multiple_lines(self, domain): + self.ensure_one() diff --git a/account_reconcile_oca/static/src/js/reconcile_move_line/reconcile_move_line_controller.esm.js b/account_reconcile_oca/static/src/js/reconcile_move_line/reconcile_move_line_controller.esm.js index af500eb958..82ab8cb510 100644 --- a/account_reconcile_oca/static/src/js/reconcile_move_line/reconcile_move_line_controller.esm.js +++ b/account_reconcile_oca/static/src/js/reconcile_move_line/reconcile_move_line_controller.esm.js @@ -8,6 +8,15 @@ export class ReconcileMoveLineController extends ListController { data[this.props.parentField] = [record.resId, record.display_name]; this.props.parentRecord.update(data); } + async clickAddAll() { + await this.props.parentRecord.save(); + await this.orm.call(this.props.parentRecord.resModel, "add_multiple_lines", [ + this.props.parentRecord.resIds, + this.model.root.domain, + ]); + await this.props.parentRecord.load(); + this.props.parentRecord.model.notify(); + } } ReconcileMoveLineController.template = `account_reconcile_oca.ReconcileMoveLineController`; diff --git a/account_reconcile_oca/static/src/js/reconcile_move_line/reconcile_move_line_view.esm.js b/account_reconcile_oca/static/src/js/reconcile_move_line/reconcile_move_line_view.esm.js index aebe7684c2..979570ba93 100644 --- a/account_reconcile_oca/static/src/js/reconcile_move_line/reconcile_move_line_view.esm.js +++ b/account_reconcile_oca/static/src/js/reconcile_move_line/reconcile_move_line_view.esm.js @@ -10,6 +10,7 @@ export const ReconcileMoveLineView = { ...listView, Controller: ReconcileMoveLineController, Renderer: ReconcileMoveLineRenderer, + buttonTemplate: "reconcile_move_line.ListView.Buttons", }; registry.category("views").add("reconcile_move_line", ReconcileMoveLineView); diff --git a/account_reconcile_oca/static/src/js/widgets/reconcile_move_line_widget.esm.js b/account_reconcile_oca/static/src/js/widgets/reconcile_move_line_widget.esm.js index a539bca43d..eef080842d 100644 --- a/account_reconcile_oca/static/src/js/widgets/reconcile_move_line_widget.esm.js +++ b/account_reconcile_oca/static/src/js/widgets/reconcile_move_line_widget.esm.js @@ -21,7 +21,7 @@ export class AccountReconcileMatchWidget extends Component { controlPanel: { // Hiding the control panel buttons "top-left": false, - "bottom-left": false, + "bottom-left": true, }, }, resModel: this.props.record.fields[this.props.name].relation, @@ -36,6 +36,7 @@ export class AccountReconcileMatchWidget extends Component { searchViewId: false, parentRecord: this.props.record, parentField: this.props.name, + showButtons: false, }; } } diff --git a/account_reconcile_oca/static/src/xml/reconcile.xml b/account_reconcile_oca/static/src/xml/reconcile.xml index f1f77d719e..b6c6263412 100644 --- a/account_reconcile_oca/static/src/xml/reconcile.xml +++ b/account_reconcile_oca/static/src/xml/reconcile.xml @@ -203,4 +203,14 @@ props.parentField + + + + +