def default_description_context_generator(payment: Payment): payment_type = PAYMENT_TYPES[payment.type] iban = to_iban(payment.meta.get("iban")) return { "payment": payment, "iban": str(to_iban(payment.meta.get("iban"))), "bic": payment.meta.get("bic") or iban_to_bic(iban), "loan_recipient": payment_type.loan_recipient, }
def iban_to_bic(iban): iban = to_iban(iban) if not iban.is_valid() or iban.country != "FR": return None cib = iban.as_stored_value[4:9] return cib_to_bic.get(cib)
def generate_reimbursement_file(config: Mapping[str, str], payments: Iterable[Payment]): config = dict(config) config.setdefault("batch", True) config.setdefault("currency", "EUR") today = datetime.date.today() sepa = SepaTransfer(config, clean=True) for payment in payments: iban = to_iban(payment.meta.get("iban")) if not iban.is_valid(): raise ValueError( f"L'IBAN pour le paiement {payment!r} n'est pas valide") bic = payment.meta.get("bic", iban_to_bic(iban)) if bic is None: raise ValueError( f"Le BIC pour le paiement {payment!r} est inconnu") rembourse = payment.meta.get("rembourse", 0) amount = payment.price - rembourse if amount <= 0: continue transfer_id = str(uuid4()).replace("-", "") sepa.add_payment({ "name": f"{payment.first_name} {payment.last_name}", "IBAN": iban.as_stored_value, "BIC": bic, "amount": payment.price - rembourse, "execution_date": today, "description": f"RBST PRET {payment.id} {payment.last_name.upper()}", "endtoend_id": transfer_id, }) payment.meta["sepa_id"] = transfer_id payment.save() return sepa.export(validate=True)
def to_python(self, value): return to_iban(value)
def __set__(self, instance, value): instance.__dict__[self.field.name] = to_iban(value)
def to_python(self, value): if value in self.empty_values: return self.empty_value return to_iban(value)