Skip to content

Commit 7b7c2d1

Browse files
JanJan
andauthored
CM-342: filter only not assigned bills (#15)
* CM-342: filter only not assigned bills * CM-342: provide more strict filtering * CM-342: add translations --------- Co-authored-by: Jan <[email protected]>
1 parent 87f11af commit 7b7c2d1

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

locale/en/LC_MESSAGES/django.po

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
msgid "payroll.validation.payroll.bill_already_assigned"
2+
msgstr "Bills %(bill_ids) already assigned to payroll."
3+
4+
msgid "payroll.validation.payroll.no_bills_for_filter_criteria"
5+
msgstr "Bills not found for given search criteria."
6+
7+
msgid "payroll.validation.payroll.name_exists"
8+
msgstr "Name %(name) already exists."
9+
10+
msgid "payroll.validation.field_empty"
11+
msgstr "Field %(field) can not be empty."

payroll/services.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ def _get_bills_queryset(self, obj_data, included_unpaid):
128128
date_bill__range=(date_from, date_to),
129129
subject_type=ContentType.objects.get_for_model(Beneficiary),
130130
subject_id__in=beneficiary_ids,
131-
status__in=[Bill.Status.VALIDATED]
131+
status__in=[Bill.Status.VALIDATED],
132+
)
133+
134+
bills_queryset = bills_queryset.filter(
135+
Q(payrollbill__isnull=True) | Q(payrollbill__is_deleted=True)
132136
)
133137

134138
if included_unpaid:

payroll/validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def are_bills_in_data(data):
5050

5151
def validate_one_payroll_per_bill(data):
5252
bills = data.get('bills', [])
53-
query = PayrollBill.objects.filter(bill__in=bills)
53+
query = PayrollBill.objects.filter(bill__in=bills, is_deleted=False)
5454
if query.exists():
5555
payroll_bill_ids = list(query.values_list('id', flat=True))
5656
return [{"message": _("payroll.validation.payroll.bill_already_assigned") % {

0 commit comments

Comments
 (0)