feat: 添加 SalesOrder 和 SalesOrderItem 模型,映射销售订单及其项 #6
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
yingmo/PharmacyERP!6
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/sales/model"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request overview
This PR introduces new GORM models under
internal/sales/modelto represent sales orders and their line items, mapping tosales_orderandsales_order_itemtables.Changes:
SalesOrdermodel with order header fields, status constants, and anItemsassociation.SalesOrderItemmodel for order line items and its table mapping.💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
@ -0,0 +16,4 @@// SalesOrderStatusFinished 订单完成。SalesOrderStatusFinished = "FINISHED"// SalesOrderStatusCancelled 订单取消。SalesOrderStatusCancelled = "CANCELLED"The sales order status constants use upper-case values (e.g., "DRAFT", "PENDING_AUDIT"), while other status constants in the repo use lower snake-case (e.g.,
inbound_order.gouses "draft", "pending_confirm"). Mixing conventions makes querying/filtering harder and is easy to get wrong across modules. Consider aligning these status values with the existing convention (or documenting why SalesOrder must differ).@ -0,0 +26,4 @@CashierID int64 `gorm:"column:cashier_id;type:bigint;not null" json:"cashier_id"`TotalAmount float64 `gorm:"column:total_amount;type:decimal(10,2);not null" json:"total_amount"`MedicareAmount float64 `gorm:"column:medicare_amount;type:decimal(10,2);default:0" json:"medicare_amount"`PersonalAmount float64 `gorm:"column:personal_amount;type:decimal(10,2);default:0" json:"personal_amount"`The money columns here use
type:decimal(10,2)while existing models usetype:numeric(… ,2)for monetary fields. Since Postgres treats DECIMAL as an alias of NUMERIC this will work, but standardizing on one spelling/precision across models helps keep schemas consistent.@ -0,0 +29,4 @@PersonalAmount float64 `gorm:"column:personal_amount;type:decimal(10,2);default:0" json:"personal_amount"`NeedAudit bool `gorm:"column:need_audit;default:false" json:"need_audit"`NeedMedicare bool `gorm:"column:need_medicare;default:false" json:"need_medicare"`Status string `gorm:"column:status;type:varchar(20);not null;index" json:"status"`statusisnot nullbut has no DB default, which makes creating a new order fragile if any code path forgets to set it. Other order-like models set a default status at the DB level (e.g.,InboundOrder.Statushasdefault:draft). Consider adding a default here (e.g., draft).@ -0,0 +30,4 @@NeedAudit bool `gorm:"column:need_audit;default:false" json:"need_audit"`NeedMedicare bool `gorm:"column:need_medicare;default:false" json:"need_medicare"`Status string `gorm:"column:status;type:varchar(20);not null;index" json:"status"`MedicareTransactionID string `gorm:"column:medicare_transaction_id;type:varchar(100)" json:"medicare_transaction_id"`medicare_amount/personal_amount/medicare_transaction_idare defined as nullable columns (nonot null) but use non-pointer Go types (float64/string). If the DB ever stores NULL (e.g., raw SQL inserts, partial updates, migrations), scanning NULL into these fields can error. Consider making the columnsnot null(with an explicit default) or switching to pointer types (e.g.,*string) for truly optional fields.