-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added views to create register fucking nailed it!
- Loading branch information
Showing
7 changed files
with
148 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.6 on 2017-10-11 12:30 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('sales', '0009_auto_20171009_1210'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='register', | ||
name='is_pay_with_card', | ||
field=models.BooleanField(default=False, verbose_name='Fue pago con tarjeta de credito'), | ||
), | ||
migrations.AddField( | ||
model_name='register', | ||
name='product_name', | ||
field=models.CharField(default='nombre jeje', max_length=255, verbose_name='nombre del producto'), | ||
preserve_default=False, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
create_expense.html |
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,25 @@ | ||
from django.conf.urls import url | ||
from django.contrib import admin | ||
from django.views.generic.base import TemplateView | ||
from .views import CreateSale | ||
from .views import CreateExpense | ||
|
||
urlpatterns = [ | ||
# url(r'home^/$', SaleCreateView.as_view(), name='sale'), | ||
url( | ||
r'venta/', | ||
CreateSale.as_view(), | ||
name='create_sale' | ||
), | ||
|
||
url( | ||
r'gasto/', | ||
CreateExpense.as_view(), | ||
name='create_expense' | ||
), | ||
|
||
url( | ||
r'inicio/', | ||
TemplateView.as_view(template_name='sales/home'), | ||
name='home' | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,92 @@ | ||
from django.views.generic.edit import CreateView | ||
from django.http import JsonResponse | ||
from django.views.generic.list import ListView | ||
from django.core.urlresolvers import reverse_lazy | ||
from django.views.generic.base import TemplateView | ||
from django.views.generic.base import View | ||
|
||
from .models import * | ||
from .data import EXPENSE_TYPE | ||
from .data import ENTRANCE_TYPE | ||
|
||
|
||
class CreateSale(TemplateView): | ||
template_name = 'sales/create_sale.html' | ||
|
||
def post(self, *args, **kwargs): | ||
data = self.request.POST | ||
|
||
owner_document = data.get('owner_document') | ||
owner = Employee.objects.filter(document=owner_document).first() | ||
if not owner: | ||
return JsonResponse({ | ||
'ok': False, | ||
'msg': 'No existe un empleado registado con esta cédula', | ||
}) | ||
|
||
client_document = data.get('client_document') | ||
client = None | ||
if client_document: | ||
client = Client.objects.get(document=owner_document) | ||
|
||
description = data.get('description') | ||
value = data.get('value') | ||
|
||
# TODO: validar si llega bien el dato | ||
is_with_card = data.get('is_card') | ||
|
||
|
||
product_name = data.get('el_name') | ||
|
||
|
||
Register.objects.Create( | ||
owner=owner, | ||
client=client, | ||
description=description, | ||
value=value, | ||
register_type=ENTRANCE_TYPE, | ||
is_pay_with_card=is_with_card, | ||
product_name=product_name, | ||
) | ||
|
||
return JsonResponse({'ok': True}) | ||
|
||
|
||
class CreateExpense(TemplateView): | ||
template_name = 'sales/create_expense.html' | ||
|
||
def post(self, *args, **kwargs): | ||
data = self.request.POST | ||
|
||
owner_document = data.get('owner_document') | ||
owner = Employee.objects.filter(document=owner_document).first() | ||
if not owner: | ||
return JsonResponse({ | ||
'ok': False, | ||
'msg': 'No existe un empleado registado con esta cédula', | ||
}) | ||
|
||
description = data.get('description') | ||
value = data.get('value') | ||
|
||
Register.objects.Create( | ||
owner=owner, | ||
description=description, | ||
value=value, | ||
register_type=EXPENSE_TYPE, | ||
) | ||
|
||
|
||
class ProductDataJSONView(View): | ||
def get(self, request, *args, **kwargs): | ||
product_id = request.GET.get('code') | ||
product = Product.objects.filter(id=product_id).first() | ||
if not product: | ||
return JsonResponse({ | ||
'ok': False, | ||
'msg': 'Producto no encontrado', | ||
}) | ||
|
||
return JsonResponse({ | ||
'name': product.name, | ||
'price': product.price, | ||
'amount': product.amount, | ||
}) |