diff --git a/api/__pycache__/settings.cpython-313.pyc b/api/__pycache__/settings.cpython-313.pyc index e4ac958e..8ec4b12e 100644 Binary files a/api/__pycache__/settings.cpython-313.pyc and b/api/__pycache__/settings.cpython-313.pyc differ diff --git a/api/__pycache__/urls.cpython-313.pyc b/api/__pycache__/urls.cpython-313.pyc index c6bad9d7..bcdc8247 100644 Binary files a/api/__pycache__/urls.cpython-313.pyc and b/api/__pycache__/urls.cpython-313.pyc differ diff --git a/app/__pycache__/document_generator.cpython-313.pyc b/app/__pycache__/document_generator.cpython-313.pyc index 556ad7a9..0d8051ca 100644 Binary files a/app/__pycache__/document_generator.cpython-313.pyc and b/app/__pycache__/document_generator.cpython-313.pyc differ diff --git a/app/__pycache__/models.cpython-313.pyc b/app/__pycache__/models.cpython-313.pyc index 539332c8..62667e9a 100644 Binary files a/app/__pycache__/models.cpython-313.pyc and b/app/__pycache__/models.cpython-313.pyc differ diff --git a/app/__pycache__/payment.cpython-313.pyc b/app/__pycache__/payment.cpython-313.pyc index 1be4eff4..563ece8a 100644 Binary files a/app/__pycache__/payment.cpython-313.pyc and b/app/__pycache__/payment.cpython-313.pyc differ diff --git a/app/document_generator.py b/app/document_generator.py index 505ac2f3..d17f6886 100644 --- a/app/document_generator.py +++ b/app/document_generator.py @@ -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): diff --git a/app/migrations/0344_legal_rep_relation_organization_bank_account_and_more.py b/app/migrations/0344_legal_rep_relation_organization_bank_account_and_more.py new file mode 100644 index 00000000..e3b84e24 --- /dev/null +++ b/app/migrations/0344_legal_rep_relation_organization_bank_account_and_more.py @@ -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), + ), + ] diff --git a/app/migrations/0345_alter_co_ownership_transaction.py b/app/migrations/0345_alter_co_ownership_transaction.py new file mode 100644 index 00000000..891270f8 --- /dev/null +++ b/app/migrations/0345_alter_co_ownership_transaction.py @@ -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'), + ), + ] diff --git a/app/models.py b/app/models.py index d5dac4cc..9b9eff95 100644 --- a/app/models.py +++ b/app/models.py @@ -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) diff --git a/static/contract/.~lock.1. Phiếu xác lập thỏa thuận ưu tiên tổ chức.docx# b/static/contract/.~lock.1. Phiếu xác lập thỏa thuận ưu tiên tổ chức.docx# new file mode 100644 index 00000000..58a88818 --- /dev/null +++ b/static/contract/.~lock.1. Phiếu xác lập thỏa thuận ưu tiên tổ chức.docx# @@ -0,0 +1 @@ +,kumduy,duy-pc,04.01.2026 23:48,file:///home/kumduy/.config/libreoffice/4; \ No newline at end of file diff --git a/static/contract/1. Phiếu xác lập thỏa thuận ưu tiên tổ chức.docx b/static/contract/1. Phiếu xác lập thỏa thuận ưu tiên tổ chức.docx new file mode 100644 index 00000000..4cb82e53 Binary files /dev/null and b/static/contract/1. Phiếu xác lập thỏa thuận ưu tiên tổ chức.docx differ