invoice_template.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from typing import Any, Dict
  2. from core.document_processor.templates.base_template import DocumentTemplate
  3. class InvoiceTemplate(DocumentTemplate):
  4. """发票模板"""
  5. @property
  6. def template_name(self) -> str:
  7. return "invoice"
  8. @property
  9. def description(self) -> str:
  10. return "增值税发票识别模板"
  11. def output_schema(self) -> Dict[str, Any]:
  12. return {
  13. "invoice_code": "发票代码",
  14. "invoice_number": "发票号码",
  15. "issue_date": "开票日期",
  16. "seller_name": "销售方名称",
  17. "seller_tax_id": "销售方税号",
  18. "buyer_name": "购买方名称",
  19. "buyer_tax_id": "购买方税号",
  20. "amount_without_tax": "不含税金额",
  21. "tax_amount": "税额",
  22. "total_amount": "价税合计",
  23. "items": [
  24. {
  25. "name": "货物或服务名称",
  26. "specification": "规格型号",
  27. "unit": "单位",
  28. "quantity": "数量",
  29. "unit_price": "单价",
  30. "amount": "金额",
  31. }
  32. ],
  33. }
  34. def extraction_rules(self) -> str:
  35. return """
  36. """
  37. def validate_result(self, result: Dict) -> bool:
  38. # 验证必填字段
  39. required_fields = ["invoice_number", "total_amount", "issue_date"]
  40. return all(field in result for field in required_fields)