|
@@ -411,6 +411,12 @@ class OutputPresenter:
|
|
|
'closing_status': '关账状态',
|
|
'closing_status': '关账状态',
|
|
|
'verification_status': '核销状态',
|
|
'verification_status': '核销状态',
|
|
|
}
|
|
}
|
|
|
|
|
+ RECEIVABLE_COST_SUMMARY = {
|
|
|
|
|
+ 'order_total_receivable_cny': '订单总应收(CNY)',
|
|
|
|
|
+ 'order_total_settlement_cny': '订单总结算(CNY)',
|
|
|
|
|
+ 'special_approval_amount_cny': '特批金额(CNY)',
|
|
|
|
|
+ 'settlement_gross_profit_cny': '结算毛利(CNY)',
|
|
|
|
|
+ }
|
|
|
RECEIVABLE_LIST_COLUMNS = {
|
|
RECEIVABLE_LIST_COLUMNS = {
|
|
|
'main_customer_name': '主客户',
|
|
'main_customer_name': '主客户',
|
|
|
'sub_customer_name': '子客户',
|
|
'sub_customer_name': '子客户',
|
|
@@ -1391,13 +1397,20 @@ class OutputPresenter:
|
|
|
return self._success_result(content, self._render_table(content), meta)
|
|
return self._success_result(content, self._render_table(content), meta)
|
|
|
|
|
|
|
|
def _present_order_receivable_cost_details(self, data, raw_meta, meta):
|
|
def _present_order_receivable_cost_details(self, data, raw_meta, meta):
|
|
|
- if set(data) != {'columns', 'records'}:
|
|
|
|
|
|
|
+ if set(data) != {'summary', 'columns', 'records'}:
|
|
|
return self._format_error(meta)
|
|
return self._format_error(meta)
|
|
|
columns = data.get('columns')
|
|
columns = data.get('columns')
|
|
|
records = data.get('records')
|
|
records = data.get('records')
|
|
|
|
|
+ summary = data.get('summary')
|
|
|
pagination = self._customer_pagination(raw_meta)
|
|
pagination = self._customer_pagination(raw_meta)
|
|
|
expected_keys = list(self.RECEIVABLE_COST_COLUMNS)
|
|
expected_keys = list(self.RECEIVABLE_COST_COLUMNS)
|
|
|
- if not isinstance(columns, list) or not isinstance(records, list):
|
|
|
|
|
|
|
+ expected_summary = list(self.RECEIVABLE_COST_SUMMARY)
|
|
|
|
|
+ if (
|
|
|
|
|
+ not isinstance(columns, list)
|
|
|
|
|
+ or not isinstance(records, list)
|
|
|
|
|
+ or not isinstance(summary, dict)
|
|
|
|
|
+ or set(summary) != set(expected_summary)
|
|
|
|
|
+ ):
|
|
|
return self._format_error(meta)
|
|
return self._format_error(meta)
|
|
|
actual_keys = []
|
|
actual_keys = []
|
|
|
for column in columns:
|
|
for column in columns:
|
|
@@ -1413,6 +1426,17 @@ class OutputPresenter:
|
|
|
if actual_keys != expected_keys or pagination is None:
|
|
if actual_keys != expected_keys or pagination is None:
|
|
|
return self._format_error(meta)
|
|
return self._format_error(meta)
|
|
|
|
|
|
|
|
|
|
+ summary_row = []
|
|
|
|
|
+ for key in expected_summary:
|
|
|
|
|
+ value = summary[key]
|
|
|
|
|
+ if (
|
|
|
|
|
+ isinstance(value, bool)
|
|
|
|
|
+ or not isinstance(value, (int, float))
|
|
|
|
|
+ or not math.isfinite(float(value))
|
|
|
|
|
+ ):
|
|
|
|
|
+ return self._format_error(meta)
|
|
|
|
|
+ summary_row.append(value)
|
|
|
|
|
+
|
|
|
numeric_keys = {
|
|
numeric_keys = {
|
|
|
'charge_weight', 'unit_price', 'receivable_original_amount',
|
|
'charge_weight', 'unit_price', 'receivable_original_amount',
|
|
|
'receivable_amount_cny', 'settlement_amount_cny',
|
|
'receivable_amount_cny', 'settlement_amount_cny',
|
|
@@ -1440,8 +1464,34 @@ class OutputPresenter:
|
|
|
{'label': self.RECEIVABLE_COST_COLUMNS[key]}
|
|
{'label': self.RECEIVABLE_COST_COLUMNS[key]}
|
|
|
for key in expected_keys
|
|
for key in expected_keys
|
|
|
]
|
|
]
|
|
|
- content = {'headers': headers, 'rows': rows, 'pagination': pagination}
|
|
|
|
|
- return self._success_result(content, self._render_table(content), meta)
|
|
|
|
|
|
|
+ content = {
|
|
|
|
|
+ 'summary': {
|
|
|
|
|
+ 'headers': [
|
|
|
|
|
+ {'label': self.RECEIVABLE_COST_SUMMARY[key]}
|
|
|
|
|
+ for key in expected_summary
|
|
|
|
|
+ ],
|
|
|
|
|
+ 'row': summary_row,
|
|
|
|
|
+ },
|
|
|
|
|
+ 'headers': headers,
|
|
|
|
|
+ 'rows': rows,
|
|
|
|
|
+ 'pagination': pagination,
|
|
|
|
|
+ }
|
|
|
|
|
+ return self._success_result(
|
|
|
|
|
+ content, self._render_order_receivable_cost_details(content), meta
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ def _render_order_receivable_cost_details(cls, content):
|
|
|
|
|
+ lines = ['订单汇总:']
|
|
|
|
|
+ summary = content['summary']
|
|
|
|
|
+ for header, value in zip(summary['headers'], summary['row']):
|
|
|
|
|
+ lines.append('- {0}: {1}'.format(header['label'], value))
|
|
|
|
|
+ lines.append('费用明细:')
|
|
|
|
|
+ lines.append(cls._render_table({
|
|
|
|
|
+ 'headers': content['headers'],
|
|
|
|
|
+ 'rows': content['rows'],
|
|
|
|
|
+ }))
|
|
|
|
|
+ return '\n'.join(lines)
|
|
|
|
|
|
|
|
def _present_receivable_cost_list(self, data, raw_meta, meta):
|
|
def _present_receivable_cost_list(self, data, raw_meta, meta):
|
|
|
if set(data) != {'columns', 'records'}:
|
|
if set(data) != {'columns', 'records'}:
|