This commit is contained in:
anhduy-tech
2026-01-09 08:21:01 +07:00
parent 8df7572ed0
commit 2b6498133f
10 changed files with 59 additions and 1 deletions

View File

@@ -0,0 +1,17 @@
# Generated by Django 5.1.7 on 2026-01-08 16:56
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('app', '0350_transaction_current'),
]
operations = [
migrations.RemoveField(
model_name='transaction_detail',
name='amount_recived',
),
]

View File

@@ -1390,7 +1390,6 @@ class Transaction_Detail(AutoCodeModel):
status = models.ForeignKey(Transaction_Status, null=True, related_name='+', on_delete=models.PROTECT, default=1)
approver = models.ForeignKey(User, null=True, related_name='+', on_delete=models.PROTECT)
approve_time = models.DateTimeField(null=True)
amount_recived = models.DecimalField(max_digits=15, decimal_places=2, null=True)
create_time = models.DateTimeField(null=True, auto_now_add=True)
update_time = models.DateTimeField(null=True, auto_now=True)

View File

@@ -86,6 +86,48 @@ def resolve_value(expr, context):
target_list.append(element_to_append)
return target_list
# =============================================
# 2.2. Hàm tổng hợp list: $agg(list, operation, field?)
# =============================================
agg_match = re.match(r"^\$agg\(([^,]+),\s*'([^']+)'(?:,\s*['\"]?([^'\"]+)['\"]?)?\)$", expr.strip())
if agg_match:
list_expr = agg_match.group(1).strip()
operation = agg_match.group(2).strip()
field_expr = agg_match.group(3).strip() if agg_match.group(3) else None
# 1. Resolve the list
target_list = resolve_value(list_expr, context)
if target_list is None:
target_list = []
if not isinstance(target_list, list):
return 0
# 2. Perform operation
if operation == 'count':
return len(target_list)
if operation == 'sum':
if not field_expr:
return 0
total = 0
for item in target_list:
value = 0
if isinstance(item, dict):
value = item.get(field_expr)
else:
value = getattr(item, field_expr, 0)
try:
total += float(value or 0)
except (ValueError, TypeError):
pass
return total
print(f" [ERROR] Unknown $agg operation: {operation}")
return 0
# =============================================
# 3. Helper: Lấy giá trị từ context theo đường dẫn dotted
# =============================================

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.