Server backup 2026-11-07 of uncommitted work in projects/pharma-web-celtic

Snapshot of the working tree on srv1071960 (branch main), taken during
server cleanup. .env files, node_modules, builds, logs and media were excluded.
This commit is contained in:
Shubhankar45
2026-11-07 05:43:12 +00:00
parent b001e2d03c
commit 0d30c58bf0
98 changed files with 1878 additions and 573 deletions
+37 -7
View File
@@ -5,8 +5,8 @@ doctors and chemists they intend to visit, and an end-of-day ACTUAL report of th
that happened. Both share this table and its call rows; the ACTUAL report points at its
plan, and records why any planned visit was missed in ``missed_visit``.
An Area Manager files a SELF report of their own visits in the same table; ``mr_user_id``
is then the Area Manager (the report's owner), and submitting it makes it final."""
An Area Business Manager files a SELF report of their own visits in the same table; ``mr_user_id``
is then the Area Business Manager (the report's owner), and submitting it makes it final."""
import uuid
from datetime import date, datetime, time
@@ -73,7 +73,7 @@ class DailyCallReport(Base, UUIDMixin, TimestampMixin):
nullable=False,
)
#: SNAPSHOT of the reviewing AM / approving GM, so an HQ handover never rewrites
#: SNAPSHOT of the reviewing ABM / overseeing AGM, so an HQ handover never rewrites
#: history (report §5.5).
current_am_user_id: Mapped[uuid.UUID | None] = mapped_column(
PGUUID(as_uuid=True), ForeignKey("user.id", ondelete="RESTRICT")
@@ -104,6 +104,9 @@ class DailyCallReport(Base, UUIDMixin, TimestampMixin):
chemist_calls: Mapped[list["ChemistCall"]] = relationship(
back_populates="dcr", cascade="all, delete-orphan", lazy="selectin"
)
stockist_calls: Mapped[list["StockistCall"]] = relationship(
back_populates="dcr", cascade="all, delete-orphan", lazy="selectin"
)
missed_visits: Mapped[list["MissedVisit"]] = relationship(
back_populates="dcr", cascade="all, delete-orphan", lazy="selectin"
)
@@ -184,18 +187,42 @@ class ChemistCall(Base, UUIDMixin, TimestampMixin):
chemist: Mapped["Chemist"] = relationship(lazy="selectin") # noqa: F821
class MissedVisit(Base, UUIDMixin, TimestampMixin):
"""Why a doctor or chemist on the approved plan was not visited that day.
class StockistCall(Base, UUIDMixin, TimestampMixin):
__tablename__ = "stockist_call"
__table_args__ = (
UniqueConstraint("dcr_id", "stockist_id", name="uq_call_dcr_stockist"),
)
Belongs to the end-of-day report; exactly one of doctor/chemist is set.
dcr_id: Mapped[uuid.UUID] = mapped_column(
PGUUID(as_uuid=True),
ForeignKey("daily_call_report.id", ondelete="CASCADE"),
nullable=False,
)
stockist_id: Mapped[uuid.UUID] = mapped_column(
PGUUID(as_uuid=True), ForeignKey("stockist.id", ondelete="RESTRICT"), nullable=False
)
visit_time: Mapped[time] = mapped_column(Time, nullable=False)
#: Order booked with the stockist on this visit.
pob: Mapped[str | None] = mapped_column(String(100))
remarks: Mapped[str | None] = mapped_column(Text)
dcr: Mapped["DailyCallReport"] = relationship(back_populates="stockist_calls")
stockist: Mapped["Stockist"] = relationship(lazy="selectin") # noqa: F821
class MissedVisit(Base, UUIDMixin, TimestampMixin):
"""Why a doctor, chemist or stockist on the approved plan was not visited that day.
Belongs to the end-of-day report; exactly one of doctor/chemist/stockist is set.
"""
__tablename__ = "missed_visit"
__table_args__ = (
UniqueConstraint("dcr_id", "doctor_id", name="uq_missed_dcr_doctor"),
UniqueConstraint("dcr_id", "chemist_id", name="uq_missed_dcr_chemist"),
UniqueConstraint("dcr_id", "stockist_id", name="uq_missed_dcr_stockist"),
CheckConstraint(
"(doctor_id IS NULL) <> (chemist_id IS NULL)", name="ck_missed_one_target"
"num_nonnulls(doctor_id, chemist_id, stockist_id) = 1", name="ck_missed_one_target"
),
)
@@ -210,6 +237,9 @@ class MissedVisit(Base, UUIDMixin, TimestampMixin):
chemist_id: Mapped[uuid.UUID | None] = mapped_column(
PGUUID(as_uuid=True), ForeignKey("chemist.id", ondelete="RESTRICT")
)
stockist_id: Mapped[uuid.UUID | None] = mapped_column(
PGUUID(as_uuid=True), ForeignKey("stockist.id", ondelete="RESTRICT")
)
reason: Mapped[str] = mapped_column(Text, nullable=False)
dcr: Mapped["DailyCallReport"] = relationship(back_populates="missed_visits")