You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 20, 2023. It is now read-only.
Describe the bug
Wrong tax is applied to order totals when order is created from admin page with a foreign address which has a VAT-number. Product taxes are correct but not the totals. Frontend orders are not affected.
To Reproduce
Steps to reproduce the behavior:
Have products with taxes and VAT-number module is active
Place an order from admin orders page with an invoice address in another EU country and a VAT-number so no taxes should be applied (correctly shown in the order summary at the bottom)
The order is created with correct order details (..._price_tax_incl = ..._price_tax_excl in table ps_order_details), but the order totals are wrong (e.g. total_products != total_products_wt in table ps_orders). These wrong values lead to an invalid invoice because the product sum is wrong.
Describe the bug
Wrong tax is applied to order totals when order is created from admin page with a foreign address which has a VAT-number. Product taxes are correct but not the totals. Frontend orders are not affected.
To Reproduce
Steps to reproduce the behavior:
Additional information
PrestaShop version: 1.7.6.0
PHP version: 7.2
VAT-number module: 2.0.0
Technical Details
It seams that the order total is calculated here https://github.com/PrestaShop/PrestaShop/blob/c389f90984cdf46c42ecf970342553b6db867aee/controllers/admin/AdminOrdersController.php#L1248 which internally uses the Product::getPriceStatic() function but without an address_id. In this situation, the function tries to get it from the cart object in the context. But the context does not have a cart object yet, so a default address is used with a wrong country. You can see that $id_address is NULL here https://github.com/PrestaShop/PrestaShop/blob/b2f4a3508462790192259028e2e39c3f58a4baca/classes/Product.php#L3218 (compare it to a frontend order which is working correctly).
Possible Solution
Add this
after this line: https://github.com/PrestaShop/PrestaShop/blob/c389f90984cdf46c42ecf970342553b6db867aee/controllers/admin/AdminOrdersController.php#L1231 to set the correct cart in the context before the totals are calculated.
I could provide a pull request for this.