feat(property): add 23-table property module with partitioned follow_logs and property_photos
This commit is contained in:
194
apps/property/models/listings.py
Normal file
194
apps/property/models/listings.py
Normal file
@@ -0,0 +1,194 @@
|
||||
from django.db import models
|
||||
|
||||
from core.enums import (
|
||||
PropertyCommissionAttachmentCategory,
|
||||
PropertyCommissionOwnerType,
|
||||
PropertyCommissionStatus,
|
||||
PropertyListingHistoryStatus,
|
||||
PropertyListingType,
|
||||
PropertyNumberHolderApprovalStatus,
|
||||
)
|
||||
from core.models.base import TimeStampedModel, UUIDPrimaryKeyModel
|
||||
|
||||
|
||||
class ListingHistory(UUIDPrimaryKeyModel):
|
||||
property = models.ForeignKey(
|
||||
"fonrey_property.Property",
|
||||
on_delete=models.RESTRICT,
|
||||
related_name="listing_histories",
|
||||
)
|
||||
listing_type = models.CharField(max_length=20, choices=PropertyListingType.choices)
|
||||
status = models.CharField(
|
||||
max_length=10,
|
||||
choices=PropertyListingHistoryStatus.choices,
|
||||
default=PropertyListingHistoryStatus.ACTIVE,
|
||||
)
|
||||
|
||||
sale_price = models.DecimalField(max_digits=12, decimal_places=2, null=True, blank=True)
|
||||
rent_price = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True)
|
||||
sale_unit_price = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True)
|
||||
|
||||
ownership_years = models.CharField(max_length=30, blank=True, default="")
|
||||
is_only_house = models.BooleanField(null=True, blank=True)
|
||||
tax_included = models.CharField(max_length=15, blank=True, default="")
|
||||
sale_reason = models.TextField(blank=True, default="")
|
||||
|
||||
seller_agent = models.ForeignKey(
|
||||
"org.Staff", null=True, blank=True, on_delete=models.SET_NULL
|
||||
)
|
||||
seller_agent_snapshot = models.JSONField(null=True, blank=True)
|
||||
|
||||
started_at = models.DateTimeField(auto_now_add=False)
|
||||
ended_at = models.DateTimeField(null=True, blank=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "listing_histories"
|
||||
indexes = [
|
||||
models.Index(fields=["property"], name="idx_lh_property"),
|
||||
models.Index(fields=["property", "status"], name="idx_lh_active"),
|
||||
]
|
||||
|
||||
|
||||
class PriceChange(UUIDPrimaryKeyModel):
|
||||
property = models.ForeignKey(
|
||||
"fonrey_property.Property", on_delete=models.RESTRICT, related_name="price_changes"
|
||||
)
|
||||
old_sale_price = models.DecimalField(max_digits=12, decimal_places=2, null=True, blank=True)
|
||||
new_sale_price = models.DecimalField(max_digits=12, decimal_places=2, null=True, blank=True)
|
||||
old_bottom_price = models.DecimalField(max_digits=12, decimal_places=2, null=True, blank=True)
|
||||
new_bottom_price = models.DecimalField(max_digits=12, decimal_places=2, null=True, blank=True)
|
||||
old_record_price = models.DecimalField(max_digits=12, decimal_places=2, null=True, blank=True)
|
||||
new_record_price = models.DecimalField(max_digits=12, decimal_places=2, null=True, blank=True)
|
||||
old_rent_price = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True)
|
||||
new_rent_price = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True)
|
||||
|
||||
change_reason = models.TextField()
|
||||
changed_at = models.DateTimeField(auto_now_add=True)
|
||||
changed_by = models.ForeignKey("org.Staff", on_delete=models.RESTRICT)
|
||||
|
||||
class Meta:
|
||||
db_table = "price_changes"
|
||||
indexes = [
|
||||
models.Index(fields=["property"], name="idx_pchg_property"),
|
||||
models.Index(fields=["property", "-changed_at"], name="idx_pchg_time"),
|
||||
]
|
||||
|
||||
|
||||
class Commission(TimeStampedModel):
|
||||
property = models.ForeignKey(
|
||||
"fonrey_property.Property", on_delete=models.CASCADE, related_name="commissions"
|
||||
)
|
||||
commission_type = models.CharField(max_length=50)
|
||||
period_start = models.DateField()
|
||||
period_end = models.DateField(null=True, blank=True)
|
||||
is_open_ended = models.BooleanField(default=False)
|
||||
|
||||
agent = models.ForeignKey(
|
||||
"org.Staff",
|
||||
null=True,
|
||||
blank=True,
|
||||
on_delete=models.SET_NULL,
|
||||
related_name="commissions_as_agent",
|
||||
)
|
||||
agent_snapshot = models.JSONField(null=True, blank=True)
|
||||
|
||||
signing_method = models.CharField(max_length=50, blank=True, default="")
|
||||
|
||||
owner_type = models.CharField(
|
||||
max_length=20,
|
||||
choices=PropertyCommissionOwnerType.choices,
|
||||
default=PropertyCommissionOwnerType.OWNER,
|
||||
)
|
||||
property_owner_contact = models.ForeignKey(
|
||||
"fonrey_property.PropertyContact",
|
||||
null=True,
|
||||
blank=True,
|
||||
on_delete=models.SET_NULL,
|
||||
related_name="commissions",
|
||||
)
|
||||
owner_name = models.CharField(max_length=50, blank=True, default="")
|
||||
owner_id_type = models.CharField(max_length=20, blank=True, default="")
|
||||
owner_id_number = models.CharField(max_length=50, blank=True, default="")
|
||||
owner_id_number_enc = models.BinaryField(null=True, blank=True)
|
||||
|
||||
remarks = models.TextField(blank=True, default="")
|
||||
|
||||
status = models.CharField(
|
||||
max_length=20,
|
||||
choices=PropertyCommissionStatus.choices,
|
||||
default=PropertyCommissionStatus.ACTIVE,
|
||||
)
|
||||
|
||||
created_by = models.ForeignKey(
|
||||
"org.Staff",
|
||||
null=True,
|
||||
blank=True,
|
||||
on_delete=models.SET_NULL,
|
||||
related_name="created_commissions",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
db_table = "commissions"
|
||||
indexes = [
|
||||
models.Index(fields=["property"], name="idx_commissions_property"),
|
||||
models.Index(fields=["property", "status"], name="idx_commissions_active"),
|
||||
]
|
||||
|
||||
|
||||
class CommissionAttachment(UUIDPrimaryKeyModel):
|
||||
commission = models.ForeignKey(
|
||||
Commission, on_delete=models.CASCADE, related_name="attachments"
|
||||
)
|
||||
category = models.CharField(
|
||||
max_length=20, choices=PropertyCommissionAttachmentCategory.choices
|
||||
)
|
||||
file_key = models.TextField()
|
||||
file_name = models.CharField(max_length=255)
|
||||
file_size = models.IntegerField(null=True, blank=True)
|
||||
sort_order = models.SmallIntegerField(default=0)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "commission_attachments"
|
||||
indexes = [models.Index(fields=["commission"], name="idx_ca_commission")]
|
||||
|
||||
|
||||
class NumberHolderApproval(UUIDPrimaryKeyModel):
|
||||
property = models.ForeignKey(
|
||||
"fonrey_property.Property",
|
||||
on_delete=models.CASCADE,
|
||||
related_name="number_holder_approvals",
|
||||
)
|
||||
contact = models.ForeignKey(
|
||||
"fonrey_property.PropertyContact",
|
||||
on_delete=models.CASCADE,
|
||||
related_name="number_holder_approvals",
|
||||
)
|
||||
|
||||
applicant = models.ForeignKey(
|
||||
"org.Staff", on_delete=models.RESTRICT, related_name="nh_applications"
|
||||
)
|
||||
approver = models.ForeignKey(
|
||||
"org.Staff",
|
||||
null=True,
|
||||
blank=True,
|
||||
on_delete=models.SET_NULL,
|
||||
related_name="nh_approvals",
|
||||
)
|
||||
|
||||
status = models.CharField(
|
||||
max_length=20,
|
||||
choices=PropertyNumberHolderApprovalStatus.choices,
|
||||
default=PropertyNumberHolderApprovalStatus.PENDING,
|
||||
)
|
||||
remarks = models.TextField(blank=True, default="")
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
decided_at = models.DateTimeField(null=True, blank=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "number_holder_approvals"
|
||||
indexes = [
|
||||
models.Index(fields=["status"], name="idx_nha_status"),
|
||||
models.Index(fields=["property"], name="idx_nha_property"),
|
||||
]
|
||||
Reference in New Issue
Block a user