def test_invoice_total_with_tax_integrity(self): invoice_entries = DocumentEntryFactory.create_batch(5) invoice = InvoiceFactory.create(invoice_entries=invoice_entries) invoice.sales_tax_percent = Decimal('20.00') self.assertEqual(invoice.total, invoice.total_before_tax + invoice.tax_value)
def test_documents_list_case_1(self): """ One proforma, one invoice, without related documents """ proforma = ProformaFactory.create() invoice_entries = DocumentEntryFactory.create_batch(3) invoice = InvoiceFactory.create(invoice_entries=invoice_entries) invoice.issue() payment_method = PaymentMethodFactory.create(customer=invoice.customer) transaction = TransactionFactory.create(payment_method=payment_method, invoice=invoice) url = reverse('document-list') with patch('silver.utils.payments._get_jwt_token', new=self._jwt_token): response = self.client.get(url) # ^ there's a bug where specifying format='json' doesn't work response_data = response.data self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response_data), 2) self.assertIn(self._get_expected_data(invoice, [transaction]), response_data) self.assertIn(self._get_expected_data(proforma), response_data)
def test_invoice_tax_value_decimal_places(self): invoice_entries = DocumentEntryFactory.create_batch(3) invoice = InvoiceFactory.create(invoice_entries=invoice_entries) invoice.sales_tax_percent = Decimal('20.00') assert self._get_decimal_places(invoice.tax_value) == 2
def test_proforma_total_with_tax_integrity(self): proforma_entries = DocumentEntryFactory.create_batch(5) proforma = ProformaFactory.create(proforma_entries=proforma_entries) proforma.sales_tax_percent = Decimal('20.00') assert proforma.total == proforma.total_before_tax + proforma.tax_value
def test_proforma_tax_value_decimal_places(self): proforma_entries = DocumentEntryFactory.create_batch(3) proforma = ProformaFactory.create(proforma_entries=proforma_entries) proforma.sales_tax_percent = Decimal('20.00') assert self._get_decimal_places(proforma.tax_value) == 2
def test_add_transaction_without_currency_and_amount(self): customer = CustomerFactory.create() payment_method = PaymentMethodFactory.create(customer=customer) entries = DocumentEntryFactory.create_batch(2) proforma = ProformaFactory.create(customer=customer, state=Proforma.STATES.ISSUED, issue_date=timezone.now().date(), currency='USD', transaction_currency='RON', transaction_xe_rate=Decimal('0.25'), proforma_entries=entries) proforma.create_invoice() invoice = proforma.related_document valid_until = datetime.now().replace(microsecond=0) + timedelta( minutes=30) url = reverse('payment-method-transaction-list', kwargs={ 'customer_pk': customer.pk, 'payment_method_id': payment_method.pk }) payment_method_url = reverse('payment-method-detail', kwargs={ 'customer_pk': customer.pk, 'payment_method_id': payment_method.id }) invoice_url = reverse('invoice-detail', args=[invoice.pk]) proforma_url = reverse('proforma-detail', args=[proforma.pk]) data = { 'payment_method': reverse('payment-method-detail', kwargs={ 'customer_pk': customer.pk, 'payment_method_id': payment_method.id }), 'valid_until': valid_until, 'invoice': invoice_url, 'proforma': proforma_url } response = self.client.post(url, format='json', data=data) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.data['payment_method'], payment_method_url) self.assertEqual(response.data['valid_until'][:-1], valid_until.isoformat()) self.assertEqual(response.data['can_be_consumed'], True) self.assertEqual(response.data['amount'], force_str(invoice.total_in_transaction_currency)) self.assertEqual(response.data['invoice'], invoice_url) self.assertEqual(response.data['proforma'], proforma_url) self.assertEqual(response.data['currency'], invoice.transaction_currency)
def test_clone_proforma_into_draft(self): proforma = ProformaFactory.create() proforma.issue() proforma.pay() entries = DocumentEntryFactory.create_batch(3) proforma.proforma_entries.add(*entries) clone = proforma.clone_into_draft() assert clone.state == Proforma.STATES.DRAFT assert clone.paid_date is None assert clone.issue_date is None assert clone.related_document is None assert (clone.series != proforma.series or clone.number != proforma.number) assert clone.sales_tax_percent == proforma.sales_tax_percent assert clone.sales_tax_name == proforma.sales_tax_name assert not clone.archived_customer assert not clone.archived_provider assert clone.customer == proforma.customer assert clone.provider == proforma.provider assert clone.currency == proforma.currency assert clone._last_state == clone.state assert clone.pk != proforma.pk assert clone.id != proforma.id assert not clone.pdf assert clone.proforma_entries.count() == 3 assert proforma.proforma_entries.count() == 3 entry_fields = [ entry.name for entry in DocumentEntry._meta.get_fields() ] for clone_entry, original_entry in zip( clone.proforma_entries.all(), proforma.proforma_entries.all()): for entry in entry_fields: if entry not in ('id', 'proforma', 'invoice'): assert getattr(clone_entry, entry) == \ getattr(original_entry, entry) assert proforma.state == Proforma.STATES.PAID
def test_invoice_total_decimal_points(self): invoice_entries = DocumentEntryFactory.create_batch(3) invoice = InvoiceFactory.create(invoice_entries=invoice_entries) assert self._get_decimal_places(invoice.total) == 2
def test_proforma_total_decimal_points(self): proforma_entries = DocumentEntryFactory.create_batch(3) proforma = ProformaFactory.create(proforma_entries=proforma_entries) assert self._get_decimal_places(proforma.total) == 2