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

[14.0] [FIX] account_invoice_triple_discount: for in invoice_line_ids if exists, else on line_ids #1605

Merged
Merged
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
17 changes: 8 additions & 9 deletions account_invoice_triple_discount/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,28 @@
restored after the original process is done
"""
old_values_by_line_id = {}
digits = self.invoice_line_ids._fields["price_unit"]._digits
self.invoice_line_ids._fields["price_unit"]._digits = (16, 16)
for line in self.invoice_line_ids:
lines = self.invoice_line_ids or self.line_ids
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to check if it is_invoice instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on the broken test, is_invoice returns True but without invoice_line_ids. So in this case it will not fix the test

digits = lines._fields["price_unit"]._digits
lines._fields["price_unit"]._digits = (16, 16)
for line in lines:
aggregated_discount = line._compute_aggregated_discount(line.discount)
old_values_by_line_id[line.id] = {
"price_unit": line.price_unit,
"discount": line.discount,
}
price_unit = line.price_unit * (1 - aggregated_discount / 100)
line.update({"price_unit": price_unit, "discount": 0})
self.invoice_line_ids._fields["price_unit"]._digits = digits
lines._fields["price_unit"]._digits = digits
res = super(AccountMove, self)._recompute_tax_lines(**kwargs)
for line in self.invoice_line_ids:
for line in lines:
if line.id not in old_values_by_line_id:
continue
line.update(old_values_by_line_id[line.id])
return res

def _has_discount(self):
self.ensure_one()
lines = self.invoice_line_ids or self.line_ids

Check warning on line 40 in account_invoice_triple_discount/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_triple_discount/models/account_move.py#L40

Added line #L40 was not covered by tests
return any(
[
line._compute_aggregated_discount(line.discount) > 0
for line in self.invoice_line_ids
]
[line._compute_aggregated_discount(line.discount) > 0 for line in lines]
)
Loading