Change vat management for supplier prices#37737
Change vat management for supplier prices#37737SylvainLegrand wants to merge 2 commits intoDolibarr:developfrom
Conversation
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.
There was a problem hiding this comment.
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 (oris_numeric) when deciding whether to format/show the default VAT so that0is 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 printingGETPOST('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 useGETPOSTISSET('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) |
There was a problem hiding this comment.
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").
| $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) |
| $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) |
There was a problem hiding this comment.
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.
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.