summary purchase: generate draft.
This commit is contained in:
		@@ -13,17 +13,39 @@
 | 
				
			|||||||
      <v-list-item>
 | 
					      <v-list-item>
 | 
				
			||||||
        <v-list-item-content>
 | 
					        <v-list-item-content>
 | 
				
			||||||
          <v-list-item-title>Cliente:</v-list-item-title>
 | 
					          <v-list-item-title>Cliente:</v-list-item-title>
 | 
				
			||||||
          <v-list-item-subtitle>{{ purchase.customer }}</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-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-content>
 | 
					        </v-list-item-content>
 | 
				
			||||||
      </v-list-item>
 | 
					      </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-list>
 | 
				
			||||||
 | 
					 | 
				
			||||||
  </v-container>
 | 
					  </v-container>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
<script>
 | 
					<script>
 | 
				
			||||||
@@ -35,9 +57,6 @@
 | 
				
			|||||||
    data () {
 | 
					    data () {
 | 
				
			||||||
      return {
 | 
					      return {
 | 
				
			||||||
        purchase: {},
 | 
					        purchase: {},
 | 
				
			||||||
        customer: {},
 | 
					 | 
				
			||||||
        lines: [],
 | 
					 | 
				
			||||||
        products: []
 | 
					 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    created() {
 | 
					    created() {
 | 
				
			||||||
@@ -45,8 +64,7 @@
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
    methods: {
 | 
					    methods: {
 | 
				
			||||||
      fetchPurchase(purchaseId) {
 | 
					      fetchPurchase(purchaseId) {
 | 
				
			||||||
        let baseUrl = '/don_confiao/api';
 | 
					        fetch(`/don_confiao/resumen_compra_json/${purchaseId}`)
 | 
				
			||||||
        fetch(`${baseUrl}/sales/${purchaseId}`)
 | 
					 | 
				
			||||||
          .then(response => response.json())
 | 
					          .then(response => response.json())
 | 
				
			||||||
          .then(data => {
 | 
					          .then(data => {
 | 
				
			||||||
            this.purchase = data;
 | 
					            this.purchase = data;
 | 
				
			||||||
@@ -54,15 +72,22 @@
 | 
				
			|||||||
          .catch(error => {
 | 
					          .catch(error => {
 | 
				
			||||||
            console.error(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>
 | 
					</script>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
from django.test import TestCase, Client
 | 
					from django.test import TestCase, Client
 | 
				
			||||||
from ..models import Sale, Product, SaleLine, Customer
 | 
					from ..models import Sale, Product, SaleLine, Customer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestSummaryViewPurchase(TestCase):
 | 
					class TestSummaryViewPurchase(TestCase):
 | 
				
			||||||
    def setUp(self):
 | 
					    def setUp(self):
 | 
				
			||||||
        customer = Customer()
 | 
					        customer = Customer()
 | 
				
			||||||
@@ -22,20 +23,29 @@ class TestSummaryViewPurchase(TestCase):
 | 
				
			|||||||
        line = SaleLine()
 | 
					        line = SaleLine()
 | 
				
			||||||
        line.sale = purchase
 | 
					        line.sale = purchase
 | 
				
			||||||
        line.product = product
 | 
					        line.product = product
 | 
				
			||||||
        line.quantity = "2"
 | 
					        line.quantity = "11"
 | 
				
			||||||
        line.unit_price = "72500"
 | 
					        line.unit_price = "72500"
 | 
				
			||||||
        line.save()
 | 
					        line.save()
 | 
				
			||||||
        self.purchase = purchase
 | 
					        self.purchase = purchase
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_summary_has_customer(self):
 | 
					    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.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'))
 | 
					        self.assertIn('Alejo Mono', response.content.decode('utf-8'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_json_summary(self):
 | 
					    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.assertEqual(response.status_code, 200)
 | 
				
			||||||
        self.assertIn('Alejo Mono', response.content.decode('utf-8'))
 | 
					        self.assertIn('Alejo Mono', response.content.decode('utf-8'))
 | 
				
			||||||
        self.assertIn('cafe', response.content.decode('utf-8'))
 | 
					        self.assertIn('cafe', response.content.decode('utf-8'))
 | 
				
			||||||
        self.assertIn('72500', 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'))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -137,13 +137,14 @@ def purchase_json_summary(request, id):
 | 
				
			|||||||
            'product': {
 | 
					            'product': {
 | 
				
			||||||
                'id': line.product.id,
 | 
					                'id': line.product.id,
 | 
				
			||||||
                'name': line.product.name,
 | 
					                'name': line.product.name,
 | 
				
			||||||
                'quantity': line.quantity,
 | 
					            },
 | 
				
			||||||
                'unit_price': line.unit_price,
 | 
					            'quantity': line.quantity,
 | 
				
			||||||
                'description': line.description,
 | 
					            'unit_price': line.unit_price,
 | 
				
			||||||
            }
 | 
					            'description': line.description,
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
    to_response = {
 | 
					    to_response = {
 | 
				
			||||||
        'id': purchase.id,
 | 
					        'id': purchase.id,
 | 
				
			||||||
 | 
					        'date': purchase.date,
 | 
				
			||||||
        'customer': {
 | 
					        'customer': {
 | 
				
			||||||
            'id': purchase.customer.id,
 | 
					            'id': purchase.customer.id,
 | 
				
			||||||
            'name': purchase.customer.name,
 | 
					            'name': purchase.customer.name,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user