Skip to content

Commit

Permalink
CP-297 fix qr without address (#1537)
Browse files Browse the repository at this point in the history
* FIX: Override validate_swiss_code_arguments

* FIX: QR Corrections depending on debtor partner's value
  • Loading branch information
NoeBerdoz authored Dec 22, 2022
1 parent b67d1a1 commit 16110a9
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions partner_compassion/models/partner_bank_compassion.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,38 @@ def build_swiss_code_vals(self, amount, *args):
and can't be empty to be allowed in post offices.
This function is a workaround to this problem.
We also ensure that the amount is in the range specified by the swiss qr specifications.
Furthermore, when the debtor partner isn't set correctly, we do not declare its information in the QR
to avoid errors on the user e-banking side.
"""
qr_code_vals = super().build_swiss_code_vals(amount, *args)

must_be_corrected = type(amount) not in [int, float] or not (0.01 <= amount <= 999999999.99)
if not must_be_corrected:
return super().build_swiss_code_vals(amount, *args)

amount = -3141592.64 # dummy value
qr_code_vals = super().build_swiss_code_vals(amount, *args)
# ensure that this position is still the amount
assert qr_code_vals[18] == f"{amount:.2f}"
qr_code_vals[18] = ""
if must_be_corrected:
amount = -3141592.64 # dummy value
qr_code_vals = super().build_swiss_code_vals(amount, *args)
# ensure that this position is still the amount
assert qr_code_vals[18] == f"{amount:.2f}"
qr_code_vals[18] = ""

# Set the debtor's value as nothing to escape scanning errors when the debtors information is not set correctly
if False in [args[2].city, args[2].zip, args[2].country_id.code]:
qr_code_vals[20] = '' # Ultimate Debtor Address Type
qr_code_vals[21] = '' # Ultimate Debtor Name
qr_code_vals[22] = '' # Ultimate Debtor Address Line 1
qr_code_vals[23] = '' # Ultimate Debtor Address Line 2
qr_code_vals[26] = '' # Ultimate Debtor Postal Country

return qr_code_vals

def validate_swiss_code_arguments(self, currency, debtor_partner, reference_to_check=''):
"""Override this function to let the creation of QR invoices without partner's information
As we can have partners without an address set we get rid of the inner function _partner_fields_set.
"""
return (reference_to_check == '' or not self._is_qr_iban()
or self._is_qr_reference(reference_to_check))


@api.model
def create(self, data):
"""Override function to notify creation in a message
Expand Down

0 comments on commit 16110a9

Please sign in to comment.