feat(crm): align product export with ListExportDropdown
Add ids/columns support and unify toolbar export UX. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
09827fdbf3
commit
5c7210facc
5 files changed
+77
-34
No files matched your search
+23
-3
@@ -31,7 +31,12 @@ from app.utils.crm_export_columns import (
|
||||
PRODUCT_EXPORT_COLUMNS,
|
||||
SUPPLIER_INFO_EXPORT_COLUMNS,
|
||||
)
|
||||
from app.utils.excel_export import export_rows_to_xlsx_response
|
||||
from app.utils.excel_export import (
|
||||
EXPORT_MAX_ROWS,
|
||||
ExportValidationError,
|
||||
export_rows_to_xlsx_response,
|
||||
filter_export_columns,
|
||||
)
|
||||
from app.crud.crm.product import (
|
||||
_category_row_to_dict,
|
||||
create_category,
|
||||
@@ -871,6 +876,12 @@ def product_import(
|
||||
return error_response(500, str(e))
|
||||
|
||||
|
||||
def _map_product_export_column_keys(requested: List[str]) -> List[str]:
|
||||
"""前端列表 prop → 导出列 field(如 cost → costPrice)。"""
|
||||
alias = {"cost": "costPrice"}
|
||||
return [alias.get(str(key), str(key)) for key in requested]
|
||||
|
||||
|
||||
@router.post("/products/export")
|
||||
def product_export(
|
||||
body: ProductListBody,
|
||||
@@ -885,23 +896,32 @@ def product_export(
|
||||
db,
|
||||
tenant_no,
|
||||
page=1,
|
||||
page_size=10000,
|
||||
page_size=EXPORT_MAX_ROWS,
|
||||
max_page_size=EXPORT_MAX_ROWS,
|
||||
keyword=body.keyword,
|
||||
category_id=body.category_id,
|
||||
status=body.status,
|
||||
supplier_id=body.supplier_id,
|
||||
ids=body.ids,
|
||||
user_info=user_info,
|
||||
match_product_no=True if body.match_product_no is None else bool(body.match_product_no),
|
||||
match_model=bool(body.match_model) if body.match_model is not None else False,
|
||||
)
|
||||
export_cols = filter_export_columns(
|
||||
PRODUCT_EXPORT_COLUMNS,
|
||||
_map_product_export_column_keys(body.columns) if body.columns else None,
|
||||
)
|
||||
date_str = datetime.now().strftime("%Y%m%d")
|
||||
return export_rows_to_xlsx_response(
|
||||
db,
|
||||
tenant_no=tenant_no,
|
||||
sheet_title="产品列表",
|
||||
columns=PRODUCT_EXPORT_COLUMNS,
|
||||
columns=export_cols,
|
||||
rows=rows,
|
||||
filename_stem=f"产品列表_{date_str}",
|
||||
)
|
||||
except ExportValidationError as e:
|
||||
return error_response(400, str(e))
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
except Exception as e:
|
||||
|
||||
Reference in new issue
Block a user