From 825e716625196eab7ff7f181639d3cbbb07fa0a6 Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 26 Dec 2019 10:51:50 +0530 Subject: [PATCH] Update tax_id fields of billing_addresses which belong to supplied user only --- datacenterlight/utils.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/datacenterlight/utils.py b/datacenterlight/utils.py index fec5d957..0b41926d 100644 --- a/datacenterlight/utils.py +++ b/datacenterlight/utils.py @@ -197,15 +197,16 @@ def create_tax_id(stripe_customer_id, vat_number, type): if not tax_id_obj: return tax_id_response - b_addresses = BillingAddress.objects.filter( - vat_number=vat_number - ) - for b_address in b_addresses: + stripe_customer = StripeCustomer.objects.get(stripe_customer_id) + billing_address_set = set() + for ho in stripe_customer.hostingorder_set.all(): + if ho.billing_address.vat_number==vat_number: + billing_address_set.add(ho.billing_address) + for b_address in billing_address_set: b_address.stripe_tax_id = tax_id_obj.id - ub_addresses = UserBillingAddress.objects.filter( - vat_number=vat_number - ) + ub_addresses = stripe_customer.user.billing_addresses.filter( + vat_number=vat_number) for ub_address in ub_addresses: ub_address.stripe_tax_id = tax_id_obj.id return tax_id_obj