Files
petriandClaude Opus 5.5 a81c073d6a Vaihe 1/2: asiakkaat, yhteyshenkilöt ja laskutusyksiköt
- customers-moduuli Clean Architecture -kerroksin: asiakas (yritys/kuluttaja),
  Y-tunnuksen tarkiste ja yksilöllisyys, yhteyshenkilöt, laskutusyksiköt
  (verkkolaskuosoite vaatii välittäjätunnuksen)
- henkilötunnus salattuna (Fernet) ja HMAC-tiiviste päällekkäisyyksiin;
  pääkäyttäjä ja johto näkevät ja poistavat, muut näkevät peitettynä
- sisäinen asiakas data-migraatiolla, ei poistettavissa
- yleinen poistonesto käänteisten relaatioiden perusteella (tulevat
  PROTECT-viiteavaimet estävät poiston automaattisesti)
- asiakkaan sivu: lisäys ja muokkaus dialogissa HTMX:llä, fokuksen hallinta
  ja ruudunlukijailmoitukset; HTMX näyttää nyt 422-validointivirheet
- testit: domain, application, integraatio ja selaintestit (axe);
  yhteiset fixturet apps/conftest.py:hin, FakeUnitOfWork shared-moduuliin
- import-linter: moduulien riippumattomuussäännöt
- dokumentit päivitetty

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-29 13:47:09 +02:00

60 lines
2.1 KiB
Python

from django.db import models
from apps.customers.domain.enums import CustomerType
from apps.shared.infrastructure.models import TimestampedModel
class CustomerModel(TimestampedModel):
name = models.CharField(max_length=200)
type = models.CharField(max_length=20, default=CustomerType.COMPANY.value)
business_id = models.CharField(max_length=9, null=True, blank=True, unique=True)
# Fernet ciphertext of the henkilötunnus; never stored in plain text.
# NULL (not "") means no code, matching the nullable unique hash below.
personal_identity_code = models.TextField(null=True, blank=True) # noqa: DJ001
# HMAC-SHA256 fingerprint for duplicate checks (the code itself is not searchable).
personal_identity_code_hash = models.CharField(
max_length=64, null=True, blank=True, unique=True
)
is_internal = models.BooleanField(default=False)
class Meta:
db_table = "customers"
ordering = ["name"]
def __str__(self) -> str:
return self.name
class ContactModel(TimestampedModel):
customer = models.ForeignKey(CustomerModel, on_delete=models.PROTECT, related_name="contacts")
name = models.CharField(max_length=150)
title = models.CharField(max_length=150, blank=True)
phone = models.CharField(max_length=50, blank=True)
email = models.EmailField(max_length=254, blank=True)
note = models.TextField(blank=True)
class Meta:
db_table = "customer_contacts"
ordering = ["name", "id"]
def __str__(self) -> str:
return self.name
class BillingUnitModel(TimestampedModel):
customer = models.ForeignKey(
CustomerModel, on_delete=models.PROTECT, related_name="billing_units"
)
name = models.CharField(max_length=200)
billing_address = models.TextField(blank=True)
e_invoice_address = models.CharField(max_length=35, blank=True)
e_invoice_operator = models.CharField(max_length=35, blank=True)
reference = models.CharField(max_length=100, blank=True)
class Meta:
db_table = "billing_units"
ordering = ["name", "id"]
def __str__(self) -> str:
return self.name