Update: Add EUR currency support for Slovak companies
- Modified get_cz_qr_code_base64() to support both CZK and EUR - Updated cz_to_iban() to better handle international IBANs (SK, etc.) - SPAYD QR now uses actual invoice currency in CC: field - Updated manifest description to reflect EUR support - Updated README with setup instructions for Slovak companies This allows Slovak companies with EUR accounts to generate SPAYD QR codes for Czech customers, enabling cross-border EUR payments via mobile banking. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
+23
-9
@@ -9,10 +9,14 @@ class AccountMove(models.Model):
|
||||
def get_cz_qr_code_base64(self):
|
||||
""" Returns Base64 PNG image for the invoice PDF """
|
||||
self.ensure_one()
|
||||
if self.currency_id.name != 'CZK':
|
||||
|
||||
# Support both EUR and CZK currencies
|
||||
# (for Slovak companies invoicing Czech customers in EUR)
|
||||
allowed_currencies = ['CZK', 'EUR']
|
||||
if self.currency_id.name not in allowed_currencies:
|
||||
return False
|
||||
|
||||
# Find bank: 1. Matching CZK, 2. No currency set (default)
|
||||
# Find bank: 1. Matching currency, 2. No currency set (default)
|
||||
bank = self.company_id.partner_id.bank_ids.filtered(lambda b: b.currency_id == self.currency_id)[:1]
|
||||
if not bank:
|
||||
bank = self.company_id.partner_id.bank_ids.filtered(lambda b: not b.currency_id)[:1]
|
||||
@@ -21,11 +25,13 @@ class AccountMove(models.Model):
|
||||
return False
|
||||
|
||||
# Build SPAYD string
|
||||
# Note: cz_to_iban handles both CZ format (123-456/0800) and IBAN format (SK..., CZ..., etc.)
|
||||
iban = self.cz_to_iban(bank.acc_number)
|
||||
amount = '%.2f' % self.amount_residual
|
||||
vs = ''.join(filter(str.isdigit, self.payment_reference or ''))[-10:]
|
||||
currency = self.currency_id.name or 'EUR'
|
||||
|
||||
spayd = f"SPD*1.0*ACC:{iban}*AM:{amount}*CC:CZK*X-VS:{vs}"
|
||||
spayd = f"SPD*1.0*ACC:{iban}*AM:{amount}*CC:{currency}*X-VS:{vs}"
|
||||
|
||||
# Generate QR Image
|
||||
qr = qrcode.make(spayd)
|
||||
@@ -35,23 +41,31 @@ class AccountMove(models.Model):
|
||||
|
||||
def cz_to_iban(self, acc_number):
|
||||
"""
|
||||
Converts '123-456/0800' or '456/0800' to a valid CZ IBAN.
|
||||
Converts Czech account number formats to IBAN.
|
||||
|
||||
Supports:
|
||||
- Czech local format: '123-456/0800' or '456/0800'
|
||||
- IBAN format: 'CZ6508000000001234567890', 'SK6509000000005123456789', etc.
|
||||
|
||||
Returns:
|
||||
str: Valid IBAN (uppercase) or original input if conversion fails
|
||||
"""
|
||||
if not acc_number:
|
||||
return ""
|
||||
|
||||
# Clean the input
|
||||
clean_acc = acc_number.replace(" ", "")
|
||||
clean_acc = acc_number.replace(" ", "").upper()
|
||||
|
||||
# If already an IBAN, return it
|
||||
if clean_acc.upper().startswith('CZ'):
|
||||
return clean_acc.upper()
|
||||
# If already an IBAN (any country), return it
|
||||
# IBAN format: 2-letter country code + 2-digit checksum + account number
|
||||
if len(clean_acc) >= 4 and clean_acc[:2].isalpha() and clean_acc[2:4].isdigit():
|
||||
return clean_acc
|
||||
|
||||
try:
|
||||
# Split into [prefix-main, bank_code]
|
||||
parts = clean_acc.split('/')
|
||||
if len(parts) != 2:
|
||||
return clean_acc # Fallback
|
||||
return clean_acc # Fallback for non-CZ format
|
||||
|
||||
bank_code = parts[1]
|
||||
account_parts = parts[0].split('-')
|
||||
|
||||
Reference in New Issue
Block a user