Commit 15db7c0d by Tuukka Kivilahti

Merge branch 'billDiscountBug' into 'master'

Bill discount bug

Bill discounts were not stacked as they should have.
If product had multiple discounts, all discounts were calculated
from the original price, not the previous result.

See merge request !352
2 parents 53215047 c41cb319
...@@ -369,9 +369,11 @@ public class BillBean implements BillBeanLocal { ...@@ -369,9 +369,11 @@ public class BillBean implements BillBeanLocal {
} }
bill.getBillLines().add(new BillLine(bill, product, count, foodwave, additionalDescription)); bill.getBillLines().add(new BillLine(bill, product, count, foodwave, additionalDescription));
BigDecimal discountPrice = product.getPrice();
for (Discount disc : discountBean.getActiveDiscountsByProduct(product, count, bill.getSentDate(), bill.getUser())) { for (Discount disc : discountBean.getActiveDiscountsByProduct(product, count, bill.getSentDate(), bill.getUser())) {
bill.getBillLines().add(new BillLine(bill, product, disc, count)); BillLine line = new BillLine(bill, product, disc,discountPrice, count);
discountPrice = discountPrice.subtract(line.getUnitPrice());
bill.getBillLines().add(line);
} }
return bill; return bill;
......
...@@ -157,10 +157,10 @@ public class BillLine extends GenericEntity { ...@@ -157,10 +157,10 @@ public class BillLine extends GenericEntity {
* @param disc * @param disc
* @param count * @param count
*/ */
public BillLine(Bill bill2, Product product, Discount disc, BigDecimal count) { public BillLine(Bill bill2, Product product, Discount disc, BigDecimal price, BigDecimal count) {
super(); super();
this.bill = bill2; this.bill = bill2;
BigDecimal unitPrice = product.getPrice().subtract(product.getPrice().multiply(disc.getPercentage())).negate().setScale(Bill.BILL_PRICE_SCALE, RoundingMode.HALF_UP); BigDecimal unitPrice = price.subtract(price.multiply(disc.getPercentage())).negate().setScale(Bill.BILL_PRICE_SCALE, RoundingMode.HALF_UP);
this.name = disc.getShortdesc(); this.name = disc.getShortdesc();
this.unitName = product.getUnitName(); this.unitName = product.getUnitName();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!