更新採購單跟商品資料一些bug
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Has been skipped
Koori-ERP-Deploy-System / deploy-production (push) Successful in 52s

This commit is contained in:
2026-01-06 15:45:13 +08:00
parent 7160a7e780
commit fad74df6ac
9 changed files with 159 additions and 64 deletions

View File

@@ -26,31 +26,25 @@ class PurchaseOrderItem extends Model
'received_quantity' => 'decimal:2',
];
protected $appends = [
'productName',
'unit',
'productId',
'unitPrice',
];
public function getProductIdAttribute(): string
{
return (string) $this->attributes['product_id'];
}
public function getUnitPriceAttribute(): float
{
return (float) $this->attributes['unit_price'];
}
// 移除 $appends 以避免自動附加導致的錯誤
// 這些屬性將在 Controller 中需要時手動附加
// protected $appends = ['productName', 'unit'];
public function getProductNameAttribute(): string
{
return $this->product ? $this->product->name : '';
return $this->product?->name ?? '';
}
public function getUnitAttribute(): string
{
return $this->product ? $this->product->base_unit : '';
// 優先使用採購單位 > 大單位 > 基本單位
// 與 PurchaseOrderController 的邏輯保持一致
if (!$this->product) {
return '';
}
return $this->product->purchase_unit
?: ($this->product->large_unit ?: $this->product->base_unit);
}
public function purchaseOrder(): BelongsTo