Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] account_reconcile_oca: Allow to select all lines at once #798

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions account_reconcile_oca/models/account_account_reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,17 @@
@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)]

Check warning on line 143 in account_reconcile_oca/models/account_account_reconcile.py

View check run for this annotation

Codecov / codecov/patch

account_reconcile_oca/models/account_account_reconcile.py#L143

Added line #L143 was not covered by tests
self.reconcile_data_info = self._recompute_data(data)

@api.onchange("manual_reference", "manual_delete")
def _onchange_manual_reconcile_reference(self):
self.ensure_one()
Expand Down Expand Up @@ -188,6 +189,13 @@
)
data_record.unlink()

def add_multiple_lines(self, domain):
res = super().add_multiple_lines(domain)
lines = self.env["account.move.line"].search(domain)

Check warning on line 194 in account_reconcile_oca/models/account_account_reconcile.py

View check run for this annotation

Codecov / codecov/patch

account_reconcile_oca/models/account_account_reconcile.py#L193-L194

Added lines #L193 - L194 were not covered by tests
for line in lines:
self._add_account_move_line(line, keep_current=True)
return res

Check warning on line 197 in account_reconcile_oca/models/account_account_reconcile.py

View check run for this annotation

Codecov / codecov/patch

account_reconcile_oca/models/account_account_reconcile.py#L196-L197

Added lines #L196 - L197 were not covered by tests


class AccountAccountReconcileData(models.TransientModel):
_name = "account.account.reconcile.data"
Expand Down
66 changes: 38 additions & 28 deletions account_reconcile_oca/models/account_bank_statement_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,36 +210,39 @@
@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
Expand Down Expand Up @@ -1253,3 +1256,10 @@
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)

Check warning on line 1262 in account_reconcile_oca/models/account_bank_statement_line.py

View check run for this annotation

Codecov / codecov/patch

account_reconcile_oca/models/account_bank_statement_line.py#L1261-L1262

Added lines #L1261 - L1262 were not covered by tests
for line in lines:
self._add_account_move_line(line, keep_current=True)
return res

Check warning on line 1265 in account_reconcile_oca/models/account_bank_statement_line.py

View check run for this annotation

Codecov / codecov/patch

account_reconcile_oca/models/account_bank_statement_line.py#L1264-L1265

Added lines #L1264 - L1265 were not covered by tests
3 changes: 3 additions & 0 deletions account_reconcile_oca/models/account_reconcile_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,6 @@
if is_counterpart:
vals["counterpart_line_ids"] = line.ids
return [vals]

def add_multiple_lines(self, domain):
self.ensure_one()

Check warning on line 127 in account_reconcile_oca/models/account_reconcile_abstract.py

View check run for this annotation

Codecov / codecov/patch

account_reconcile_oca/models/account_reconcile_abstract.py#L127

Added line #L127 was not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -36,6 +36,7 @@ export class AccountReconcileMatchWidget extends Component {
searchViewId: false,
parentRecord: this.props.record,
parentField: this.props.name,
showButtons: false,
};
}
}
Expand Down
10 changes: 10 additions & 0 deletions account_reconcile_oca/static/src/xml/reconcile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,14 @@
<attribute name="parentField">props.parentField</attribute>
</xpath>
</t>
<t
t-name="reconcile_move_line.ListView.Buttons"
t-inherit="web.ListView.Buttons"
t-inherit-mode="primary"
owl="1"
>
<xpath expr="//div[hasclass('o_list_buttons')]" position="inside">
<button class="btn btn-primary" t-on-click="clickAddAll">Add all</button>
</xpath>
</t>
</templates>