66 lines
3.6 KiB
Python
66 lines
3.6 KiB
Python
"""Backup detail reads the saved pending-detail post-packaging value directly."""
|
|
from pathlib import Path
|
|
import unittest
|
|
|
|
from scripts.backfill_backup_post_packaging import post_pack_for_item
|
|
|
|
|
|
class BackupRemainingPackagingTest(unittest.TestCase):
|
|
def test_backfill_matches_pending_post_packaging(self):
|
|
item = {'material_code': 'M1', 'quantity': 1,
|
|
'actual_quantity': 0, 'pre_pack_qty': 5000}
|
|
self.assertEqual(post_pack_for_item(item, 3000, {}), 2000)
|
|
item['actual_quantity'] = 3000
|
|
item['pre_pack_qty'] = 0
|
|
self.assertEqual(post_pack_for_item(item, 3000, {}), 0)
|
|
|
|
def test_frontend_column_is_next_to_order_quantity(self):
|
|
source = (Path(__file__).resolve().parents[1] / 'static/js/app.js').read_text(encoding='utf-8')
|
|
self.assertIn('>下单数量</th>', source)
|
|
self.assertIn('>剩余包材</th>', source)
|
|
self.assertIn("remainingPack = b.post_pack_qty", source)
|
|
purchase_source = (Path(__file__).resolve().parents[1] / 'routes/purchase.py').read_text(encoding='utf-8')
|
|
self.assertIn("bm['post_pack_qty'] = post_pack_qty", purchase_source)
|
|
|
|
def test_backup_detail_includes_lead_time_and_packaging_progress(self):
|
|
root = Path(__file__).resolve().parents[1]
|
|
frontend = (root / 'static/js/app.js').read_text(encoding='utf-8')
|
|
backend = (root / 'routes/purchase.py').read_text(encoding='utf-8')
|
|
|
|
self.assertIn("['货期', (item.lead_time", frontend)
|
|
self.assertIn("item.lead_time + '天'", frontend)
|
|
self.assertIn('>下单进度</th>', frontend)
|
|
self.assertIn("b.order_progress || '-'", frontend)
|
|
|
|
normalize_source = backend[
|
|
backend.index('def _normalize_backup_bom('):
|
|
backend.index("# ─── API: 采购订单 ───")
|
|
]
|
|
self.assertIn("AS order_progress", normalize_source)
|
|
self.assertIn("BINARY `编码`=BINARY %s", normalize_source)
|
|
self.assertIn("BINARY `来源产品编码`=BINARY %s", normalize_source)
|
|
self.assertIn("`下单时间`=%s", normalize_source)
|
|
self.assertIn("current['order_progress']", normalize_source)
|
|
|
|
def test_backup_detail_reads_saved_planning_sales_snapshot(self):
|
|
source = purchase_source = (Path(__file__).resolve().parents[1] / 'routes/purchase.py').read_text(encoding='utf-8')
|
|
frontend = (Path(__file__).resolve().parents[1] / 'static/js/app.js').read_text(encoding='utf-8')
|
|
self.assertIn("row['sales_info']", source)
|
|
detail_source = source[source.index('def purchase_backup_detail():'):source.index("@purchase_bp.route('/api/purchase/pending_export')")]
|
|
self.assertIn("raw_snapshot = row.pop('sales_snapshot', None)", detail_source)
|
|
self.assertNotIn('_build_planning_sales_snapshot(', detail_source)
|
|
self.assertIn('sales_snapshot, sales_snapshot_at', source)
|
|
self.assertIn('与计划预测详情云仓数据完全同源', frontend)
|
|
self.assertIn("return {'__scope': 'cloud'", source)
|
|
self.assertIn("row['sales_snapshot_scope']", source)
|
|
self.assertIn("salesSnapshotScope === 'cloud' ? '云仓数据' : '默认数据(历史)'", frontend)
|
|
self.assertIn('<span>销量信息</span></div>', frontend)
|
|
self.assertIn('class="pd-fields pd-fields-4col"', frontend)
|
|
self.assertIn("formatPopupFieldValue(field[0], value, salesInfo)", frontend)
|
|
self.assertIn("['库存可支撑天数', salesLabelPrefix + '库存可支撑天数']", frontend)
|
|
self.assertIn('历史订单未保存销量快照', frontend)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|