Skip to content

Commit f129627

Browse files
committed
refactor: code refactoring
1 parent feef2db commit f129627

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# openimis-be-invoice_payment_py
1+
# openimis-be-invoice_py
22

33
OpenIMIS backend module for invoices, bills, and payments.
44

invoice/migrations/0014_bill_code_sequence.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ def apply_bill_code_trigger(apps, schema_editor):
158158
_pg_apply(schema_editor)
159159
elif vendor == 'microsoft':
160160
_mssql_apply(schema_editor)
161+
else:
162+
raise RuntimeError(
163+
f"Unsupported DB vendor '{vendor}' for bill code trigger migration; "
164+
"only 'postgresql' and 'microsoft' are supported."
165+
)
161166

162167

163168
def reverse_bill_code_trigger(apps, schema_editor):
@@ -166,6 +171,11 @@ def reverse_bill_code_trigger(apps, schema_editor):
166171
_pg_reverse(schema_editor)
167172
elif vendor == 'microsoft':
168173
_mssql_reverse(schema_editor)
174+
else:
175+
raise RuntimeError(
176+
f"Unsupported DB vendor '{vendor}' for bill code trigger reverse migration; "
177+
"only 'postgresql' and 'microsoft' are supported."
178+
)
169179

170180

171181
class Migration(migrations.Migration):

invoice/services/bill.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import decimal
22
from typing import Union, List
33

4+
from simple_history.utils import bulk_create_with_history
5+
46
from invoice.models import Bill, BillItem
57
from core.services import BaseService
68
from invoice.services.billLineItem import BillLineItemService
@@ -84,7 +86,7 @@ def _evaluate_generic_types(self, bill_data):
8486

8587
@classmethod
8688
def bulk_create_bills(cls, bills):
87-
created = Bill.objects.bulk_create(bills, batch_size=BULK_CREATE_BATCH_SIZE)
89+
created = bulk_create_with_history(bills, Bill, batch_size=BULK_CREATE_BATCH_SIZE)
8890
# Re-fetch codes assigned by DB trigger for rows that had empty codes.
8991
empty_code_ids = [b.id for b in created if not b.code]
9092
if empty_code_ids:
@@ -99,4 +101,4 @@ def bulk_create_bills(cls, bills):
99101

100102
@classmethod
101103
def bulk_create_bill_items(cls, bill_items):
102-
return BillItem.objects.bulk_create(bill_items, batch_size=BULK_CREATE_BATCH_SIZE)
104+
return bulk_create_with_history(bill_items, BillItem, batch_size=BULK_CREATE_BATCH_SIZE)

0 commit comments

Comments
 (0)