Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INVOICE] Bad display of Basic price and total tax when free gift tax rate is not the same as the products #24122

Open
Tracked by #13822
jcarloscid opened this issue Apr 20, 2021 · 14 comments
Labels
1.7.6.7 Affects versions BO Category: Back Office Bug Type: Bug Invoices Label: Which BO under menu is concerned Minor Severity: minor bug > https://build.prestashop.com/news/severity-classification Ready Status: Issue is ready to be worked on Taxes and Prices Component: Which BO section is concerned Verified The issue has been reproduced

Comments

@jcarloscid
Copy link

jcarloscid commented Apr 20, 2021

Describe the bug

PS-issue-sample.pdf
I am attaching the invoice of a sample order demonstrating the issue.
The total tax amount is correct, however the breakdown is incorrect.

Invoice data:
Products 4.000 % 0,80 €
21.000 % 0,46 €
Shipping 21.000 % 0,84 €

Expected behavior

Expected data:
Products 4.000 % 1,26 €
21.000 % 0,00 €
Shipping 21.000 % 0,84 €

Rationale:
The order contains a gift (via cart rule). The gross price of the product is 4,13€ and the tax rate is 21% for that product. As the net price of this product is 0€, taxes should be 0€ also. This is a mistake in the breakdown.

Shipping price is 4,00€ and tax rate is 21% (0,84€). This is computed correctly.

The non-gifted product has a price of 31,50€ and a tax rate of 4% (so taxes are 1,26€). This is a mistake in the breakdown as it should appear on the tax rate 4% line.

Tesis 1: As for tax calculation, the discount applies to the item with the lowest tax rate.
Item #1 base price: 4,13€ -- Tax rate 21% -- Taxes: 0,87€
Item #2 Base price: 31,50€ - 4,13 = 27,37€ -- Tax rate 4% -- Taxes: 1,09€

Tesis 1 does not explain tax breakdown.

Tesis 2: Discount is prorated among all products
Item #1 base price: 4,13€ -- Discount (4,13/35,63) * 4,13 = 0,48€ -- Net price: 3,65€ -- Tax rate 21% -- Taxes: 0,77€
Item #2 Base price: 31,50€ -- Discount (4,13/35,63) * 31,50 = 3,65€ -- Net price: 27,85 -- Tax rate 4% -- Taxes: 1,11€

Tesis 2 does not explain tax breakdown either.

Possible root cause:
My guess is that taxes are computed correctly for the order but are then incorrectly translated to the database.

In table ps_order_invoice, discounts only appear as a summary. There is no breakdown.
ps_order_invoice.total_discount_tax_excl
ps_order_invoice.total_discount_tax_incl

Ass far as I know there is no breakdown of discounts applied in any table.

Table ps_order_detail does not include information of the discount that applies to each order line.

Table ps_order_cart_rule does not include information of the tax rule that applies to the discount.

Table ps_order_detail_tax has inconsistent data. For the sample above unit amount and total amount should be equal, but:

id_order_detail id_tax  unit_amount total_amount    
3523            2        1.113949        0.800000    
3524            1        0.767182        0.460000    

Note that unit_amount column matches the calculations using tesis 2.

Note also that the sum of total_amount is correct according to the rationale (the discount is applied to the gifted product), but the breakdown by each product does not have any sense.

Steps to reproduce

  1. Create a product A with tax 10% and price 100 euros (this amount is just a sample)
  2. Create a product B with tax 20% & price = 100 euros
  3. Create a cart rule: select product B as free gift, the cart rule is applied automatically
  4. Create an order with product A (it should add product B as a gift)
  5. See error => Tax breakdown is wrong (the products line at 20% should be 0 as product B is a gift).

Screenshots

image

Additional infos

  • PS version: 1.7.7.1
  • PHP version: 7.3.27
@hibatallahAouadni
Copy link
Contributor

Hello @jcarloscid

Could you please provide your PrestaShop and PHP versions.
Please check this EPIC #9703 it contains all the issue related to this subject, and I think your issue is similar to this one #11722

Please check and feedback.
Thanks!

@hibatallahAouadni hibatallahAouadni added 1.7.x Branch Bug Type: Bug NMI Status: issue needs more information Taxes and Prices Component: Which BO section is concerned BO Category: Back Office Invoices Label: Which BO under menu is concerned labels Apr 20, 2021
@jcarloscid
Copy link
Author

PS version is 1.7.7.1
PHP version is 7.3.27

I do no think my issue is really similar to #11722

The key to reproduce the issue is:

  • The order contains products with different tax (VAT) rates
  • One of the products is for free (a gift) via a cart rule (like free gift for orders above xx€)

And the wrong thing is on the taxes breakdown, not on the discount.

The discount as defined on the cart rule is applied correctly. Overall taxes are computed correctly (assuming that the discounted amount correspond to the price of the gift). but the taxes breakdown is wrong.

I also have not seen any similar issue on EPIC #9703

@jcarloscid
Copy link
Author

Ping @PrestaShop/prestashop-core-developers friendly reminder ;-)

@matks
Copy link
Contributor

matks commented May 2, 2021

Hello @jcarloscid, the team is currently under heavy workload because of the deep testing of PrestaShop 1.7.7.4 so you might need some patience before next answer 😉

@Webstudio7
Copy link

Webstudio7 commented May 7, 2021

We are experiencing the same problems with the conditions below, the tax breakdown is completely wrong.
On the example below the product with 9% TAX is free because this is a gift.

Still there is € 0,75 of 9% VAT on the invoice.

Conditions to create this problem -->

  • The order contains products with different tax (VAT) rates
  • One of the products is for free (a gift) via a cart rule (like free gift for orders above xx€)

PS version is 1.7.7.4
PHP version is 7.3.27

71000009f

@hibatallahAouadni hibatallahAouadni added 1.7.7.1 Affects versions and removed 1.7.x Branch labels May 11, 2021
@hibatallahAouadni
Copy link
Contributor

hibatallahAouadni commented May 11, 2021

Hello @jcarloscid

Thanks for your patience and sorry for the late response 🙏
So to sumarize the issue, we need to follow these steps to reproduce it:

  1. create a product A with tax 21%
  2. create a product B with tax 9%
  3. create a cart rule with condition: Minimum amount: 20 euros, and action: select product B as free gift
  4. create an Order with product A and apply the created cart rule
  5. See error => the total tax is wrong

Is those steps right? did I miss something?
And could you please check if you encounred this issue with PS1.7.6.9 (or any lower version)?
Please check and feedback.

PS: related to #22951

Thanks!

@jcarloscid
Copy link
Author

To be more precise:

  1. Create a transport method T with tax 21% available for the products below
  2. Create a product A with tax 4% and price above 100 euros (this amount is just a sample)
  3. Create a product B with tax 21%
  4. Create a cart rule with condition: Minimum amount: 100 euros, and action: select product B as free gift, the cart rule is applied automatically
  5. Create an order with product A (it should add product B as a gift)
  6. See error => Tax breakdown is wrong (the products line at 21% should be 0 as product B is a gift). Total taxes however are correct.

I will try to test this in another PS 1.7.6.x version, but I can't guarantee I will find a suitable environment. I will let you know if I succeed.

2-000050-2021 (1).pdf

@hibatallahAouadni
Copy link
Contributor

Hello @jcarloscid

It seems everythink ok to me, see the attached screenshot below:

image

image

But, in the invoice, I encounter an issue similar to this one #19790:

image

I remember that I have seen this issue but I couldn't find it 😕
Ping @khouloudbelguith could you please help me to find it.

  1. See error => Tax breakdown is wrong (the products line at 21% should be 0 as product B is a gift). Total taxes however are correct.

In my case, the total is correct: product_a (104.00) + shipping (12.10) = (116.10) ✔️
And total tawes is correct too: product_a tax (4.00) + shipping (2.10) = (6.10) ✔️

Thanks!

@jcarloscid
Copy link
Author

Great!! You have reproduced the issue.

As far as i have investigated the problem is on the data model. PrestaShop does not persist enough information in order to be able to rebuild this invoice correctly.

Take a look at table ps_order_detail_tax for this order and try to explain current figures.

@hibatallahAouadni
Copy link
Contributor

Hello @jcarloscid

Thanks to @khouloudbelguith we found the original issue #14646
Could you please check it 🙏 just to make sure that your issue is a duplicate of #14646

Thanks!

@jcarloscid
Copy link
Author

Well, I can´t tell this is the same case.

I think that the key point on my issue is that we have TWO PRODUCT with a different tax rate each and one of them is A GIFT.

Issue #14646 tells about a SINGLE PRODUCT with TWO taxes.

But on May 20th you already reproduced my issue. The issue is on the invoice, not on the order, and it affects the tax breakdown (total tax is correct).

Why I think you have all these three issues (#24122, #14646 and #19790)? My guess is that PrestaShop does not persists enough information on the database in order to correctly rebuild the tax breakdown, so it is prorating somewhat the taxes for the products using the total taxes and the (base price * quantity) of the products.

@hibatallahAouadni
Copy link
Contributor

Hello @jcarloscid

Well then, thanks for your feedback!
I was able to reproduce the issue with PS1.7.6.7, PS1.7.7.4 and develop. I’ll add this to the debug backlog so that it’s fixed.

image

Please be aware that due to the high number of reported issues, some bugs might take a very long time to be resolved. If this issue is important to you and you cannot wait for it to be fixed on the project’s own time, we strongly suggest you consider hiring a specialist to help you.

If you manage to get the problem fixed, then please contribute the fix back to the project as a Pull Request. Remember that the more people contribute, the better PrestaShop becomes for everyone.

Thank you

@hibatallahAouadni hibatallahAouadni added Minor Severity: minor bug > https://build.prestashop.com/news/severity-classification Ready Status: Issue is ready to be worked on and removed NMI Status: issue needs more information labels May 31, 2021
@jcarloscid
Copy link
Author

Perfect. Thanks.

@hibatallahAouadni hibatallahAouadni changed the title Taxes incorrectly computed for an order that includes a discount and products with different tax rates [INVOICE] Bad display of Basic price and total tax when free gift tax rate is not the same as the products May 31, 2021
@hibatallahAouadni hibatallahAouadni added 1.7.6.7 Affects versions 1.7.7.4 Affects versions develop Branch and removed 1.7.7.1 Affects versions labels May 31, 2021
@hibatallahAouadni hibatallahAouadni added Verified The issue has been reproduced and removed develop Branch 1.7.7.4 Affects versions labels Jan 13, 2022
@Nonoland
Copy link

Hello,
I have the same problem with my version of PrestaShop 1.7.8.1
When I have a free product with a cart rule but this product has a different tax, the tax is still paid by the customer.

Is there no solution found?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.7.6.7 Affects versions BO Category: Back Office Bug Type: Bug Invoices Label: Which BO under menu is concerned Minor Severity: minor bug > https://build.prestashop.com/news/severity-classification Ready Status: Issue is ready to be worked on Taxes and Prices Component: Which BO section is concerned Verified The issue has been reproduced
Projects
None yet
Development

No branches or pull requests

5 participants