fix: do not fail if company_country is not set

it's optional
This commit is contained in:
Livio Bieri 2024-02-08 11:25:37 +01:00
parent 1ced57212d
commit a4ef999684
1 changed files with 18 additions and 21 deletions

View File

@ -277,31 +277,28 @@ def update_user_address(user: User, checkout_info: CheckoutInformation):
user.street_number = checkout_info.street_number user.street_number = checkout_info.street_number
user.postal_code = checkout_info.postal_code user.postal_code = checkout_info.postal_code
user.city = checkout_info.city user.city = checkout_info.city
try:
user.country = Country.objects.get(country_id=checkout_info.country)
except Country.DoesNotExist:
pass
user.organisation_detail_name = checkout_info.company_name if checkout_info.country:
user.organisation_street = checkout_info.company_street user.country = Country.objects.filter(country_id=checkout_info.country).first()
user.organisation_street_number = checkout_info.company_street_number
user.organisation_postal_code = checkout_info.company_postal_code
user.organisation_city = checkout_info.company_city
try:
user.organisation_country = Country.objects.get(
country_id=checkout_info.company_country
)
except Country.DoesNotExist:
pass
if ( if (
user.organisation_detail_name checkout_info.company_name
and user.organisation_street and checkout_info.company_street
and user.organisation_street_number and checkout_info.company_street_number
and user.organisation_postal_code and checkout_info.company_postal_code
and user.organisation_city and checkout_info.company_city
and user.organisation_country and checkout_info.company_country
): ):
user.organisation_detail_name = checkout_info.company_name
user.organisation_street = checkout_info.company_street
user.organisation_street_number = checkout_info.company_street_number
user.organisation_postal_code = checkout_info.company_postal_code
user.organisation_city = checkout_info.company_city
user.organisation_country = Country.objects.filter(
country_id=checkout_info.company_country
).first()
user.invoice_address = User.INVOICE_ADDRESS_ORGANISATION user.invoice_address = User.INVOICE_ADDRESS_ORGANISATION
user.save() user.save()