Пример #1
0
    def save(self, commit=True):
        company = self.forms['company'].save(commit=False)
        billing_address = self.forms['billing'].save(commit=False)
        person = self.forms['contact_person'].save(commit=False)
        user = self.forms['user_account'].save(commit=False)

        company.default_billing_address = billing_address
        company.default_shipping_address = billing_address

        for field in ['name', 'name_ext', 'email', 'phone']:
            setattr(billing_address, field, getattr(company, field))

        person.user = user

        user.first_name = person.first_name
        user.last_name = person.last_name
        user.email = person.email

        # If company registration requires approval,
        # company and person contacts will be created as inactive
        if company_registration_requires_approval(self.request.shop):
            company.is_active = False
            person.is_active = False

        if commit:
            user.save()
            person.user = user
            person.save()
            person.shops.add(self.request.shop)
            billing_address.save()
            company.default_billing_address = billing_address
            company.default_shipping_address = billing_address
            company.save()
            company.shops.add(self.request.shop)
            company.members.add(person)

        company_registration_save.send(sender=type(self),
                                       request=self.request,
                                       user=user,
                                       company=company)
        return user
Пример #2
0
    def save(self, commit=True):
        with atomic():
            company = self.forms["company"].save(commit=False)
            billing_address = self.forms["billing"].save(commit=False)
            person = self.forms["contact_person"].save(commit=False)
            user = self.forms["user_account"].save(commit=False)

            company.default_billing_address = billing_address
            company.default_shipping_address = billing_address

            for field in ["name", "name_ext", "email", "phone"]:
                setattr(billing_address, field, getattr(company, field))

            person.user = user

            user.first_name = person.first_name
            user.last_name = person.last_name
            user.email = person.email

            # If company registration requires approval,
            # company and person contacts will be created as inactive
            if company_registration_requires_approval(self.request.shop):
                company.is_active = False
                person.is_active = False

            user.save()
            person.user = user
            person.save()
            person.shops.add(self.request.shop)
            billing_address.save()
            company.default_billing_address = billing_address
            company.default_shipping_address = billing_address
            company.save()
            company.add_to_shop(self.request.shop)
            company.members.add(person)

        company_registration_save.send(sender=type(self),
                                       request=self.request,
                                       user=user,
                                       company=company)
        return user
Пример #3
0
    def save(self, commit=True):
        company = self.forms['company'].save(commit=False)
        billing_address = self.forms['billing'].save(commit=False)
        person = self.forms['contact_person'].save(commit=False)
        user = self.forms['user_account'].save(commit=False)

        company.default_billing_address = billing_address
        company.default_shipping_address = billing_address

        for field in ['name', 'name_ext', 'email', 'phone']:
            setattr(billing_address, field, getattr(company, field))

        person.user = user

        user.first_name = person.first_name
        user.last_name = person.last_name
        user.email = person.email

        # If company registration requires approval,
        # company and person contacts will be created as inactive
        if company_registration_requires_approval(self.request.shop):
            company.is_active = False
            person.is_active = False

        if commit:
            user.save()
            person.user = user
            person.save()
            person.shops.add(self.request.shop)
            billing_address.save()
            company.default_billing_address = billing_address
            company.default_shipping_address = billing_address
            company.save()
            company.add_to_shop(self.request.shop)
            company.members.add(person)

        company_registration_save.send(sender=type(self), request=self.request, user=user, company=company)
        return user