def get_billing_address_instance(self, row): address_line_1 = self.column_from_row("bill-address-1", row) address_line_2 = self.column_from_row("bill-address-2", row) address_line_3 = self.column_from_row("bill-address-3", row) if address_line_1 == "" and address_line_2 == "" and address_line_3 == "": return billing_address = self.get_street_and_housenumber_from_address(address_line_1, address_line_2, address_line_3) buyer_name, billing_city = self.column_from_row("buyer-name", row), self.column_from_row("bill-city", row) billing_country_code = self.column_from_row("bill-country", row) billing_postal_code = self.column_from_row("bill-postal-code", row) address_data = {"first_name_last_name": buyer_name, "adresszusatz": billing_address.get("adresszusatz"), "adresszusatz2": None, "street_and_housenumber": billing_address.get("street_and_housenumber"), "address_line_1": address_line_1, "address_line_2": address_line_2, "address_line_3": address_line_3, "place": billing_city, "zip": billing_postal_code, "country_code": billing_country_code } billing_address_instance = Adress.objects.filter(**address_data).first() if billing_address_instance is None: billing_address_instance = Adress(**address_data) billing_address_instance.save() return billing_address_instance
def get_billing_address_instance(self, row, mission): address_line_1 = row.get("Adresse 1", "") or "" address_line_2 = row.get("Adresse 2", "") or "" if address_line_1 == "": if mission.billing_address is not None: return mission.billing_address return billing_address = address_line_1 buyer_name, billing_city = row.get("Name des Käufers", "") or "", row.get("Ort", "") or "" billing_country = row.get("Land", "") or "" billing_postal_code = row.get("PLZ", "") or "" address_data = { "first_name_last_name": buyer_name, "adresszusatz": None, "adresszusatz2": None, "street_and_housenumber": billing_address, "address_line_1": address_line_1, "address_line_2": address_line_2, "place": billing_city, "zip": billing_postal_code, "country": billing_country } billing_address_instance = None if mission is not None: billing_address_instance = mission.billing_address if billing_address_instance is None: billing_address_instance = Adress(**address_data) billing_address_instance.save() return billing_address_instance
def get_shipping_address_instance(self, row): address_line_1 = self.column_from_row("ship-address-1", row) address_line_2 = self.column_from_row("ship-address-2", row) address_line_3 = self.column_from_row("ship-address-3", row) if address_line_1 == "" and address_line_2 == "" and address_line_3 == "": return shipping_address = self.get_street_and_housenumber_from_address(address_line_1, address_line_2, address_line_3) recipient_name, ship_city = self.column_from_row("recipient-name", row), self.column_from_row("ship-city", row) ship_country_code = self.column_from_row("ship-country", row) ship_postal_code = self.column_from_row("ship-postal-code", row) address_data = {"first_name_last_name": recipient_name, "adresszusatz": shipping_address.get("adresszusatz"), "adresszusatz2": None, "street_and_housenumber": shipping_address.get("street_and_housenumber"), "address_line_1": address_line_1, "address_line_2": address_line_2, "address_line_3": address_line_3, "place": ship_city, "zip": ship_postal_code, "country_code": ship_country_code } shipping_address_instance = Adress.objects.filter(**address_data).first() if shipping_address_instance is None: shipping_address_instance = Adress(**address_data) shipping_address_instance.save() return shipping_address_instance
def form_valid(self, form): data = form.cleaned_data client = Client(name=data.get("name"), qr_code=data.get("qr_code")) bank = Bank(bank=data.get("bank"), bic=data.get("bic"), iban=data.get("iban")) contact = Contact(company_image=data.get("company_image"), telefon=data.get("phone"), fax=data.get("fax"), email=data.get("email"), website=data.get("website"), website_conditions_link=data.get("website_conditions_link"), commercial_register=data.get("commercial_register"), tax_number=data.get("tax_number"), sales_tax_identification_number=data.get("sales_tax_identification_number")) billing_address = Adress(firma=data.get("billing_company"), strasse=data.get("billing_street"), hausnummer=data.get("billing_house_number"), place=data.get("billing_place"), zip=data.get("billing_zip"), vorname=data.get("billing_first_name"), nachname=data.get("billing_last_name")) delivery_address = Adress(firma=data.get("delivery_company"), strasse=data.get("delivery_street"), hausnummer=data.get("delivery_house_number"), place=data.get("delivery_place"), zip=data.get("delivery_zip"), vorname=data.get("delivery_first_name"), nachname=data.get("delivery_last_name")) try: billing_address.save() delivery_address.save() bank.save() contact.billing_address = billing_address contact.delivery_address = delivery_address contact.save() contact.bank.add(bank) contact.save() client.contact = contact client.save() except ValidationError as e: return render(self.request, self.template_name, self.get_context_data()) return super().form_valid(form)
def update_or_create_shipping_address_from_order(self, order, mission_instance): shipping_address = order.get("ShippingAddress") # restlich werte aus json in Adresse speichern if shipping_address is not None: shipping_address_components = self.get_street_and_housenumber_from_shipping_address( shipping_address) city_and_postal_code_have_changed = ( mission_instance.delivery_address is not None and mission_instance.delivery_address.place is not None and mission_instance.delivery_address.zip is not None and str.lower(shipping_address.get("City")) != str.lower( mission_instance.delivery_address.place) and str.lower(shipping_address.get("PostalCode")) != str.lower( mission_instance.delivery_address.zip)) postal_code_or_place_is_none = ( mission_instance.delivery_address is not None and (mission_instance.delivery_address.place is None or mission_instance.delivery_address.zip is None)) street_and_housenumber = shipping_address_components.get( "street_and_housenumber") city = shipping_address.get("City") postal_code = shipping_address.get("PostalCode") if mission_instance.delivery_address is None: shipping_address_instance = Adress( first_name_last_name=shipping_address.get("Name"), street_and_housenumber=street_and_housenumber, adresszusatz=None, adresszusatz2=None, place=city, zip=postal_code, country_code=shipping_address.get("CountryCode")) shipping_address_instance.save() mission_instance.delivery_address = shipping_address_instance else: if city_and_postal_code_have_changed is True or postal_code_or_place_is_none: mission_instance.delivery_address.first_name_last_name = shipping_address.get( "Name") mission_instance.delivery_address.street_and_housenumber = street_and_housenumber mission_instance.delivery_address.adresszusatz = None mission_instance.delivery_address.adresszusatz2 = None mission_instance.delivery_address.place = city mission_instance.delivery_address.zip = postal_code mission_instance.delivery_address.country_code = shipping_address.get( "CountryCode") mission_instance.delivery_address.save() return mission_instance.delivery_address
def get_shipping_address_instance(self, row, mission): address_line_1 = row.get("Click &", "") or "" address_line_2 = row.get(" Collect: Referenznummer", "") or "" if address_line_1 == "": if mission.delivery_address is not None: return mission.delivery_address return shipping_address = address_line_1 recipient_name, ship_city = row.get( "Name des Käufers", "") or "", row.get("Versand nach Adresse 1", "") or "" ship_country = row.get("Versand nach Staat", "") or "" ship_postal_code = row.get("Versand nach Ort", "") or "" address_data = { "first_name_last_name": recipient_name, "adresszusatz": None, "adresszusatz2": None, "street_and_housenumber": shipping_address, "address_line_1": address_line_1, "address_line_2": address_line_2, "place": ship_city, "zip": ship_postal_code, "country": ship_country } shipping_address_instance = None if mission is not None: shipping_address_instance = mission.delivery_address if shipping_address_instance is None: shipping_address_instance = Adress(**address_data) shipping_address_instance.save() return shipping_address_instance
def form_valid(self, form): data = form.cleaned_data client = self.get_object() client.name = data.get("name") client.contact.telefon = data.get("phone") client.contact.fax = data.get("fax") client.contact.email = data.get("email") client.contact.website = data.get("website") client.contact.website_conditions_link = data.get("website_conditions_link") client.contact.commercial_register = data.get("commercial_register") client.contact.tax_number = data.get("tax_number") client.contact.sales_tax_identification_number = data.get("sales_tax_identification_number") billing_address = client.contact.billing_address if billing_address is None: billing_address = Adress() billing_address.firma = data.get("billing_company") billing_address.strasse = data.get("billing_street") billing_address.hausnummer = data.get("billing_house_number") billing_address.place = data.get("billing_place") billing_address.zip = data.get("billing_zip") billing_address.vorname = data.get("billing_first_name") billing_address.nachname = data.get("billing_last_name") delivery_address = client.contact.delivery_address if delivery_address is None: delivery_address = Adress() delivery_address.firma = data.get("delivery_company") delivery_address.strasse = data.get("delivery_street") delivery_address.hausnummer = data.get("delivery_house_number") delivery_address.place = data.get("delivery_place") delivery_address.zip = data.get("delivery_zip") delivery_address.vorname = data.get("delivery_first_name") delivery_address.nachname = data.get("delivery_last_name") if data.get("qr_code") is False: client.qr_code.delete() else: client.qr_code = data.get("qr_code") if data.get("company_image") is False: client.contact.company_image.delete() else: client.contact.company_image = data.get("company_image") if client.contact.bank.first() is None: bank = Bank(bank=data.get("bank"), bic=data.get("bic"), iban=data.get("iban")) bank.save() client.contact.bank.add(bank) if client.contact.bank.first() is not None: bank = client.contact.bank.first() bank.bank = data.get("bank") bank.bic = data.get("bic") bank.iban = data.get("iban") bank.save() print(f"Hero: {client.contact.bank.first()}") try: billing_address.save() delivery_address.save() client.contact.billing_address = billing_address client.contact.delivery_address = delivery_address client.contact.save() client.save() except ValidationError as e: return render(self.request, self.template_name, self.get_context_data()) return super().form_valid(form)