feat(view): set price based on product select on first line from purchase.
This commit is contained in:
25
tienda_ilusion/don_confiao/static/js/buy_general.js
Normal file
25
tienda_ilusion/don_confiao/static/js/buy_general.js
Normal file
@@ -0,0 +1,25 @@
|
||||
setPriceListeners();
|
||||
|
||||
function setPriceListeners() {
|
||||
document.querySelectorAll('select[id^="id_saleline_set-"][id$="-product"]').forEach((input) => {
|
||||
console.log('setPriceListenersForeach');
|
||||
console.log(input.id);
|
||||
input.addEventListener('change', (e) => setLinePrice(e));
|
||||
});
|
||||
}
|
||||
|
||||
function setLinePrice(e) {
|
||||
console.log('setLinePrice');
|
||||
let input = e.target;
|
||||
const idLine = input.id.split('-')[1];
|
||||
const productId = input.value;
|
||||
const priceInput = document.getElementById(`id_saleline_set-${idLine}-unit_price`);
|
||||
|
||||
const product = listProducts.find((product) => product.id == productId);
|
||||
if (product) {
|
||||
priceInput.value = product.price_list;
|
||||
} else {
|
||||
priceInput.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user