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

[IMP] Add a config and a hook to sort moves using partner or residual amount #402

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions account_invoice_overdue_reminder/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class ResCompany(models.Model):
default="last_reminder",
string="Contact to Remind",
)
overdue_reminder_sort_by_amount = fields.Boolean(
string="Sort Overdue reminder by remaining amount", default=True
)

@api.model
def _overdue_reminder_interface_selection(self):
Expand Down
18 changes: 14 additions & 4 deletions account_invoice_overdue_reminder/wizard/overdue_reminder_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@
domain.append(("user_id", "in", self.user_ids.ids))
return domain

def _sort_moves(self, moves):
# Use a config to sort by residual amount desc
# Config is set to true by default
if self.company_id.overdue_reminder_sort_by_amount:
return sorted(
moves,
key=lambda to_sort: to_sort["amount_residual_signed"],
reverse=True,
)
# Sorted by partner name
return moves

Check warning on line 130 in account_invoice_overdue_reminder/wizard/overdue_reminder_wizard.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_overdue_reminder/wizard/overdue_reminder_wizard.py#L130

Added line #L130 was not covered by tests

def run(self):
self.ensure_one()
if self.start_days < 0:
Expand Down Expand Up @@ -159,10 +171,8 @@
["commercial_partner_id", "amount_residual_signed"],
["commercial_partner_id"],
)
# Sort by residual amount desc
rg_res_sorted = sorted(
rg_res, key=lambda to_sort: to_sort["amount_residual_signed"], reverse=True
)
rg_res_sorted = self._sort_moves(rg_res)

Check warning on line 174 in account_invoice_overdue_reminder/wizard/overdue_reminder_wizard.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_overdue_reminder/wizard/overdue_reminder_wizard.py#L174

Added line #L174 was not covered by tests

action_ids = []
for rg_re in rg_res_sorted:
commercial_partner_id = rg_re["commercial_partner_id"][0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ class ResConfigSettings(models.TransientModel):
overdue_reminder_partner_policy = fields.Selection(
related="company_id.overdue_reminder_partner_policy", readonly=False
)

overdue_reminder_sort_by_amount = fields.Boolean(
related="company_id.overdue_reminder_sort_by_amount", readonly=False
)
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,29 @@
</div>
</div>
</div>
<div
class="col-12 col-md-12 o_setting_box"
id="overdue_reminder_sort_by_amount"
>
<div class="o_setting_left_pane">
<field name="overdue_reminder_sort_by_amount" />
</div>
<div class="o_setting_right_pane">
<div class="row" name="overdue_reminder_sort_by_amount">
<label
for="overdue_reminder_sort_by_amount"
class="col-md-4"
/>
<span
class="fa fa-lg fa-building-o col-md-1"
title="Values set here are company-specific."
aria-label="Values set here are company-specific."
groups="base.group_multi_company"
role="img"
/>
</div>
</div>
</div>
<div
class="col-12 col-md-12 o_setting_box"
id="overdue_reminder_other_fields"
Expand Down
Loading