Skip to content

Commit

Permalink
Merge PR #4351 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by tafaRU
  • Loading branch information
OCA-git-bot committed Sep 9, 2024
2 parents 0962de7 + 5106b58 commit 6c180de
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
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,
)

0 comments on commit 6c180de

Please sign in to comment.