Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion care/emr/resources/invoice/sync_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def sync_invoice_items(invoice: Invoice):
care_method=settings.INVOICE_FINAL_AMOUNT_ROUNDING_METHOD,
)
if not invoice.is_refund and (invoice.total_net < 0 or invoice.total_gross < 0):
raise ValidationError("A Refund Ivoice is required for negative values")
raise ValidationError("A Refund Invoice is required for negative values")
invoice.total_price_components = json.loads(
json.dumps(
summary["total_price_components"],
Expand Down
43 changes: 43 additions & 0 deletions care/emr/tests/test_invoice_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,49 @@ def test_attach_account_to_invoice_attaches_all_billable_charge_items(self):
self.assertEqual(self.charge_item_1.paid_invoice, invoice)
self.assertEqual(self.charge_item_2.paid_invoice, invoice)

def test_attach_account_to_invoice_rejects_negative_total_without_refund(self):
role = self.create_role_with_permissions(
[
InvoicePermissions.can_read_invoice.name,
InvoicePermissions.can_write_invoice.name,
]
)
self.attach_role_facility_organization_user(self.organization, self.user, role)
self.client.force_authenticate(user=self.user)

baker.make(
"emr.ChargeItem",
facility=self.facility,
patient=self.patient,
encounter=self.encounter,
account=self.account,
status=ChargeItemStatusOptions.billable.value,
quantity=Decimal("1.00"),
unit_price_components=[{"amount": -500, "monetary_component_type": "base"}],
total_price_components=[
{"amount": -500, "monetary_component_type": "base"}
],
total_price=Decimal("-500.00"),
)

invoice = baker.make(
"emr.Invoice",
facility=self.facility,
account=self.account,
patient=self.patient,
status=InvoiceStatusOptions.draft.value,
is_refund=False,
total_net=Decimal("0.00"),
total_gross=Decimal("0.00"),
)

response = self.client.post(self._get_url(invoice.external_id))
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
response.json()["errors"][0]["msg"],
"A Refund Invoice is required for negative values",
)

def test_attach_account_to_invoice_requires_draft_status(self):
role = self.create_role_with_permissions(
[
Expand Down
Loading