forked from erp-dev/erp
feat: allocation record for pre sales order
This commit is contained in:
@@ -3,14 +3,60 @@ from __future__ import annotations
|
||||
from decimal import Decimal, InvalidOperation
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import transaction
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils import timezone
|
||||
|
||||
from basic_info import models as basic_info_models
|
||||
|
||||
from . import models
|
||||
|
||||
|
||||
def render_pre_sales_order_created_markdown(
|
||||
*,
|
||||
pre_sales_order_id: str,
|
||||
human_id: str,
|
||||
created_at: str,
|
||||
sender_label: str,
|
||||
customer_name: str,
|
||||
warehouse_name: str,
|
||||
kind: str,
|
||||
items_count: int,
|
||||
) -> str:
|
||||
template = getattr(
|
||||
settings,
|
||||
"PRE_SALES_ORDER_CREATED_WECOM_MARKDOWN_TEMPLATE",
|
||||
(
|
||||
"### 预销售单创建\n"
|
||||
"\n"
|
||||
"- **预销售单ID**:`{pre_sales_order_id}`\n"
|
||||
"- **订单编号**:`{human_id}`\n"
|
||||
"- **创建时间**:`{created_at}`\n"
|
||||
"- **发送者**:{sender_label}\n"
|
||||
"- **客户**:{customer_name}\n"
|
||||
"- **仓库**:{warehouse_name}\n"
|
||||
"- **类型**:{kind}\n"
|
||||
"- **明细条数**:`{items_count}`\n"
|
||||
),
|
||||
)
|
||||
|
||||
created_at_str = (created_at or "").strip()
|
||||
if not created_at_str:
|
||||
created_at_str = timezone.localtime(timezone.now()).strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
return template.format(
|
||||
pre_sales_order_id=str(pre_sales_order_id or "-") or "-",
|
||||
human_id=str(human_id or "-") or "-",
|
||||
created_at=str(created_at_str),
|
||||
sender_label=str(sender_label or "系统自动发送"),
|
||||
customer_name=str(customer_name or "-"),
|
||||
warehouse_name=str(warehouse_name or "-"),
|
||||
kind=str(kind or "-"),
|
||||
items_count=int(items_count) if items_count is not None else 0,
|
||||
)
|
||||
|
||||
|
||||
def _to_decimal(value: Any, *, field_name: str) -> Decimal:
|
||||
if value is None or value == '':
|
||||
raise ValueError(f'{field_name} 不能为空')
|
||||
|
||||
Reference in New Issue
Block a user