def test_old_invoices_are_marked_as_created(self): # previous year with freeze_time('2016-11-01'): invoice1 = factories.InvoiceFactory() # previous month with freeze_time('2017-01-15'): invoice2 = factories.InvoiceFactory() with freeze_time('2017-02-4'): tasks.create_monthly_invoices() invoice1.refresh_from_db() self.assertEqual( invoice1.state, models.Invoice.States.CREATED, 'Invoice for previous year is not marked as CREATED', ) invoice2.refresh_from_db() self.assertEqual( invoice2.state, models.Invoice.States.CREATED, 'Invoice for previous month is not marked as CREATED', )
def setUp(self): self.tenant = openstack_factories.TenantFactory() self.project = self.tenant.service_project_link.project self.resource = marketplace_factories.ResourceFactory( project=self.project) self.resource.scope = self.tenant self.resource.save() self.order = marketplace_factories.OrderFactory(project=self.project) marketplace_factories.OrderItemFactory(resource=self.resource, order=self.order) self.new_project = structure_factories.ProjectFactory() self.start_invoice = invoices_factories.InvoiceFactory( customer=self.project.customer, year=2020, month=1, state=invoices_models.Invoice.States.PENDING, ) invoices_factories.InvoiceItemFactory( invoice=self.start_invoice, project=self.project, scope=self.resource, ) self.target_invoice = invoices_factories.InvoiceFactory( customer=self.new_project.customer, year=2020, month=1, state=invoices_models.Invoice.States.PENDING, )
def setUp(self): self.fixture = ServiceFixture() self.project = self.fixture.project self.resource = marketplace_factories.ResourceFactory( project=self.project) self.resource.scope = self.fixture.volume self.resource.save() resource_offering = self.resource.offering resource_offering.scope = self.fixture.service_settings resource_offering.save() self.order = marketplace_factories.OrderFactory(project=self.project) marketplace_factories.OrderItemFactory(resource=self.resource, order=self.order) self.new_project = structure_factories.ProjectFactory() self.start_invoice = invoices_factories.InvoiceFactory( customer=self.project.customer, year=2020, month=1, state=invoices_models.Invoice.States.PENDING, ) invoices_factories.InvoiceItemFactory( invoice=self.start_invoice, project=self.project, resource=self.resource, ) self.target_invoice = invoices_factories.InvoiceFactory( customer=self.new_project.customer, year=2020, month=1, state=invoices_models.Invoice.States.PENDING, )
def test_move_resource_exception_handling(self): start_invoice = invoices_factories.InvoiceFactory( customer=self.project.customer, year=2020, month=1, state=invoices_models.Invoice.States.PENDING, ) invoices_factories.InvoiceItemFactory( invoice=start_invoice, project=self.project, resource=self.resource, ) invoices_factories.InvoiceFactory( customer=self.new_project.customer, year=2020, month=1, state=invoices_models.Invoice.States.CREATED, ) response = self.get_response(self.fixture.staff) self.resource.refresh_from_db() self.assertEqual(response.status_code, status.HTTP_409_CONFLICT) self.assertEqual( response.json(), { 'error_message': 'Resource moving is not possible, because invoice items moving is not possible.' }, ) self.assertEqual(self.resource.project, self.project)
def setUp(self): self.fixture = structure_fixtures.CustomerFixture() self.fixture.owner self.invoice = factories.InvoiceFactory(customer=self.fixture.customer) self.patcher = mock.patch('waldur_mastermind.invoices.utils.pdfkit') mock_pdfkit = self.patcher.start() mock_pdfkit.from_string.return_value = b'pdf content'
def test_price_estimate_for_customer_is_updated_when_invoice_is_created(self): estimate = models.PriceEstimate.objects.get(scope=self.fixture.customer) estimate.total = 100 estimate.save() invoice_factories.InvoiceFactory(customer=self.fixture.customer) estimate.refresh_from_db() self.assertEqual(estimate.total, 0)
def test_do_not_link_payment_to_invoice_if_customers_are_different(self): self.client.force_authenticate(self.fixture.staff) invoice = factories.InvoiceFactory(state=models.Invoice.States.PAID) payload = { 'invoice': factories.InvoiceFactory.get_url(invoice=invoice) } response = self.client.post(self.url, payload) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def setUp(self): for price in [200, 100, 300]: project = structure_factories.ProjectFactory() invoice = invoice_factories.InvoiceFactory( customer=project.customer) invoice_factories.GenericInvoiceItemFactory( invoice=invoice, project=project, unit_price=price, quantity=1, unit=invoice_models.InvoiceItem.Units.QUANTITY)
def setUp(self): self.fixture = structure_fixtures.ProjectFixture() self.profile = factories.PaymentProfileFactory( organization=self.fixture.customer) self.payment = factories.PaymentFactory(profile=self.profile) self.invoice = factories.InvoiceFactory( customer=self.fixture.customer, state=models.Invoice.States.PAID) self.url = factories.PaymentFactory.get_url(payment=self.payment, action='link_to_invoice') self.url_unlink = factories.PaymentFactory.get_url( payment=self.payment, action='unlink_from_invoice')
def test_when_invoice_item_is_created_total_is_updated(self, scope): invoice = invoice_factories.InvoiceFactory( customer=self.fixture.customer) invoice_factories.InvoiceItemFactory(invoice=invoice, project=self.fixture.project, unit_price=10, quantity=31) estimate = models.PriceEstimate.objects.get( scope=getattr(self.fixture, scope)) self.assertAlmostEqual( decimal.Decimal(estimate.total), decimal.Decimal(10 * 31), )
def test_report_context(self): invoice_1 = factories.InvoiceFactory() invoice_2 = factories.InvoiceFactory() invoice_3 = factories.InvoiceFactory() factories.PaymentProfileFactory( organization=invoice_1.customer, payment_type=models.PaymentType.FIXED_PRICE, is_active=True, attributes={ 'end_date': '2017-10-01', 'contract_sum': 100 }, ) factories.PaymentProfileFactory( organization=invoice_2.customer, payment_type=models.PaymentType.FIXED_PRICE, is_active=True, ) factories.PaymentProfileFactory( organization=invoice_2.customer, payment_type=models.PaymentType.FIXED_PRICE, is_active=False, ) context = invoices_utils.get_monthly_invoicing_reports_context() self.assertEqual(len(context['invoices']), 1) self.assertEqual(context['invoices'][0], invoice_3) self.assertEqual(len(context['contracts']), 2) customer_1_context = [ c for c in context['contracts'] if c['name'] == invoice_1.customer.abbreviation ][0] self.assertEqual(customer_1_context['end_date_alarm'], True) self.assertEqual(customer_1_context['payments_alarm'], True) customer_2_context = [ c for c in context['contracts'] if c['name'] == invoice_2.customer.abbreviation ][0] self.assertEqual(customer_2_context['end_date_alarm'], False) self.assertEqual(customer_2_context['payments_alarm'], None)
def setUp(self): self.prices = [200, 100, 300, 0] customers = structure_factories.CustomerFactory.create_batch(len(self.prices)) for (customer, price) in zip(customers, self.prices): if price == 0: continue project = structure_factories.ProjectFactory(customer=customer) invoice = invoice_factories.InvoiceFactory(customer=customer) invoice_factories.InvoiceItemFactory( invoice=invoice, project=project, unit_price=price, quantity=1, unit=invoice_models.InvoiceItem.Units.QUANTITY, )
def test_existing_invoice_is_updated_on_resource_creation(self): start_date = timezone.datetime(2014, 2, 27, tzinfo=pytz.UTC) end_date = core_utils.month_end(start_date) usage_days = utils.get_full_days(start_date, end_date) month_days = monthrange(start_date.year, start_date.month)[1] factor = quantize_price(decimal.Decimal(usage_days) / month_days) with freeze_time(start_date): invoice = factories.InvoiceFactory(customer=self.fixture.customer) self.resource.set_state_ok() self.resource.save() self.assertEqual(models.Invoice.objects.count(), 1) self.assertTrue(invoice.items.filter(resource=self.resource).exists()) expected_price = self.plan_component.price * factor self.assertEqual(invoice.price, Decimal(expected_price))
def test_default_tax_percent_is_used_on_invoice_creation(self): customer = structure_factories.CustomerFactory() customer.default_tax_percent = 20 customer.save() invoice = invoices_factories.InvoiceFactory(customer=customer) self.assertEqual(invoice.tax_percent, customer.default_tax_percent)
def setUp(self): self.fixture = structure_fixtures.ProjectFixture() self.invoice = factories.InvoiceFactory(customer=self.fixture.customer) self.url = structure_factories.CustomerFactory.get_url( self.fixture.customer)
def setUp(self): super(UpdateInvoiceCurrentCostTest, self).setUp() self.project = structure_factories.ProjectFactory() self.invoice = factories.InvoiceFactory(customer=self.project.customer)
def setUp(self): self.fixture = fixtures.ExpertsFixture() self.registrator = registrators.ExpertRequestRegistrator() self.invoice = invoice_factories.InvoiceFactory()