Skip to content

Change vat management for supplier prices#37737

Open
SylvainLegrand wants to merge 2 commits intoDolibarr:developfrom
SylvainLegrand:NEW_PURCHASE_VAT_MANAGEMENT
Open

Change vat management for supplier prices#37737
SylvainLegrand wants to merge 2 commits intoDolibarr:developfrom
SylvainLegrand:NEW_PURCHASE_VAT_MANAGEMENT

Conversation

@SylvainLegrand
Copy link
Copy Markdown
Contributor

When creating a supplier price:
1 - The default VAT rate is the product's sales VAT rate. In many situations, this isn't a problem because the sales and purchase VAT rates are the same. However, for the construction sector, with its reduced sales VAT rate, this behavior is inconsistent.
2 - If the multi-currency function is enabled, no default currency is offered, which is a waste of time in 80% of cases.

This fix applies the default purchase VAT rate and the company's base currency.

When creating a supplier price:
1 - The default VAT rate is the product's sales VAT rate.
In many situations, this isn't a problem because the sales and purchase VAT rates are the same.
However, for the construction sector, with its reduced sales VAT rate, this behavior is inconsistent.
2 - If the multi-currency function is enabled, no default currency is offered, which is a waste of time in 80% of cases.
This fix applies the default purchase VAT rate and the company's base currency.
Copilot AI review requested due to automatic review settings April 3, 2026 19:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts the default values proposed when creating/editing supplier prices to better match purchasing workflows (notably in cases where sales VAT differs from purchase VAT, and when multicurrency is enabled).

Changes:

  • Change the suggested default supplier VAT from product sales VAT to a standard country VAT rate (by not passing the product id into get_default_tva()).
  • Always default supplier price currency to the company base currency when no currency is set.
  • Default the multicurrency rate display fallback to 1.
Comments suppressed due to low confidence (2)

htdocs/product/price_suppliers.php:642

  • The VAT default can legitimately be 0 (e.g., seller not subject to VAT). With the current logic, a 0 result from get_default_tva() will later be treated as “empty” (notably via the $default_vat != '' check when building $vattosuggest), so the field renders blank and the form validation then rejects the submission. Consider using a strict empty-string check (or is_numeric) when deciding whether to format/show the default VAT so that 0 is preserved and displayed as "0".
			$default_vat = get_default_tva($mysoc2, $mysoc, 0, 0); // use standard country VAT rate, not product sale VAT rate (accounting non-sense for purchases)
			$default_npr = get_default_npr($mysoc2, $mysoc, 0, 0);
			if (empty($default_vat)) {
				$default_npr = $default_vat;
			}

htdocs/product/price_suppliers.php:706

  • The currency rate <input> value is built by printing GETPOST('multicurrency_tx') and then printing the formatted $vatratetoshow, which can concatenate two values when the form is re-rendered after a POST (e.g., "0.50.5"), producing an invalid value. Build the value from a single computed source (e.g., $vatratetoshow) and use GETPOSTISSET('multicurrency_tx') to distinguish an explicitly-posted empty string from “not provided”.
				print '<input class="flat width50" name="multicurrency_tx" value="';
				print GETPOST('multicurrency_tx');
				$vatratetoshow = GETPOST('multicurrency_tx') ? GETPOST('multicurrency_tx') : (isset($object->fourn_multicurrency_tx) ? $object->fourn_multicurrency_tx : '1'); // change: default rate to 1
				if ($vatratetoshow !== '') {
					print vatrate($vatratetoshow);
				}
				print '">';

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

$mysoc2->tva_assuj = 1;
$default_vat = get_default_tva($mysoc2, $mysoc, $object->id, 0);
$default_npr = get_default_npr($mysoc2, $mysoc, $object->id, 0);
$default_vat = get_default_tva($mysoc2, $mysoc, 0, 0); // use standard country VAT rate, not product sale VAT rate (accounting non-sense for purchases)
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in the inline comment: "non-sense" is typically spelled "nonsense". Consider also rephrasing to a more neutral description (e.g., "not appropriate for purchases").

Suggested change
$default_vat = get_default_tva($mysoc2, $mysoc, 0, 0); // use standard country VAT rate, not product sale VAT rate (accounting non-sense for purchases)
$default_vat = get_default_tva($mysoc2, $mysoc, 0, 0); // Use standard country VAT rate, not product sale VAT rate (not appropriate for purchases)

Copilot uses AI. Check for mistakes.
$mysoc2->tva_assuj = 1;
$default_vat = get_default_tva($mysoc2, $mysoc, $object->id, 0);
$default_npr = get_default_npr($mysoc2, $mysoc, $object->id, 0);
$default_vat = get_default_tva($mysoc2, $mysoc, 0, 0); // use standard country VAT rate, not product sale VAT rate (accounting non-sense for purchases)
Copy link
Copy Markdown
Member

@eldy eldy Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default vat rate of a product depends on 3 param: the country seller, the country buyer and the product itself. Whatever ir country, the rule dependson this 3 parameters so there is no reason to remove the of of project.
For exemple if default vat for product X when seller is german is 10% , we must get 10%,but for other products like product Y, the default vat rate may be 12%.

If there is this rule to define a default vat rate when you sell as a french to a german, you should have exactly the same rule when you buy as a german to a french company.
Becasue selling product X from FR to DE is sameas buying product X from DE to FR

It will be easier to describe how to reproduce the bug with use cases of values you set, you get and you expect to get.

@eldy eldy added the Discussion Some questions or discussions are opened and wait answers of author or other people to be processed label Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Discussion Some questions or discussions are opened and wait answers of author or other people to be processed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants