def test_get_fields_billing(self):
        scaffold = Scaffold()

        address = BillingAddress(
            first_name='First Name',
            last_name='Last Name',
            line1='First Line Address',
            line4='Bruxelles',
            postcode='1000',
            country_id='BE')

        order_data = {
            'billing_address': address
        }
        fields = scaffold.get_fields_billing(None, order_data)

        assert Constants.BILLING_STREET in fields
        assert Constants.BILLING_NUMBER in fields
        assert Constants.BILLING_CITY in fields
        assert Constants.BILLING_POSTCODE in fields
        assert Constants.BILLING_STATE in fields
        assert Constants.BILLING_COUNTRY in fields

        assert fields[Constants.BILLING_STREET] == address.line1
        assert fields[Constants.BILLING_NUMBER] == '.', (
            'Since Oscar does not provide a street number we set a fake value')
        assert fields[Constants.BILLING_CITY] == address.city
        assert fields[Constants.BILLING_POSTCODE] == address.postcode
        assert fields[Constants.BILLING_STATE] == address.state
        assert fields[Constants.BILLING_COUNTRY] == address.country_id
Пример #2
0
    def save(self, commit=True):

        if self.cleaned_data.get('billing_option') == self.SAME_AS_SHIPPING:
            # Convert shipping address into billing address
            billing_addr = BillingAddress()
            self.shipping_address.populate_alternative_model(billing_addr)
            if commit:
                billing_addr.save()
            return billing_addr
        else:
            address = super(BillingAddressForm, self).save(commit=False)
            try:
                address = UserAddress.objects.get(
                    user=self.instance.user,
                    hash=address.generate_hash())
                    
                last_address = UserAddress.objects.get(user=self.instance.user, is_default_for_billing=True)
                last_address.is_default_for_billing = False
                
                address.is_default_for_billing = True
                address.save()
                
            except UserAddress.DoesNotExist:
                address.is_default_for_billing = True
                address.save()
            return address
Пример #3
0
 def save(self, commit=True):
     if self.cleaned_data.get('same_as_shipping') == self.SAME_AS_SHIPPING:
         # Convert shipping address into billing address
         billing_addr = BillingAddress()
         self.shipping_address.populate_alternative_model(billing_addr)
         if commit:
             billing_addr.save()
         return billing_addr
     return super(BillingAddressForm, self).save(commit)
Пример #4
0
 def get_billing_address_form(self, shipping_address):
     """
     Return an instantiated billing address form
     """
     addr = self.get_default_billing_address()
     if not addr:
         return BillingAddressForm(shipping_address=shipping_address)
     billing_addr = BillingAddress()
     addr.populate_alternative_model(billing_addr)
     return BillingAddressForm(shipping_address=shipping_address,
                               instance=billing_addr)