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

[FIX] Fix not enough available amount msg for draft prepaid supplier … #46

Merged
merged 2 commits into from
Apr 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@ def _compute_prepaid_amount(self):
move_lines, paid_lines = account._prepaid_move_lines()
total_amount = -sum(move_lines.mapped("amount_currency")) or 0.0
available_amount = -sum(paid_lines.mapped("amount_currency")) or 0.0
not_paid_lines = move_lines - paid_lines
supplier_not_paid = not_paid_lines.filtered(
lambda line: line.amount_currency > 0.0
)
available_amount -= sum(supplier_not_paid.mapped("amount_currency"))
account.prepaid_total_amount = total_amount
# this one is used for display/info, so we show what is really available
# as if all supplier invoices were paid.
account.prepaid_available_amount = available_amount
# Keep available_amount without to_pay supplier invoices
# Keep available_amount without to_pay supplier invoices neither ongoing
# supplier invoices because it is used to make them to pay.
account.available_amount = (
-sum(
move_lines.filtered(lambda m: m.prepaid_is_paid).mapped(
Expand Down
39 changes: 33 additions & 6 deletions project_invoicing_subcontractor/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,8 @@ def _compute_subcontractor_state(self): # noqa: C901
)
break
total_amount = analytic_account.prepaid_total_amount
available_amount = analytic_account.available_amount
available_amount = analytic_account.prepaid_available_amount
if inv.state == "draft":
total_amount -= amount
available_amount -= amount
other_draft_invoices = self.env["account.move.line"].search(
[
("parent_state", "=", "draft"),
Expand All @@ -291,14 +289,20 @@ def _compute_subcontractor_state(self): # noqa: C901
("move_id.move_type", "=", ["in_invoice", "in_refund"]),
]
)
if float_compare(total_amount, 0, precision_digits=precision) == -1:
if (
inv.state == "draft"
and float_compare(
total_amount, amount, precision_digits=precision
)
== -1
):
account_reasons.append(
"""Le solde du compte analytique %s est négatif %s. """
"""Le solde du compte analytique %s n'est pas suffisant : %s. """
"""Il est necessaire de facturer le client."""
% (analytic_account.name, total_amount)
)
color = "danger"
elif (
elif inv.state == "draft" and (
float_compare(
available_amount, amount, precision_digits=precision
)
Expand All @@ -312,6 +316,29 @@ def _compute_subcontractor_state(self): # noqa: C901
)
if color != "red":
color = "info"
elif (
inv.state != "draft"
and float_compare(total_amount, 0, precision_digits=precision)
== -1
):
account_reasons.append(
"""Le solde du compte analytique %s est négatif %s. """
"""Il est necessaire de facturer le client."""
% (analytic_account.name, total_amount)
)
color = "danger"
elif inv.state != "draft" and (
float_compare(available_amount, 0, precision_digits=precision)
== -1
):
account_reasons.append(
"""Le solde payé du compte analytique %s est insuffisant %s. """
"""La facture sera payable une fois que le client aura reglé """
"""ses factures."""
% (analytic_account.name, available_amount)
)
if color != "red":
color = "info"
else:
account_reasons.append(
"""Le solde payé du compte analytique %s est suffisant. """
Expand Down
Loading