更新採購單跟商品資料一些bug
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user