def create_tenant(tenant_name, attached_users=[]): from django.contrib.auth.models import Group from core.models import Tenant, FRRegistrationInfo from contacts.models import Address from invoicing.models import Currency tenant = Tenant( name=tenant_name, email='*****@*****.**', postal_address=Address(street_address='Street address'), billing_address=Address(street_address='Street address'), registration_info=FRRegistrationInfo( share_capital='100 000 EUR', siret='123 456 789 012 00001', rcs_number='PARIS 005', vat_number='FR01234567890')) # Tenant settings tenant.tenant_settings.invoicing.supported_currencies = [ Currency.objects.get(symbol='EUR'), Currency.objects.get(symbol='USD') ] tenant.tenant_settings.invoicing.default_currency = Currency.objects.get( symbol='EUR') tenant.save() group = Group.objects.get(name=tenant.slug) for attached_user in attached_users: group.user_set.add(attached_user) group.save() return tenant
def setUp(self): super(SupplierResourceTest, self).setUp() #Create the user self.username = '******' self.password = '******' self.user = User.objects.create_user(self.username, '*****@*****.**', self.password) self.client.force_authenticate(self.user) self.supplier_data = supplier_data self.supplier_data['addresses'] = [base_address] self.mod_supplier_data = self.supplier_data.copy() del self.mod_supplier_data['addresses'] try: del self.mod_supplier_data['contacts'] except KeyError: pass self.supplier = Supplier(**self.mod_supplier_data) self.supplier.is_supplier = True self.supplier.save() self.address = Address(**base_address) self.address.contact = self.supplier self.address.save() self.contact = SupplierContact(**base_supplier_contact[0]) self.contact.supplier = self.supplier self.contact.save()
def new_contact(request): data = {} template = 'contacts/new_contact.html' data['message'] = None if request.method == "POST": data['form'] = ContactForm(request.POST) if data['form'].is_valid(): # each Address has a User ID # TODO: if email exists - solve this passwd = User.objects.make_random_password() user = User(username=data['form'].cleaned_data['searchname'], email=data['form'].cleaned_data['email'], password=passwd) user.save() adr = Address( adr_searchname=data['form'].cleaned_data['searchname'], adr_email=data['form'].cleaned_data['email'], adr_user_id=user, ) adr.save() contacttypes = ContactType.objects.all() for ct_type in contacttypes: ctdata = ContactData( cd_contacttype_id=ct_type, cd_textfield=data['form'].cleaned_data['{index}'.format( index=ct_type.id)], cd_address_id=adr) ctdata.save() return redirect('proj_contacts') else: data['form'] = ContactForm() print data return render(request, template, data)
def setUp(self): """ Set up dependent objects """ super(ItemTest, self).setUp() self.ct = ContentType(app_label="po") self.ct.save() self.p = Permission(codename="add_purchaseorder", content_type=self.ct) self.p.save() self.p2 = Permission(codename="change_purchaseorder", content_type=self.ct) self.p2.save() #Create the user self.username = '******' self.password = '******' self.user = User.objects.create_user( self.username, '*****@*****.**', self.password) self.user.save() self.user.user_permissions.add(self.p) self.user.user_permissions.add(self.p2) self.client.login(username=self.username, password=self.password) self.supplier = Supplier(**base_supplier) self.supplier.save() self.address = Address(**base_address) self.address.contact = self.supplier self.address.save() self.contact = SupplierContact(name='test', email='*****@*****.**', telephone=1234, primary=True) self.contact.supplier = self.supplier self.contact.save() self.supply = Fabric.create(**base_fabric) #self.supply.units = "m^2" self.supply.save() self.po = PurchaseOrder() self.po.employee = self.user self.po.supplier = self.supplier self.po.terms = self.supplier.terms self.po.vat = 7 self.po.order_date = datetime.datetime(2014, 3, 2) self.po.save() self.item = Item(unit_cost=Decimal('13.55'), quantity=Decimal('10'), supply=self.supply) self.item.description = self.supply.description self.item.purchase_order = self.po self.item.save()
def fill_tenant_initial_data(tenant, language_code): """ This task creates inital data when a new :class:`~core.models.Tenant` is created """ from core.models import VosaeUser from contacts.models import Contact, Organization, Email, Address from invoicing.models import Item, Tax, Currency with respect_language(language_code): initial_vosae_user = VosaeUser.objects.get(tenant=tenant) # Creates default taxes, based on registration country for tax_percent, tax_name in tenant.registration_info.DEFAULT_TAXES: Tax(tenant=tenant, name=tax_name, rate=tax_percent).save() # Creates a shared organization Organization( tenant=tenant, creator=initial_vosae_user, corporate_name=u'Vosae', emails=[ Email(type=u'WORK', email=u'*****@*****.**') ], addresses=[ Address(type=u'WORK', street_address=u'35 Rue Lesdiguières', postal_code=u'38000', city=u'Grenoble', country=u'France') ], note=_('We\'d like to make it right'), private=False ).save() # Creates a shared contact Contact( tenant=tenant, creator=initial_vosae_user, name=_('Support'), firstname=u'Vosae', role=_('The best support'), emails=[ Email(type=u'WORK', email=u'*****@*****.**') ], organization=Organization.objects.get(tenant=tenant, corporate_name=u'Vosae'), private=False ).save() # Creates an item Item( tenant=tenant, reference=_('TEST-ITEM'), description=_('Test item'), unit_price=Decimal('1000'), currency=Currency.objects.get(symbol='EUR'), tax=Tax.objects.filter(tenant=tenant).first(), type=u'SERVICE' ).save()
def edit_contact(request, address_id): message = None contacttypes = ContactType.objects.all() categories = Category.objects.all() if request.method == "POST": form = ContactForm(request.POST) if form.is_valid(): adr = Address(id=address_id, adr_searchname=form.cleaned_data['searchname'], adr_email=form.cleaned_data['email']) adr.save() # TODO: ct_type proof need to be implemented for ct_type in contacttypes: cd_id = ContactData.objects.filter( cd_contacttype_id__id=ct_type.id, cd_address_id__id=address_id) if len(cd_id) > 0: ctdata = ContactData( id=cd_id, cd_contacttype_id=ct_type, cd_textfield=form.cleaned_data['{index}'.format( index=ct_type.id)], cd_address_id=adr) else: ctdata = ContactData( cd_contacttype_id=ct_type, cd_textfield=form.cleaned_data['{index}'.format( index=ct_type.id)], cd_address_id=adr) print(ctdata, cd_id) ctdata.save() return redirect('all_contacts') else: adr = get_object_or_404(Address, pk=address_id) datadict = {'searchname': adr.adr_searchname, 'email': adr.adr_email} adr_data = ContactData.objects.filter( cd_address_id=address_id).order_by('cd_contacttype_id__ct_sort_id') for adr_element in adr_data: datadict['{index}'.format(index=adr_element.cd_contacttype_id.id )] = adr_element.cd_textfield form = ContactForm( initial=datadict ) # TODO: datadict index out of contacttype_id and catagory_id for Tab's # or send filtered by category and ordered and give a list with the stop-point return render(request, 'contacts/edit_contact.html', { 'address': adr, 'message': message, 'form': form, 'categories': categories })
def setUp(self): """ Sets up environment for tests """ super(TestItemResource, self).setUp() self.create_user() self.client.login(username='******', password='******') #Create supplier, customer and addrss self.customer = Customer(**base_customer) self.customer.save() self.supplier = Supplier(**base_supplier) self.supplier.save() self.address = Address(address1="Jiggle", contact=self.customer) self.address.save() #Create a product to add self.product = Product.create(self.user, **base_product) self.product.save() self.fabric = Fabric.create(**base_fabric) f_data = base_fabric.copy() f_data["pattern"] = "Stripe" self.fabric2 = Fabric.create(**f_data) #Create acknowledgement ack_data = base_ack.copy() del ack_data['customer'] del ack_data['items'] del ack_data['employee'] del ack_data['project'] self.ack = Estimate(**ack_data) self.ack.customer = self.customer self.ack.employee = self.user self.ack.save() #Create an item self.item_data = { 'id': 1, 'quantity': 1, 'is_custom_size': True, 'width': 1500, "fabric": { "id": 1 } } self.item = Item.create(acknowledgement=self.ack, **self.item_data)
def setUp(self): super(CustomerResourceTest, self).setUp() #Create the user self.username = '******' self.password = '******' self.user = User.objects.create_user(self.username, '*****@*****.**', self.password) self.client.force_authenticate(self.user) self.customer = Customer(**base_contact) self.customer.is_customer = True self.customer.save() self.address = Address(**base_address) self.address.contact = self.customer self.address.save()
def setUp(self): """ Set up for the Acknowledgement Test Objects created: -User -Customer -Supplier -Address -product -2 fabrics After Creating all the needed objects for the Acknowledgement, test that all the objects have been made. """ super(ShippingResourceTest, self).setUp() self.ct = ContentType(app_label="shipping") self.ct.save() #Create the user self.username = '******' self.password = '******' self.user = User.objects.create_user(self.username, '*****@*****.**', self.password) self.user.save() p = Permission(content_type=self.ct, codename="change_shipping") p.save() p2 = Permission(content_type=self.ct, codename="add_shipping") p2.save() self.user.user_permissions.add(p) self.user.user_permissions.add(p2) self.user.save() self.setup_client() #Create supplier, customer and addrss self.customer = Customer(**base_customer) self.customer.save() self.supplier = Supplier(**base_supplier) self.supplier.save() self.address = Address(address1="Jiggle", contact=self.customer) self.address.save() #Create project self.project = Project.objects.create(codename="Ladawan") #Create phase self.phase = Phase.objects.create(description="Phase 1/6", project=self.project) #Create a product to add self.product = Product.create(self.user, **base_product) self.product.save() self.fabric = Fabric.create(**base_fabric) f_data = base_fabric.copy() f_data["pattern"] = "Stripe" self.fabric2 = Fabric.create(**f_data) #Create acknowledgement ack_data = base_ack.copy() del ack_data['customer'] del ack_data['items'] del ack_data['employee'] self.ack = Acknowledgement(**ack_data) self.ack.customer = self.customer self.ack.employee = self.user self.ack.save() #Create an item item_data = { 'id': 1, 'quantity': 1, 'is_custom_size': True, 'width': 1500, "fabric": { "id": 1 } } self.item = AckItem.create(acknowledgement=self.ack, **item_data) #Create an item item_data = { 'id': 1, 'quantity': 2, 'is_custom_size': True, 'width': 1500, "fabric": { "id": 1 } } self.item2 = AckItem.create(acknowledgement=self.ack, **item_data)
def setUp(self): """ Set up for the Estimate Test Objects created: -User -Customer -Supplier -Address -product -2 fabrics After Creating all the needed objects for the Estimate, test that all the objects have been made. """ super(EstimateResourceTest, self).setUp() # Set Base URL self.base_url = '{0}'.format('/api/v1/estimate/') self.ct = ContentType(app_label="estimates") self.ct.save() #Create the user self.username = '******' self.password = '******' self.user = User.objects.create_user(self.username, '*****@*****.**', self.password) p = Permission(content_type=self.ct, codename="change_estimate") p.save() p2 = Permission(content_type=self.ct, codename="add_estimate") p2.save() self.user.user_permissions.add(p) self.user.user_permissions.add(p2) self.user.save() self.setup_client() #Create supplier, customer and addrss customer = copy.deepcopy(base_customer) del customer['id'] self.customer = Customer(**customer) self.customer.save() self.supplier = Supplier(**base_supplier) self.supplier.save() self.address = Address(address1="Jiggle", contact=self.customer) self.address.save() #Create a product to add self.product = Product.create(self.user, **base_product) self.product.save() #Create custom product self.custom_product = Product() self.custom_product.id = 10436 self.custom_product.save() self.fabric = Fabric.create(**base_fabric) self.fabric.quantity = 26 self.fabric.save() f_data = base_fabric.copy() f_data["pattern"] = "Stripe" self.fabric2 = Fabric.create(**f_data) #Create custom product self.custom_product = Product.create(self.user, description="Custom Custom", id=10436, width=0, depth=0, height=0, price=0, wholesale_price=0, retail_price=0) self.custom_product.id = 10436 self.custom_product.save() self.image = S3Object(key='test', bucket='test') self.image.save() #Create acknowledgement ack_data = base_ack.copy() del ack_data['customer'] del ack_data['items'] del ack_data['employee'] del ack_data['project'] self.ack = Estimate(**ack_data) self.ack.customer = self.customer self.ack.employee = self.user self.ack.save() #Create an item item_data = { 'id': 1, 'quantity': 1, 'is_custom_size': True, 'width': 1500, "fabric": { "id": 1 } } self.item = Item.create(estimate=self.ack, **item_data) item_data = { 'is_custom': True, 'description': 'F-04 Sofa', 'quantity': 3 } self.item2 = Item.create(estimate=self.ack, **item_data) #Create fake S3Objects to test files attached to acknowledgements self.file1 = S3Object(key='test1', bucket='test') self.file2 = S3Object(key='test2', bucket='test') self.file1.save() self.file2.save()
def setUp(self): """ Set up dependent objects """ super(PurchaseOrderTest, self).setUp() self.ct = ContentType(app_label="po") self.ct.save() self.p = Permission(codename="add_purchaseorder", content_type=self.ct) self.p.save() self.p2 = Permission(codename="change_purchaseorder", content_type=self.ct) self.p2.save() #Create the user self.username = '******' self.password = '******' self.user = User.objects.create_user( self.username, '*****@*****.**', self.password) self.user.save() self.user.user_permissions.add(self.p) self.user.user_permissions.add(self.p2) self.client.login(username=self.username, password=self.password) self.client.force_authenticate(self.user) self.supplier = Supplier(**base_supplier) self.supplier.save() self.address = Address(**base_address) self.address.contact = self.supplier self.address.save() self.contact = SupplierContact(name='test', email='*****@*****.**', telephone=1234, primary=True) self.contact.supplier = self.supplier self.contact.save() # Create Custom Supply # not implemented # Create Fabric self.supply = Fabric.create(**base_fabric) #self.supply.units = "m^2" self.supply.save() self.supply1 = self.supply self.product = Product(supply=self.supply, supplier=self.supplier, cost=base_fabric['unit_cost'], purchasing_units='m') self.product.save() self.supply2 = Fabric.create(**base_fabric2) self.supply2.discount = 5 self.supply2.save() self.product2 = Product(supply=self.supply2, supplier=self.supplier, cost=base_fabric['unit_cost']) self.product2.save() self.supply1.supplier = self.supplier self.supply2.supplier = self.supplier #Create supply with no target item self.supply3 = Supply.objects.create(description='test supply') self.supply3.id = 203 self.supply3.save() #Create a project self.project = Project() self.project.codename = 'MC House' self.project.save() self.po = PurchaseOrder() self.po.employee = self.user self.po.supplier = self.supplier self.po.terms = self.supplier.terms self.po.vat = 7 self.order_date = datetime.datetime(2017, 1, 15, 15, 30, 0, 0, tzinfo=timezone('Asia/Bangkok')) self.po.order_date = self.order_date self.po.receive_date = datetime.datetime.now() self.po.save() #self.po.create_and_upload_pdf() self.item = Item.create(supplier=self.supplier, id=1, **base_purchase_order['items'][0]) self.item.purchase_order = self.po self.item.save() self.po.calculate_total() self.po.save()
def edit(request, contact_id=None): ''' Show the edit page for the current contact, or create a new one ''' exists = False if contact_id == None else True if request.method == 'POST': # save data contact = None street = request.POST.get('street') apartment = request.POST.get('apartment') city = request.POST.get('city') state = request.POST.get('state') zip = request.POST.get('zip') owned_by = request.user first_name = request.POST.get('first_name') last_name = request.POST.get('last_name') phone_number = request.POST.get('phone_number') email_address = request.POST.get('email_address') if exists: # if the contact already exists, update it - else add it contact = Contact.objects.get(id=contact_id) address = Address.objects.get(id=contact.address.id) address.street = street address.apartment = apartment address.city = city address.state = state address.zip = zip address.save() contact.first_name = first_name contact.last_name = last_name contact.phone_number = phone_number contact.email_address = email_address contact.address = address contact.save() else: # add the address address = Address(street=street, apartment=apartment, city=city, state=state, zip=zip) address.save() # add the contact contact = Contact(owned_by=owned_by, first_name=first_name, last_name=last_name, phone_number=phone_number, email_address=email_address, address=address) contact.save() return redirect('contacts:contacts') else: if contact_id == None: return render(request, 'contacts/edit.html', { 'contact': None, 'exists': exists }) else: contact = Contact.objects.get(id=contact_id) # check if contact belongs to logged in user if contact.owned_by == request.user: exists = True return render(request, 'contacts/edit.html', { 'contact': contact, 'exists': exists }) else: return redirect('contacts:contacts')