Saving purchase order reverts any amounts changed

Vote:
 

For flat rate markets we store prices without tax in the catalog. We calculate the tax when the price is loaded whenever a user visits a product page. This has caused us to do some extra calculations when using the fixed price promo as the badge that gets shown does not tax into account the tax. We are able to update this value in the badge fine but we have noticed some other issues.

The purchase order still retains the tax of the discounted items which we would like to remove. I have tried the following:
var orderReference = _orderRepository.SaveAsPurchaseOrder(cart);
var purchaseOrder = _orderRepository.Load<PurchaseOrder>(orderReference.OrderGroupId);

purchaseOrder.TaxTotal -= taxAmount;
purchaseOrder.Total -= taxAmount;

purchaseOrder.AcceptChanges();

_orderRepository.Save(purchaseOrder);

After AcceptChanges() the value is still correct but when I call Save the value reverts. Is there a way to stop it reverting on Save?

#224396
Edited, Jun 18, 2020 15:58
Vote:
 

Have you tried creating your own ITaxCalculator?
https://world.episerver.com/documentation/developer-guides/commerce/orders/calculating-orders-intro/calculating-orders-tax-calculator/

The order handling is setup so that different Calculators has the logic that creates the totals that are saved on the PurchaseOrders, they are automatically called by episerver so you can't modify the totals yourself.

#224398
Jun 18, 2020 18:01
Vote:
 

purchaseOrder.AcceptChanges();

_orderRepository.Save(purchaseOrder);

both those lines save the order, only one is needed. I think you should remove AcceptChanges() and try again

#224418
Jun 19, 2020 7:29
Vote:
 

Hi Quan,

I have tried the following:

var orderReference = _orderRepository.SaveAsPurchaseOrder(cart);
var purchaseOrder = _orderRepository.Load<PurchaseOrder>(orderReference.OrderGroupId);

purchaseOrder.TaxTotal -= taxAmount;
purchaseOrder.Total -= taxAmount;

_orderRepository.Save(purchaseOrder);

Which still reverted the amount.

I also tried:

var orderReference = _orderRepository.SaveAsPurchaseOrder(cart);
var purchaseOrder = _orderRepository.Load<PurchaseOrder>(orderReference.OrderGroupId);

purchaseOrder.TaxTotal -= taxAmount;
purchaseOrder.Total -= taxAmount;

purchaseOrder.AcceptChanges();

Which seemed like it had saved the amount but when checking the order in commerce manager the amount has somehow still reverted :(.

I am going to double check if its being saved again further down the line.

#224420
Edited, Jun 19, 2020 8:53
Vote:
 

Hi Quan,

That was it! Further on down the line we were saving the purchase order again using the orderrepository. I have now changed this to AcceptChanges() whichs works much better :).

Thanks!

#224421
Jun 19, 2020 9:07
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.