因此,我正在開發一個發票模塊,並堅持一個邏輯。 步驟來生成發票:如何開發部分發票模塊的邏輯/算法?
Bringing all those rows whose cancelled_date is none or is of current_month from the database
這給了我所有的數據,生成客戶的發票當月。
僞代碼 -
If membership is new:
if (working_days/total_days) in a month is 1:
Don't calculate prorata
else:
calculate pro rata(For no. of days)
else:
calculate invoice generally
現在的問題是:客戶的cancelled_date可在上述方案等進行設定: 僞代碼 -
If membership is new:
if (working_days/total_days) in a month is 1:
if cancelled_date == end_date_month:
Don't calculate prorata
else:
calculate pro rata
else:
if cancelled_date == end_date_month:
calculate pro rata(For no. of days)
else:
calculate pro rata (start_date & end_date for current
month)
else:
if cancelled_date == end_date_month:
calculate invoice generally
else:
calculate pro rata
我怎麼能不使僅通過簡單地解決cancelled_date場景來減少代碼。我無法想到上面的一個好邏輯/算法。
嘿,你好,謝謝!這也導致如果其他因爲代碼是在Python中。我仍然需要把這些if/else。 –
對不起,我沒有考慮到這一點 – OzW
我在想的是做兩個單獨的函數,並在類中爲cancelled_membership創建一個屬性並計算它們在不同函數中的發票。 –