feat(view): set price based on product select on first line from purchase.
This commit is contained in:
		@@ -43,6 +43,7 @@ class Product(models.Model):
 | 
				
			|||||||
        all_products = cls.objects.all()
 | 
					        all_products = cls.objects.all()
 | 
				
			||||||
        for product in all_products:
 | 
					        for product in all_products:
 | 
				
			||||||
            rproduct = {
 | 
					            rproduct = {
 | 
				
			||||||
 | 
					                "id": product.id,
 | 
				
			||||||
                "name": product.name,
 | 
					                "name": product.name,
 | 
				
			||||||
                "price_list": product.price,
 | 
					                "price_list": product.price,
 | 
				
			||||||
                "uom": product.measuring_unit,
 | 
					                "uom": product.measuring_unit,
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										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 = '';
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -32,6 +32,7 @@
 | 
				
			|||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script src="https://cdn.tailwindcss.com/"></script>
 | 
					<script src="https://cdn.tailwindcss.com/"></script>
 | 
				
			||||||
 | 
					<script src="{% static 'js/buy_general.js' %}"></script>
 | 
				
			||||||
<script src="{% static 'js/add_line.js' %}"></script>
 | 
					<script src="{% static 'js/add_line.js' %}"></script>
 | 
				
			||||||
<script src="{% static 'js/sale_summary.js' %}"></script>
 | 
					<script src="{% static 'js/sale_summary.js' %}"></script>
 | 
				
			||||||
<script src="{% static 'js/calculate_subtotal_line.js' %}"></script>
 | 
					<script src="{% static 'js/calculate_subtotal_line.js' %}"></script>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user