feat(inout): 발주 메일을 보내면 입고 담당에게 발주 알림 메일 자동 발송
- 같은 Gmail·같은 제목, 내용은 발주번호·발주일·제품 코드·제품명·수량 - 알림 실패·입고 담당 없음은 공장 메일을 막지 않고 결과에 안내, 미리보기에 받을 사람 표시 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
- 새 발주서 저장 → 미리보기 팝업(받는 사람 = 공장 이메일, 요약 표 본문) → 사람이 [메일 발송]을 눌러야 보냄.
|
||||
- **발주 담당 본인 Gmail**(Gmail API `gmail.send`, 사람마다 [Gmail 연결] 1회 — 고른 구글 계정 = ERP 계정 확인). 갱신 토큰은 `APP_ENCRYPTION_KEY` AES-GCM 암호문(`gmail.py`).
|
||||
- 보낸 기록·재발송 확인.
|
||||
- **입고 담당 발주 알림 자동 발송**(2026-10-19): 발주 메일이 나가면 같은 Gmail 로 옵션 → 담당자의 입고 담당들에게 따로 보냄 — 제목은 발주 메일과 같고 내용은 발주번호·발주일·제품 코드·제품명·수량만(`store.order_notice_mail`, `router._send_order_notice`). 실패해도 공장 메일은 그대로(안내만), 미리보기 창에 받을 사람 안내.
|
||||
- **참조 기본값 `king@dbxcorp.co.kr`**(2026-10-19) — 미리보기 참조 칸에 미리 들어감, 옵션 → 공장 탭 "발주 메일 참조"에서 고침(`inout_settings` `order_mail_cc`, 행이 없으면 기본값 — 저장만 005 필요).
|
||||
|
||||
## 입고 요청 메일 (005, 2026-10-19)
|
||||
|
||||
@@ -648,6 +648,7 @@ def mail_preview(request: Request, order_id: int) -> JSONResponse:
|
||||
"callback_url": _callback_url(request), # 구글 클라우드 승인된 리디렉션 URI 에 등록해야 하는 주소(안내용)
|
||||
"from": user.get("email", ""), "to": order.get("factory_email") or "", "factory": order["factory_name"],
|
||||
"cc": st.get_settings()[store.SETTING_ORDER_MAIL_CC], # 참조 기본(옵션 → 공장, 처음엔 king@dbxcorp.co.kr)
|
||||
"notice_to": _receive_emails(st), # 발송하면 이 입고 담당들에게 발주 알림이 따로 감
|
||||
"subject": mail["subject"], "html": mail["html"],
|
||||
"sent": [{"at": store.fmt_datetime(m["sent_at"]), "by": m["sent_by"], "to": m["to_addrs"]} for m in order["mails"]],
|
||||
})
|
||||
@@ -686,7 +687,34 @@ def mail_send(request: Request, order_id: int, payload: dict[str, Any] = Body(..
|
||||
return JSONResponse({"ok": False, "message": str(exc)}, status_code=502)
|
||||
st.add_order_mail(order_id, sent_by=email, to=to, cc=cc, subject=mail["subject"], gmail_id=gid)
|
||||
st.mark_gmail(email)
|
||||
return JSONResponse({"ok": True, "message": f"메일을 보냈습니다 → {', '.join(to)}"})
|
||||
note = _send_order_notice(st, user, order, refresh, subject=mail["subject"])
|
||||
return JSONResponse({"ok": True, "message": f"메일을 보냈습니다 → {', '.join(to)}" + (f" · {note}" if note else ""),
|
||||
"notice": note})
|
||||
|
||||
|
||||
def _receive_emails(st: Any) -> list[str]:
|
||||
"""발주 알림 받는 사람 = 옵션 → 담당자의 입고 담당(지정된 사람만, ERP 관리자는 자동으로 넣지 않음)."""
|
||||
return list(st.list_roles().get(store.ROLE_RECEIVE) or [])
|
||||
|
||||
|
||||
def _send_order_notice(st: Any, user: dict[str, Any], order: dict[str, Any], refresh: str, *, subject: str) -> str:
|
||||
"""발주 메일을 보낸 뒤 입고 담당들에게 따로 자동 발송(2026-10-19) — 같은 Gmail·같은 제목, 내용은 발주번호·발주일·품목(코드·이름·수량).
|
||||
공장 메일은 이미 나갔으므로 여기 실패는 막지 않고 안내 문구만 돌려준다."""
|
||||
from . import gmail # noqa: WPS433
|
||||
|
||||
to = _receive_emails(st)
|
||||
if not to:
|
||||
return "입고 담당이 옵션에 없어 발주 알림 메일은 보내지 않았습니다"
|
||||
email = user.get("email", "")
|
||||
m = store.order_notice_mail(order, subject=subject, sender_name=str(user.get("name") or ""), sender_email=email)
|
||||
try:
|
||||
raw = gmail.build_message(sender_name=str(user.get("name") or ""), sender_email=email, to=to, cc=[],
|
||||
subject=m["subject"], text=m["text"], html=m["html"])
|
||||
gmail.send(refresh, raw)
|
||||
except (gmail.GmailError, gmail.GmailNotConnected) as exc:
|
||||
_log.warning("inout order notice mail failed: %s (%s)", order.get("order_no"), exc)
|
||||
return f"입고 담당 알림 메일은 보내지 못했습니다({exc})"
|
||||
return f"입고 담당 {len(to)}명에게 발주 알림 메일도 보냈습니다"
|
||||
|
||||
|
||||
# ────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -646,3 +646,38 @@ def sabangnet_xlsx(rows: list[list[Any]]) -> bytes:
|
||||
|
||||
def sabangnet_filename(order: dict[str, Any], receipt: dict[str, Any]) -> str:
|
||||
return f"사방넷_입고_{receipt['receipt_date']:%Y%m%d}_{order['order_no']}.xlsx"
|
||||
|
||||
|
||||
# ════════════════════════════════════════════════════════════
|
||||
# 발주 알림 메일(2026-10-19) — 발주 담당이 발주 메일을 보낼 때 입고 담당(옵션 → 담당자)에게 같은 Gmail 로 따로 자동 발송.
|
||||
# 내용 = 발주번호·발주일·제품 코드·제품명·수량만(단가·무게 등은 넣지 않음), 제목 = 발주 메일과 같음.
|
||||
# ════════════════════════════════════════════════════════════
|
||||
def order_notice_mail(order: dict[str, Any], *, subject: str, sender_name: str, sender_email: str) -> dict[str, str]:
|
||||
e = _html.escape
|
||||
lines = order["lines"]
|
||||
total = sum(int(x["qty"]) for x in lines)
|
||||
who = sender_name or sender_email
|
||||
when = fmt_date(order["order_date"])
|
||||
text = ["입고 담당자님, 안녕하세요.", "", "아래와 같이 공장에 발주했습니다. 입고 준비에 참고해 주세요.", "",
|
||||
f"- 발주번호: {order['order_no']}", f"- 발주일: {when}", "", "[발주 품목] 제품 코드 · 제품명 · 수량"]
|
||||
text += [f"- {x['item_code']} · {x['item_name']} · {int(x['qty']):,}개" for x in lines]
|
||||
text += [f"합계 {total:,}개", "", f"발주 담당: {who} ({sender_email})"]
|
||||
td = "padding:4px 10px;border:1px solid #d9dce1;font-size:14px;line-height:20px;"
|
||||
th = f"{td}background:#f6f7f9;font-weight:700;white-space:nowrap;"
|
||||
r = "text-align:right;white-space:nowrap;"
|
||||
facts = (f'<tr><th style="{th}text-align:left">발주번호</th><td style="{td}">{e(order["order_no"])}</td>'
|
||||
f'<th style="{th}text-align:left">발주일</th><td style="{td}">{e(when)}</td></tr>')
|
||||
rows = "".join(f'<tr><td style="{td}font-family:Consolas,monospace">{e(x["item_code"])}</td><td style="{td}">{e(x["item_name"])}</td>'
|
||||
f'<td style="{td}{r}">{int(x["qty"]):,}</td></tr>' for x in lines)
|
||||
html = (
|
||||
'<div style="font-family:\'Malgun Gothic\',\'Apple SD Gothic Neo\',sans-serif;font-size:14px;color:#1d1d1f;line-height:1.6">'
|
||||
"<p>입고 담당자님, 안녕하세요.<br>아래와 같이 공장에 발주했습니다. 입고 준비에 참고해 주세요.</p>"
|
||||
f'<table cellpadding="0" cellspacing="0" style="border-collapse:collapse;margin:8px 0 0">{facts}</table>'
|
||||
'<div style="height:18px;line-height:18px;font-size:1px"> </div>'
|
||||
'<table cellpadding="0" cellspacing="0" style="border-collapse:collapse;min-width:420px">'
|
||||
f'<thead><tr><th style="{th}">제품 코드</th><th style="{th}">제품명</th><th style="{th}">수량</th></tr></thead>'
|
||||
f'<tbody>{rows}</tbody>'
|
||||
f'<tfoot><tr><th colspan="2" style="{th}text-align:right">합계</th><th style="{th}{r}">{total:,}</th></tr></tfoot></table>'
|
||||
f'<p style="color:#555;margin-top:18px">발주 담당: {e(who)} (<a href="mailto:{e(sender_email)}">{e(sender_email)}</a>)</p></div>'
|
||||
)
|
||||
return {"subject": subject, "text": "\n".join(text), "html": html}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "erp_base.html" %}
|
||||
{% from "inout/_macros.html" import order_badge, progress, due, n, ymd %}
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261019f" />{% endblock %}
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261019g" />{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="io">
|
||||
@@ -68,4 +68,4 @@
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
{% block scripts %}<script src="/static/inout.js?v=20261019b" defer></script>{% endblock %}
|
||||
{% block scripts %}<script src="/static/inout.js?v=20261019c" defer></script>{% endblock %}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
</footer>
|
||||
</dialog>
|
||||
{%- endmacro -%}
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261019f" />{% endblock %}
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261019g" />{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% set active = order.status in ('open', 'partial') %}
|
||||
@@ -253,4 +253,4 @@
|
||||
{% endif %}
|
||||
</section>
|
||||
{% endblock %}
|
||||
{% block scripts %}<script src="/static/inout.js?v=20261019b" defer></script>{% endblock %}
|
||||
{% block scripts %}<script src="/static/inout.js?v=20261019c" defer></script>{% endblock %}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{% extends "erp_base.html" %}
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261019f" />{% endblock %}
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261019g" />{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="io">
|
||||
@@ -80,4 +80,4 @@
|
||||
</form>
|
||||
</section>
|
||||
{% endblock %}
|
||||
{% block scripts %}<script src="/static/inout.js?v=20261019b" defer></script>{% endblock %}
|
||||
{% block scripts %}<script src="/static/inout.js?v=20261019c" defer></script>{% endblock %}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "erp_base.html" %}
|
||||
{% from "inout/_macros.html" import due, n, ymd %}
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261019f" />{% endblock %}
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261019g" />{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="io">
|
||||
@@ -88,4 +88,4 @@
|
||||
{% endif %}
|
||||
</section>
|
||||
{% endblock %}
|
||||
{% block scripts %}<script src="/static/inout.js?v=20261019b" defer></script>{% endblock %}
|
||||
{% block scripts %}<script src="/static/inout.js?v=20261019c" defer></script>{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user