This commit is contained in:
anhduy-tech
2026-01-05 00:34:49 +07:00
parent 15bb6720b6
commit e0403055e3
11 changed files with 76 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
import os
import subprocess
from datetime import datetime
from django.db import models
import numpy as np
from docx import Document
from docx.enum.text import WD_ALIGN_PARAGRAPH
@@ -206,13 +206,23 @@ class DocumentGenerator:
raise ValueError(f"Could not resolve '{lookup_from}'. It is not a valid API parameter or a reference to another data source.")
def _get_value_from_object(self, obj, field_path):
if obj is None:
if not obj:
return None
parts = field_path.split('.')
value = obj
for part in field_path.replace("__", ".").split("."):
for part in parts:
if value is None:
return None
break
# Lấy thuộc tính từ object
value = getattr(value, part, None)
# KIỂM TRA NẾU LÀ QUAN HỆ NGƯỢC (ForeignKey ngược hoặc ManyToMany)
# Trong Django, các quan hệ này trả về một Manager (có method 'all')
if hasattr(value, 'all') and not isinstance(value, models.Model):
value = value.first() # Tự động lấy bản ghi đầu tiên
return value
def fetch_data(self):

View File

@@ -0,0 +1,35 @@
# Generated by Django 5.1.7 on 2026-01-04 16:15
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0343_import_setting_call_api_delete_payment'),
]
operations = [
migrations.AddField(
model_name='legal_rep',
name='relation',
field=models.ForeignKey(default=10, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='app.relation'),
preserve_default=False,
),
migrations.AddField(
model_name='organization',
name='bank_account',
field=models.CharField(max_length=50, null=True),
),
migrations.AddField(
model_name='organization',
name='bank_name',
field=models.CharField(max_length=100, null=True),
),
migrations.AddField(
model_name='organization',
name='tax_code',
field=models.CharField(max_length=20, null=True),
),
]

View File

@@ -0,0 +1,19 @@
# Generated by Django 5.1.7 on 2026-01-04 17:34
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0344_legal_rep_relation_organization_bank_account_and_more'),
]
operations = [
migrations.AlterField(
model_name='co_ownership',
name='transaction',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='co_op', to='app.transaction'),
),
]

View File

@@ -1321,8 +1321,11 @@ class Individual(models.Model):
class Organization(models.Model):
customer = models.ForeignKey(Customer, null=False, related_name='orgncust', on_delete=models.PROTECT)
shortname = models.CharField(max_length=50, null=False)
established_date = models.DateField()
website = models.CharField(max_length=200, null=True)
established_date = models.DateField()
tax_code = models.CharField(max_length=20, null=True)
website = models.CharField(max_length=200, null=True)
bank_account = models.CharField(max_length=50, null=True)
bank_name = models.CharField(max_length=100, null=True)
type = models.ForeignKey(Company_Type, null=True, related_name='+', on_delete=models.PROTECT)
create_time = models.DateTimeField(null=True, auto_now_add=True)
update_time = models.DateTimeField(null=True, auto_now=True)
@@ -1334,6 +1337,7 @@ class Organization(models.Model):
class Legal_Rep(models.Model):
organization = models.ForeignKey(Organization, null=False, related_name='orgrep', on_delete=models.PROTECT)
people = models.ForeignKey(People, null=False, related_name='+', on_delete=models.PROTECT)
relation = models.ForeignKey(Relation, null=False, related_name='+', on_delete=models.PROTECT)
create_time = models.DateTimeField(null=True, auto_now_add=True)
class Meta:
@@ -1952,7 +1956,7 @@ class Transaction_Discount(models.Model):
class Co_Ownership(models.Model):
code = models.CharField(max_length=30, null=False, unique=True)
transaction = models.ForeignKey(Transaction, null=False, related_name='+', on_delete=models.PROTECT)
transaction = models.ForeignKey(Transaction, null=False, related_name='co_op', on_delete=models.PROTECT)
people = models.ForeignKey(People, null=False, related_name='+', on_delete=models.PROTECT)
create_time = models.DateTimeField(null=True, auto_now_add=True)
update_time = models.DateTimeField(null=True, auto_now=True)