feat: 添加 SalesOrder 和 SalesOrderItem 模型,映射销售订单及其项 #6

Merged
YingmoY merged 1 commit from feat/sales/model into main 2026-03-23 02:45:35 +08:00
YingmoY commented 2026-03-23 02:45:25 +08:00 (Migrated from github.com)
No description provided.
copilot-pull-request-reviewer[bot] (Migrated from github.com) reviewed 2026-03-23 02:48:22 +08:00
copilot-pull-request-reviewer[bot] (Migrated from github.com) left a comment

Pull request overview

This PR introduces new GORM models under internal/sales/model to represent sales orders and their line items, mapping to sales_order and sales_order_item tables.

Changes:

  • Added SalesOrder model with order header fields, status constants, and an Items association.
  • Added SalesOrderItem model for order line items and its table mapping.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

## Pull request overview This PR introduces new GORM models under `internal/sales/model` to represent sales orders and their line items, mapping to `sales_order` and `sales_order_item` tables. **Changes:** - Added `SalesOrder` model with order header fields, status constants, and an `Items` association. - Added `SalesOrderItem` model for order line items and its table mapping. --- 💡 <a href="/YingmoY/PharmacyERP/new/main?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
@ -0,0 +16,4 @@
// SalesOrderStatusFinished 订单完成。
SalesOrderStatusFinished = "FINISHED"
// SalesOrderStatusCancelled 订单取消。
SalesOrderStatusCancelled = "CANCELLED"
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2026-03-23 02:48:22 +08:00

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.go uses "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).

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.go` uses "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"`
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2026-03-23 02:48:22 +08:00

The money columns here use type:decimal(10,2) while existing models use type: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.

The money columns here use `type:decimal(10,2)` while existing models use `type: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"`
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2026-03-23 02:48:21 +08:00

status is not null but 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.Status has default:draft). Consider adding a default here (e.g., draft).

	Status                string           `gorm:"column:status;type:varchar(20);not null;default:DRAFT;index" json:"status"`
`status` is `not null` but 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.Status` has `default:draft`). Consider adding a default here (e.g., draft). ```suggestion Status string `gorm:"column:status;type:varchar(20);not null;default:DRAFT;index" json:"status"` ```
@ -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"`
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2026-03-23 02:48:22 +08:00

medicare_amount / personal_amount / medicare_transaction_id are defined as nullable columns (no not 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 columns not null (with an explicit default) or switching to pointer types (e.g., *string) for truly optional fields.

	MedicareAmount        float64          `gorm:"column:medicare_amount;type:decimal(10,2);not null;default:0" json:"medicare_amount"`
	PersonalAmount        float64          `gorm:"column:personal_amount;type:decimal(10,2);not null;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"`
	MedicareTransactionID string           `gorm:"column:medicare_transaction_id;type:varchar(100);not null;default:''" json:"medicare_transaction_id"`
`medicare_amount` / `personal_amount` / `medicare_transaction_id` are defined as nullable columns (no `not 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 columns `not null` (with an explicit default) or switching to pointer types (e.g., `*string`) for truly optional fields. ```suggestion MedicareAmount float64 `gorm:"column:medicare_amount;type:decimal(10,2);not null;default:0" json:"medicare_amount"` PersonalAmount float64 `gorm:"column:personal_amount;type:decimal(10,2);not null;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"` MedicareTransactionID string `gorm:"column:medicare_transaction_id;type:varchar(100);not null;default:''" json:"medicare_transaction_id"` ```
Sign in to join this conversation.
No description provided.