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] RiBa: conferma fatture senza conto bancario da list view #4351

Merged
merged 1 commit into from
Sep 9, 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
26 changes: 26 additions & 0 deletions l10n_it_riba/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,32 @@ def month_check(self, invoice_date_due, all_date_due):
return True
return False

def _post(self, soft=True):
inv_riba_no_bank = self.filtered(
lambda x: x.is_riba_payment
and x.move_type == "out_invoice"
and not x.riba_partner_bank_id
)
if inv_riba_no_bank:
inv_details = (
_(
'Invoice %(name)s for customer "%(customer_name)s", '
"total %(amount)s",
name=inv.display_name,
customer_name=inv.partner_id.display_name,
amount=inv.amount_total,
)
for inv in inv_riba_no_bank
)
raise UserError(
_(
"Cannot post invoices with C/O payments without bank. "
"Please check the following invoices:\n\n- "
+ "\n- ".join(inv_details)
)
)
return super()._post(soft=soft)

def action_post(self):
for invoice in self:
# ---- Add a line with collection fees for each due date only for first due
Expand Down
32 changes: 32 additions & 0 deletions l10n_it_riba/tests/test_riba.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,3 +732,35 @@ def test_file_substitute_forbidden_chars(self):
file_content = base64.decodebytes(export_wizard.riba_txt).decode()
self.assertNotIn("Via di là", file_content)
self.assertIn("Via di la", file_content)

def test_riba_inv_no_bank(self):
"""
Test that a riba invoice without a bank defined
cannot be confirmed (e.g. via the list view)
"""
self.invoice.company_id.due_cost_service_id = self.service_due_cost.id
self.invoice.riba_partner_bank_id = False
with self.assertRaises(UserError) as err:
self.invoice.action_post()
err_msg = err.exception.args[0]
self.assertIn("Cannot post invoices", err_msg)
self.assertIn(self.invoice.partner_id.display_name, err_msg)
# We have to add back a taxed collection fee for each payment term line
# because they have been added during `action_post`
# and recorded in the exception message,
# but `assertRaises` rolls them back
collection_fees = self.invoice.invoice_payment_term_id.riba_payment_cost
collection_fees_tax = self.invoice.fiscal_position_id.map_tax(
self.service_due_cost.taxes_id
)
taxed_collection_fees = collection_fees_tax.compute_all(collection_fees)[
"total_included"
]
self.assertIn(
str(
self.invoice.amount_total
+ len(self.invoice.invoice_payment_term_id.line_ids)
* taxed_collection_fees
),
err_msg,
)
SirAionTech marked this conversation as resolved.
Show resolved Hide resolved
Loading