Developer forum

Forum » Development » VAT applied twice on discounts in Custom SalesDiscountProvider

VAT applied twice on discounts in Custom SalesDiscountProvider


Reply

Hi there,

I am having an issue with a custom SalesDiscountProvider. I have the following specs:

 

1. Prices in DB including sales tax: Off

2. Sales tax: 19% (system wide and default sales group)

3. I have a product with a price of 100 euro

4. When displayed on the page and in the cart, the price displays as 119 euro (which is good; 100 euro + 19% tax).

 

However, when I try to calculate a discount using a custom SalesDiscountProvider (based on the Extensibility API documentation), by discount is taxed twice. When I try to give  a 10% discount, the discount amount is 14.161 instead of 11.90. 14.161 is the correct discount price (e.g. 11.90) + an additional 19% sales tax.

 

Am I doing something wrong? Is the sample code from the API documentation not OK or does it assume other configuration settings? Can you suggest a better solution?

Here's the gist of the method that adds the diccount order line. As comments, I added some remarks and questions about my observations on the price and tax values.


public override void ProcessOrder(eCommerce.Orders.Order order)
{
  if (_DiscountValue.Type == DiscountTypes.Percent)
  {
    double discountPercentage = 10; // Fake number; is calculated in the real implementation
    double discountPrice;

    discountPrice = (order.PriceBeforeFees.Price / 100) * discountPercentage.Value;
 // discountPrice is now 11.90 which is fine

    // Get rawprice of the discount.
    PriceRaw rawprice = new PriceRaw(discountPrice, Dynamicweb.eCommerce.Common.Application.DefaultCurrency);
 // rawPrice.Price is now 11.90 which is still fine
 
    // Convert to a calculated price
    PriceCalculated CalcPrice = new Dynamicweb.eCommerce.Prices.PriceCalculated(rawprice);
 // CalcPrice.Prince is now 14.161 which is not good. Its ShowPricesWithVAT is set to True
 
    CalcPrice.PriceWithoutVAT = CalcPrice.PriceWithVAT;
 // Should this actually be the other way around? Do we even need this?
 
    CalcPrice.VATPercent = 0;
    CalcPrice.VAT = 0;
 
    // We need a negative value
    discountPrice = CalcPrice.Price - (CalcPrice.Price * 2);
    // Add a new order line
    OrderLine line = new OrderLine();
    line.Order = order;
    line.Quantity = 1;
    line.ProductName = DiscountName;
    line.SetUnitPrice(discountPrice);
    line.Type = Base.ChkString(Base.ChkNumber(OrderLine.OrderLineType.Discount));
    // Insert orderline
    order.OrderLines.Add(line, false);
  }
}


Replies

 

You must be logged in to post in the forum