More complete fix for #29587 for suplier with no vat. Fix also

ref_supplier not propagated.
This commit is contained in:
Laurent Destailleur 2024-05-03 00:30:01 +02:00
parent 5e50b4aa2e
commit 30de8684fd
3 changed files with 28 additions and 20 deletions

View file

@ -3857,6 +3857,7 @@ class Form
'tva_tx_formated' => price($objp->tva_tx, 0, $langs, 1, -1, 2),
'tva_tx' => price2num($objp->tva_tx),
'default_vat_code' => $objp->default_vat_code,
'supplier_ref' => $objp->ref_fourn,
'discount' => $outdiscount,
'type' => $outtype,
'duration_value' => $outdurationvalue,
@ -3896,6 +3897,7 @@ class Form
'tva_tx_formated' => price($objp->tva_tx),
'tva_tx' => price2num($objp->tva_tx),
'default_vat_code' => $objp->default_vat_code,
'supplier_ref' => $objp->ref_fourn,
'discount' => $outdiscount,
'type' => $outtype,
'duration_value' => $outdurationvalue,

View file

@ -162,18 +162,13 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption = '', $minLen
price_ttc: item.price_ttc,
price_unit_ht: item.price_unit_ht,
price_unit_ht_locale: item.price_unit_ht_locale,
';
if (isModEnabled('multicurrency')) {
$script .= '
multicurrency_code: item.multicurrency_code,
multicurrency_unitprice: item.multicurrency_unitprice,
';
}
$script .= '
multicurrency_code: item.multicurrency_code,
multicurrency_unitprice: item.multicurrency_unitprice,
description : item.description,
ref_customer: item.ref_customer,
tva_tx: item.tva_tx,
default_vat_code: item.default_vat_code
default_vat_code: item.default_vat_code,
supplier_ref: item.supplier_ref
}
}));
} else {
@ -187,7 +182,7 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption = '', $minLen
console.log("We will trigger change on input '.$htmlname.' because of the select definition of autocomplete code for input#search_'.$htmlname.'");
console.log("Selected id = "+ui.item.id+" - If this value is null, it means you select a record with key that is null so selection is not effective");
console.log("Propagate before some properties retrieved by ajax into data-xxx properties of #'.$htmlnamejquery.' component");
console.log("Before, we propagate some properties, retrieved by the ajax of the get, into the data-xxx properties of the component #'.$htmlnamejquery.'");
//console.log(ui.item);
// For supplier price and customer when price by quantity is off
@ -200,18 +195,16 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption = '', $minLen
$("#'.$htmlnamejquery.'").attr("data-ref-customer", ui.item.ref_customer);
$("#'.$htmlnamejquery.'").attr("data-tvatx", ui.item.tva_tx);
$("#'.$htmlnamejquery.'").attr("data-default-vat-code", ui.item.default_vat_code);
';
if (isModEnabled('multicurrency')) {
$script .= '
$("#'.$htmlnamejquery.'").attr("data-supplier-ref", ui.item.supplier_ref); // supplier_ref of price
// For multi-currency values
$("#'.$htmlnamejquery.'").attr("data-multicurrency-code", ui.item.multicurrency_code);
$("#'.$htmlnamejquery.'").attr("data-multicurrency-unitprice", ui.item.multicurrency_unitprice);
';
}
if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
$script .= '
// For customer price when PRODUIT_CUSTOMER_PRICES_BY_QTY is on
console.log("PRODUIT_CUSTOMER_PRICES_BY_QTY is on, propagate also prices by quantity into data-pbqxxx properties");
console.log("PRODUIT_CUSTOMER_PRICES_BY_QTY is on, so we propagate also prices by quantity into data-pbqxxx properties");
$("#'.$htmlnamejquery.'").attr("data-pbq", ui.item.pbq);
$("#'.$htmlnamejquery.'").attr("data-pbqup", ui.item.price_ht);
$("#'.$htmlnamejquery.'").attr("data-pbqbase", ui.item.pricebasetype);
@ -221,7 +214,7 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption = '', $minLen
}
$script .= '
// A new value has been selected, we trigger the handlers on #htmlnamejquery
console.log("Trigger changes on #'.$htmlnamejquery.'");
console.log("Now, we trigger changes on #'.$htmlnamejquery.'");
$("#'.$htmlnamejquery.'").val(ui.item.id).trigger("change"); // Select new value
// Complementary actions

View file

@ -1101,14 +1101,21 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
var default_vat_code = $('option:selected', this).attr('data-default-vat-code'); // When select is done from HTML select
if (typeof default_vat_code === 'undefined') { default_vat_code = jQuery('#idprodfournprice').attr('data-default-vat-code');} // When select is done from HTML input with ajax autocomplete
var supplier_ref = $('option:selected', this).attr('data-supplier-ref'); // When select is done from HTML select
if (typeof supplier_ref === 'undefined') { supplier_ref = jQuery('#idprodfournprice').attr('data-supplier-ref'); } // When select is done from HTML input with ajax autocomplete
<?php if (($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier' || $object->element == 'invoice_supplier_rec') && !$seller->tva_assuj) { ?>
if (tva_tx != .0) {
tva_tx = .0;
default_vat_code = null;
}
<?php } ?>
var stringforvatrateselection = tva_tx;
if (typeof default_vat_code != 'undefined' && default_vat_code != null && default_vat_code != '') {
stringforvatrateselection = stringforvatrateselection+' ('+default_vat_code+')';
}
var supplier_ref = $('option:selected', this).attr('data-supplier-ref'); // When select is done from HTML select
if (typeof supplier_ref === 'undefined') { supplier_ref = jQuery('#idprodfournprice').attr('data-supplier-ref');} // When select is done from HTML input with ajax autocomplete
var has_multicurrency_up = false;
<?php
if (isModEnabled('multicurrency') && $object->multicurrency_code != $conf->currency) {
@ -1192,13 +1199,19 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
var default_vat_code = $('option:selected', this).attr('data-default-vat-code'); // When select is done from HTML select
if (typeof default_vat_code === 'undefined') { default_vat_code = jQuery('#idprodfournprice').attr('data-default-vat-code');} // When select is done from HTML input with ajax autocomplete
var supplier_ref = $('option:selected', this).attr('data-supplier-ref'); // When select is done from HTML select
if (typeof supplier_ref === 'undefined') { supplier_ref = jQuery('#idprodfournprice').attr('data-supplier-ref'); } // When select is done from HTML input with ajax autocomplete
var stringforvatrateselection = tva_tx;
if (typeof default_vat_code != 'undefined' && default_vat_code != null && default_vat_code != '') {
stringforvatrateselection = stringforvatrateselection+' ('+default_vat_code+')';
}
console.log("objectline_create.tpl We find data for price : tva_tx = "+tva_tx+", default_vat_code = "+default_vat_code+", stringforvatrateselection="+stringforvatrateselection+" for product id = "+jQuery('#idprodfournprice').val());
console.log("objectline_create.tpl We find data for price : tva_tx = "+tva_tx+", default_vat_code = "+default_vat_code+", supplier_ref = "+supplier_ref+", stringforvatrateselection="+stringforvatrateselection+" for product id = "+jQuery('#idprodfournprice').val());
// Set supplier_ref
$('#fourn_ref').val(supplier_ref);
// Set vat rate if field is an input box
$('#tva_tx').val(tva_tx);
// Set vat rate by selecting the combo