Production

This commit is contained in:
Shubhankar45
2026-09-22 06:23:46 +00:00
commit 8fdd20b29f
217 changed files with 31212 additions and 0 deletions
+100
View File
@@ -0,0 +1,100 @@
"""The approved Daily Call Report PDF is a copy of the company's printed form."""
from datetime import date, datetime, timezone
from types import SimpleNamespace as NS
from app.pdf.forms import build_dcr_context
from app.pdf.service import _env
def _doctor(name, promote="", sample="", remarks="", outcome="MET", qualification="MBBS"):
return NS(
doctor=NS(name=name, qualification=qualification), product_promote=promote,
product_sample=sample, remarks=remarks, call_outcome=NS(value=outcome),
)
def _context(doctors, chemists=(), approval=None, **dcr_overrides):
dcr = NS(
mr=NS(full_name="Sumit Patel", employee_code="MR001"), headquarters=NS(name="Bhubaneswar"),
report_date=date(2026, 9, 21), stockist_visit="Ganesh Distributors", order_value="45,000",
mr_remarks="", approved_at=datetime(2026, 9, 21, tzinfo=timezone.utc), id="abc",
)
for key, value in dcr_overrides.items():
setattr(dcr, key, value)
return build_dcr_context(dcr, list(doctors), list(chemists), approval)
def _render(ctx) -> str:
return _env.get_template("dcr.html").render(**ctx)
class TestReferenceLayout:
def test_header_and_headings_match_the_printed_form(self):
html = _render(_context([_doctor("Dr Sen")]))
for text in (
"CELTIC LIFE SCIENCE PVT LTD", "DAILY CALL REPORT", "NAME:", "HEADQUARTER:", "Date:", "Month:",
"SR. NO.", "DR. NAME", "QUALIFICATION", "PRODUCT PROMOTE", "PRODUCT SAMPLE", "REMARKS",
"CHEMIST VISIT", "NAME OF THE CHEMIST", "POB", "STOCKIST VISIT :", "ORDER :", "MR Signature",
):
assert text in html, text
def test_ten_doctor_lines_and_five_chemist_lines_like_the_paper(self):
ctx = _context([_doctor("Dr Sen")], [NS(chemist=NS(name="Konark"), pob="100")])
assert len(ctx["grids"]["doctors"]["rows"]) == 10
assert len(ctx["grids"]["chemists"]["rows"]) == 5
assert [r["cells"][0] for r in ctx["grids"]["doctors"]["rows"]] == [str(i) for i in range(1, 11)]
def test_more_than_ten_visits_continue_rather_than_get_dropped(self):
ctx = _context([_doctor(f"Dr {i}") for i in range(13)])
assert len(ctx["grids"]["doctors"]["rows"]) == 13
def test_cells_are_filled_from_the_top_in_column_order(self):
ctx = _context([_doctor("Dr Sen", "Calcium", "Vit D", "Follow up", qualification="MBBS, MD")])
assert ctx["grids"]["doctors"]["rows"][0]["cells"] == ["1", "Dr Sen", "MBBS, MD", "Calcium", "Vit D", "Follow up"]
assert ctx["grids"]["doctors"]["rows"][1]["cells"] == ["2", "", "", "", "", ""]
def test_meta_block_uses_local_date_format_and_month_name(self):
meta = _context([])["meta_rows"]
assert meta[0] == [("NAME:", "Sumit Patel"), ("Date:", "21/09/2026")]
assert meta[1] == [("HEADQUARTER:", "Bhubaneswar"), ("Month:", "September 2026")]
def test_a_visit_that_did_not_happen_is_flagged_in_remarks(self):
ctx = _context([_doctor("Dr Rout", outcome="NOT_AVAILABLE", remarks="Try Monday")])
assert ctx["grids"]["doctors"]["rows"][0]["cells"][5] == "Not available. Try Monday"
def test_chemist_pob_stockist_and_order_are_printed(self):
ctx = _context([], [NS(chemist=NS(name="Konark Medical Stores"), pob="12,500")])
html = _render(ctx)
assert ctx["grids"]["chemists"]["rows"][0]["cells"] == ["1", "Konark Medical Stores", "12,500"]
assert "Ganesh Distributors" in html and "45,000" in html
def test_the_old_report_layout_is_gone(self):
html = _render(_context([_doctor("Dr Sen")]))
assert "Approval Trail" not in html and "Doctor Calls (" not in html
def test_nothing_is_printed_that_is_not_on_the_paper_form(self):
html = _render(_context([_doctor("Dr Sen")], mr_remarks="Good Day"))
assert "Good Day" not in html and "Approved by" not in html and "Report ID" not in html
class TestSignatures:
APPROVAL = {"name": "Shubhankar Patel", "at": "21/09/2026 13:05"}
def test_an_approved_report_carries_both_signatures(self):
html = _render(_context([_doctor("Dr Sen")], approval=self.APPROVAL))
assert "MR Signature" in html and "Sumit Patel (MR001)" in html
assert "APPROVAL SIGNATURE:" in html and "Shubhankar Patel" in html and "21/09/2026 13:05" in html
def test_without_an_approval_there_is_no_approval_signature(self):
html = _render(_context([_doctor("Dr Sen")]))
assert "MR Signature" in html
assert "APPROVAL SIGNATURE" not in html
def test_signature_text_is_escaped(self):
html = _render(_context([_doctor("Dr Sen")], approval={"name": "<b>x</b>", "at": "now"}))
assert "<b>x</b>" not in html
def test_user_text_is_escaped(self):
html = _render(_context([_doctor("<script>alert(1)</script>")]))
assert "<script>" not in html