Example #1
0
    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()
Example #2
0
    def setUp(self):
        """
        Set up the view 
        
        -login the user
        """
        super(SupplyAPITest, self).setUp()

        self.create_user()
        self.client.login(username='******', password='******')

        self.supplier = Supplier(**base_supplier)
        self.supplier.save()
        self.supplier2 = Supplier.objects.create(**base_supplier)
        self.supply = Supply.create(**base_supply)
        self.assertIsNotNone(self.supply.pk)
        self.supply2 = Supply.create(**base_supply)
        self.assertIsNotNone(self.supply2.pk)
        self.supply3 = Supply.create(**base_supply)
        self.assertIsNotNone(self.supply3.pk)
        self.supply4 = Supply.create(**base_supply)
        self.assertIsNotNone(self.supply4.pk)

        self.product = Product(supplier=self.supplier, supply=self.supply)
        self.product.save()

        self.employee = Employee(first_name="John", last_name="Smith")
        self.employee.save()
Example #3
0
    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()
Example #4
0
    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)
Example #5
0
    def setUp(self):
        """
        Set up the view 
        
        -login the user
        """
        super(FabricAPITestCase, self).setUp()

        self.create_user()
        self.client.login(username='******', password='******')

        self.supplier = Supplier(**base_supplier)
        self.supplier.save()
        self.supply = Fabric.create(**base_fabric)
        self.assertIsNotNone(self.supply.pk)
        self.supply2 = Fabric.create(**base_fabric)
        self.assertIsNotNone(self.supply.pk)

        self.product = Product(supplier=self.supplier, supply=self.supply)
        self.product.save()
Example #6
0
    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)
Example #7
0
    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()
Example #8
0
    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()