feat(입출고): 대성화학·인천공장 발주 메일 표를 간단하게
공장 이름에 대성화학·인천공장이 들어가면 품목 표를 번호·제품 코드· 제품명·수량·박스당 수량·박스 수·비고로 만들고, 요약 표와 글 본문에서도 금액·무게·PP·은을 뺀다. 박스 값은 메일을 만들 때의 상품 정보로 계산한다. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import base64
|
||||
import email
|
||||
import json
|
||||
import re
|
||||
import unittest
|
||||
from datetime import date
|
||||
from email import policy
|
||||
@@ -118,6 +119,50 @@ class MailContentTests(unittest.TestCase):
|
||||
self.assertTrue(m2["text"].startswith("안녕하세요."))
|
||||
self.assertNotIn("요청 사항", m2["text"])
|
||||
|
||||
def test_order_mail_simple_factories(self):
|
||||
"""대성화학·인천공장 — 표는 번호·제품 코드·제품명·수량·박스당 수량·박스 수·비고만, 단가·금액·무게·은은 어디에도 없음. 다른 공장은 그대로."""
|
||||
from decimal import Decimal as D
|
||||
|
||||
priced = [{"item_code": "MT-0320", "item_name": "통", "qty": 100, "memo": "흰색", "unit_price": D("7777"),
|
||||
"weight_g": D("50"), "silver_pct": D("3")}]
|
||||
for name in ("대성화학", "(주)대성화학", "인천공장", "인천 공장"):
|
||||
with self.subTest(name=name):
|
||||
m = s.order_mail(_order(factory_name=name, lines=priced), sender_name="K", sender_email="k@x.com")
|
||||
head = m["html"][m["html"].index("<thead>"):m["html"].index("</thead>")]
|
||||
self.assertEqual(re.findall(r"<th[^>]*>([^<]*)</th>", head), ["번호", "제품 코드", "제품명", "수량", "박스당 수량", "박스 수", "비고"])
|
||||
row = m["html"][m["html"].index("<tbody>"):m["html"].index("</tbody>")]
|
||||
self.assertEqual(row.count("<td"), 7)
|
||||
self.assertEqual(m["html"][m["html"].index("<tfoot>"):].count("<th"), 5) # 합계(3칸 합침)·수량·박스당 빈칸·박스·비고
|
||||
for part in (m["html"], m["text"]):
|
||||
self.assertNotRegex(part, "단가|금액|무게|PP|은\\(|7,777|777,700")
|
||||
self.assertIn("1. MT-0320 통 — 100개 (흰색)", m["text"])
|
||||
self.assertIn("발주번호", m["html"])
|
||||
other = s.order_mail(_order(lines=[dict(priced[0], body_per_box=30)]), sender_name="K", sender_email="k@x.com")
|
||||
for part in ("단가(원)", "금액(원)", "전체 무게(kg)", "PP 사용량(kg)", "은(Ag) 함유량", "7,777"):
|
||||
self.assertIn(part, other["html"])
|
||||
self.assertIn(">No</th>", other["html"])
|
||||
self.assertIn("단가 7,777", other["text"])
|
||||
self.assertNotIn("박스", other["html"].replace("박스당 24개", "")) # 다른 공장엔 박스 칸 없음(요청 사항 글 제외)
|
||||
|
||||
def test_order_mail_simple_boxes(self):
|
||||
"""박스당 수량·박스 수(올림) — 뚜껑 있으면 통·뚜껑 따로, 입수 없으면 '-', 합계는 있는 줄만."""
|
||||
self.assertEqual(s.line_boxes({"qty": 100, "body_per_box": 30}), {"per": "30개", "count": "4박스", "total": 4})
|
||||
self.assertEqual(s.line_boxes({"qty": 90, "body_per_box": 30})["total"], 3)
|
||||
self.assertEqual(s.line_boxes({"qty": 1000, "body_per_box": 120, "lid_per_box": 500}),
|
||||
{"per": "통 120개 · 뚜껑 500개", "count": "통 9 · 뚜껑 2박스", "total": 11})
|
||||
self.assertEqual(s.line_boxes({"qty": 5}), {"per": "-", "count": "-", "total": None})
|
||||
lines = [{"item_code": "A", "item_name": "봉투", "qty": 2600, "memo": "", "body_per_box": 100, "lid_per_box": None},
|
||||
{"item_code": "B", "item_name": "통", "qty": 1000, "memo": "흰색", "body_per_box": 120, "lid_per_box": 500},
|
||||
{"item_code": "C", "item_name": "없음", "qty": 5, "memo": ""}]
|
||||
m = s.order_mail(_order(factory_name="대성화학", memo="", lines=lines), sender_name="K", sender_email="k@x.com")
|
||||
self.assertIn(">100개</td>", m["html"])
|
||||
self.assertIn(">26박스</td>", m["html"])
|
||||
self.assertIn("통 9 · 뚜껑 2박스", m["html"])
|
||||
self.assertIn("37박스 (미설정 1종 제외)", m["html"])
|
||||
self.assertIn("1. A 봉투 — 2,600개 · 박스당 100개 · 26박스", m["text"])
|
||||
self.assertIn("2. B 통 — 1,000개 · 박스당 통 120개 · 뚜껑 500개 · 통 9 · 뚜껑 2박스 (흰색)", m["text"])
|
||||
self.assertIn("3. C 없음 — 5개", m["text"])
|
||||
|
||||
def test_build_message_utf8_and_alternative(self):
|
||||
raw = gmail.build_message(sender_name="킹", sender_email="king@dbxcorp.co.kr", to=["a@x.com", "b@y.com"], cc=["c@z.com"],
|
||||
subject="[발주] 테스트 · 한글", text="본문", html="<p>본문</p>")
|
||||
|
||||
@@ -461,6 +461,47 @@ def body(c):
|
||||
st.exclude_product(code, by=admin["email"])
|
||||
print("OK")
|
||||
run(body)
|
||||
''', {"INOUT_TEST_DB_URL": DSN})
|
||||
self.assertEqual(res.returncode, 0, res.stdout + res.stderr)
|
||||
self.assertIn("OK", res.stdout)
|
||||
|
||||
@unittest.skipUnless(DB_ENABLED, "INOUT_TEST_DB_URL(localhost) not set")
|
||||
def test_simple_factory_mail_shows_boxes(self):
|
||||
"""대성화학 메일 미리보기 — 상품 정보의 박스 입수로 박스 칸이 차고 단가는 없음. 다른 공장은 예전 표."""
|
||||
res = _run('''
|
||||
import re, uuid
|
||||
from app.modules.inout.db import InoutDBStore
|
||||
st = InoutDBStore(__import__("os").environ["INOUT_TEST_DB_URL"])
|
||||
main.app.state.inout_store = st
|
||||
main.app.state.inout_items = Items()
|
||||
tag = uuid.uuid4().hex[:6].upper()
|
||||
admin = U("admin-%s@t.local" % tag.lower(), role="admin")
|
||||
users.append(admin)
|
||||
CODE = "ZS-%s-A" % tag
|
||||
|
||||
def order_for(c, factory):
|
||||
c.post("/inout/settings/factories", data={"name": factory, "is_active": "1"}, headers={"X-Inout-Options": "1"})
|
||||
fid = next(f["id"] for f in st.list_factories() if f["name"] == factory)
|
||||
r = c.post("/inout/orders/new", data={"factory_id": fid, "order_date": "2026-11-04", "item_code": [CODE],
|
||||
"item_name": [""], "qty": ["100"], "line_memo": [""]}, follow_redirects=False)
|
||||
return int(re.search(r"/inout/orders/(\\d+)", r.headers["location"]).group(1))
|
||||
|
||||
def body(c):
|
||||
who["u"] = admin
|
||||
st.import_products([{"code": CODE, "name": "통 " + tag}], by=admin["email"])
|
||||
try:
|
||||
r = c.post("/inout/settings/products/save", headers={"X-Inout-Options": "1"}, json={"rows": [
|
||||
{"code": CODE, "unit_price": "7777", "weight_g": "", "silver_pct": "", "body_per_box": "30", "lid_per_box": ""}]})
|
||||
assert r.json()["ok"], r.text
|
||||
html = c.get("/inout/orders/%d/mail" % order_for(c, "대성화학-" + tag)).json()["html"]
|
||||
assert "박스당 수량" in html and ">30개</td>" in html and ">4박스</td>" in html, html
|
||||
assert "단가" not in html and "7,777" not in html
|
||||
html = c.get("/inout/orders/%d/mail" % order_for(c, "보통공장-" + tag)).json()["html"]
|
||||
assert "박스당 수량" not in html and "7,777" in html
|
||||
finally:
|
||||
st.exclude_product(CODE, by=admin["email"])
|
||||
print("OK")
|
||||
run(body)
|
||||
''', {"INOUT_TEST_DB_URL": DSN})
|
||||
self.assertEqual(res.returncode, 0, res.stdout + res.stderr)
|
||||
self.assertIn("OK", res.stdout)
|
||||
|
||||
Reference in New Issue
Block a user