summary purchase: generate draft.

This commit is contained in:
Mono Mono 2024-11-02 13:54:09 -05:00
parent 1519b3c8bb
commit b134b88791
3 changed files with 65 additions and 29 deletions

View File

@ -13,17 +13,39 @@
<v-list-item>
<v-list-item-content>
<v-list-item-title>Cliente:</v-list-item-title>
<v-list-item-subtitle>{{ purchase.customer }}</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-list-item>
<v-list-item-content>
<v-list-item-title>Productos:</v-list-item-title>
<v-list-item-subtitle>{{ purchase.saleline_set }}</v-list-item-subtitle>
<v-list-item-subtitle v-if="purchase.customer">{{ purchase.customer.name }}</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-list>
<v-list-item v-for="(line, index) in purchase.set_lines" :key="index">
<v-list-item-content>
<v-list-item-title>Producto:</v-list-item-title>
<v-list-item-subtitle>
<v-row>
<v-col >Nombre:</v-col>
<v-col >{{ line.product.name }}</v-col>
<v-col >Precio:</v-col>
<v-col >{{ currencyFormat(line.unit_price) }}</v-col>
<v-col >Cantidad:</v-col>
<v-col >{{ line.quantity }}</v-col>
<v-col >Cantidad:</v-col>
<v-col >{{ line.quantity }}</v-col>
<v-col >Subtotal:</v-col>
<v-col >{{ currencyFormat(calculateSubtotal(line.price, line.quantity)) }}</v-col>
</v-row>
</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
</v-list>
<v-list>
<v-list-item>
<v-list-item-content>
<v-list-item-title>Total:</v-list-item-title>
<v-list-item-subtitle v-if="purchase.set_lines">{{ currencyFormat(calculateTotal(purchase.set_lines)) }}</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
</v-list>
</v-list>
</v-container>
</template>
<script>
@ -35,9 +57,6 @@
data () {
return {
purchase: {},
customer: {},
lines: [],
products: []
};
},
created() {
@ -45,8 +64,7 @@
},
methods: {
fetchPurchase(purchaseId) {
let baseUrl = '/don_confiao/api';
fetch(`${baseUrl}/sales/${purchaseId}`)
fetch(`/don_confiao/resumen_compra_json/${purchaseId}`)
.then(response => response.json())
.then(data => {
this.purchase = data;
@ -54,15 +72,22 @@
.catch(error => {
console.error(error);
});
/* fetch(`${baseUrl}/customers/${this.purchase.customer}`)
* .then(response => response.json())
* .then(data => {
* this.purchase = data;
* })
* .catch(error => {
* console.error(error);
* }); */
},
currencyFormat(value) {
return new Intl.NumberFormat('es-CO', { style: 'currency', currency: 'COP' }).format(value);
},
calculateSubtotal(price, quantity) {
price = parseFloat(price || 0);
quantity = parseFloat(price || 0);
return price * quantity;
},
calculateTotal(lines) {
let total = 0;
lines.forEach(line => {
total += this.calculateSubtotal(line.price, line.quantity);
});
return total;
}
},
};
</script>

View File

@ -1,6 +1,7 @@
from django.test import TestCase, Client
from ..models import Sale, Product, SaleLine, Customer
class TestSummaryViewPurchase(TestCase):
def setUp(self):
customer = Customer()
@ -22,20 +23,29 @@ class TestSummaryViewPurchase(TestCase):
line = SaleLine()
line.sale = purchase
line.product = product
line.quantity = "2"
line.quantity = "11"
line.unit_price = "72500"
line.save()
self.purchase = purchase
def test_summary_has_customer(self):
response = self.client.get("/don_confiao/resumen_compra/" + str(self.purchase.id))
url = "/don_confiao/resumen_compra/" + str(self.purchase.id)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context["purchase"].customer, self.purchase.customer)
self.assertEqual(
response.context["purchase"].customer,
self.purchase.customer
)
self.assertIn('Alejo Mono', response.content.decode('utf-8'))
def test_json_summary(self):
response = self.client.get(f"/don_confiao/resumen_compra_json/{self.purchase.id}")
url = f"/don_confiao/resumen_compra_json/{self.purchase.id}"
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertIn('Alejo Mono', response.content.decode('utf-8'))
self.assertIn('cafe', response.content.decode('utf-8'))
self.assertIn('72500', response.content.decode('utf-8'))
self.assertIn('quantity', response.content.decode('utf-8'))
self.assertIn('11', response.content.decode('utf-8'))
self.assertIn('date', response.content.decode('utf-8'))
self.assertIn(self.purchase.date, response.content.decode('utf-8'))

View File

@ -137,13 +137,14 @@ def purchase_json_summary(request, id):
'product': {
'id': line.product.id,
'name': line.product.name,
'quantity': line.quantity,
'unit_price': line.unit_price,
'description': line.description,
}
},
'quantity': line.quantity,
'unit_price': line.unit_price,
'description': line.description,
})
to_response = {
'id': purchase.id,
'date': purchase.date,
'customer': {
'id': purchase.customer.id,
'name': purchase.customer.name,