Fix: fallback to numeric VAT rate match when default_vat_code is null (#37830)

* Fix: fallback to numeric VAT rate match when default_vat_code is not set on product

* fix: restore VAT rate assignment for input box case alongside combo fallback

---------

Co-authored-by: Zakaria Boushaba <z.boushaba@vold.africa>
This commit is contained in:
Zakaria Boushaba 2026-04-13 12:25:05 +01:00 committed by GitHub
parent 5d56da3117
commit e87e4eb187
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -943,13 +943,20 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
<?php
} ?>
}
// Set vat rate if field is an input box
$('#tva_tx').val(tva_tx);
// Set vat rate by selecting the combo
//$('#tva_tx option').val(tva_tx); // This is bugged, it replaces the vat key of all options
$('#tva_tx option').removeAttr('selected');
console.log("stringforvatrateselection="+stringforvatrateselection+" -> value of option label for this key="+$('#tva_tx option[value="'+stringforvatrateselection+'"]').val());
$('#tva_tx option[value="'+stringforvatrateselection+'"]').prop('selected', true);
// Set vat rate: handle both input box and combo cases
if ($('#tva_tx option').length) {
// It is a combo: try exact match first (rate + code), fallback to numeric match
if ($('#tva_tx option[value="' + stringforvatrateselection + '"]').length) {
$('#tva_tx').val(stringforvatrateselection);
} else {
$('#tva_tx option').filter(function () {
return parseFloat($(this).val()) === parseFloat(tva_tx);
}).first().prop('selected', true);
}
} else {
// It is an input box
$('#tva_tx').val(tva_tx);
}
<?php
if (getDolGlobalInt('PRODUIT_AUTOFILL_DESC') == 1) {