Grailsを使用して請求書管理アプリケーションを作成していますが、継承で問題が発生しています。
各請求書に行/アイテムのコレクションを含める必要があり、請求書が印刷用にフォーマットされている場合、アイテムは日付で並べ替えられ、カテゴリごとにリストに分けられ、各行の価格が異なる方法で計算されるようにすることが私の意図である場合具体的なタイプごとの方法(時間指定されたアイテムはratesプロパティで1時間ごとに検索され、価格設定されたアイテムには作成時に価格が割り当てられます)。
Node Invoiceには、Itemオブジェクトのコレクションであるプロパティ「items」があります。
私のドメインクラスのソース:
class Invoice {
static constraints = {
}
String client
Date dateCreated
Date lastUpdated
CostProfile rates
def relatesToMany = [items : Item]
Set items = new HashSet()
}
abstract class Item{
static constraints = {
}
String description
Date date
enum category {SERVICE,GOODS,OTHER}
def belongsTo = Invoice
Invoice invoice
}
class TimedItem extends Item{
static constraints = {
}
int minutes
}
class PricedItem extends Item{
static constraints = {
}
BigDecimal cost
BigDecimal taxrate
}
問題のあるコードのソース:
invoiceInstance.items.add(new TimedItem(description:"waffle", minutes:60, date:new Date(),category:"OTHER"))
def firstList = []
def lastList = []
invoiceInstance.items.sort{it.date}
invoiceInstance.items.each(){
switch(((Item)it).category){
case "LETTER":
firstList.add(it)
break;
default:
lastList.add(it)
}
}
エラーメッセージ:
groovy.lang.MissingPropertyException:No such property:category for class:TimedItem
Stacktraceは、上記の例の6行目を示しています。