Skip to content

Commit

Permalink
added views to create register fucking nailed it!
Browse files Browse the repository at this point in the history
  • Loading branch information
cbdavide committed Oct 11, 2017
1 parent cf0a748 commit 615d50e
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 3 deletions.
26 changes: 26 additions & 0 deletions sales/migrations/0010_auto_20171011_1230.py
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,
),
]
10 changes: 10 additions & 0 deletions sales/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ class Register(models.Model):
verbose_name='servicio',
)

is_pay_with_card = models.BooleanField(
default=False,
verbose_name='Fue pago con tarjeta de credito'
)

product_name = models.CharField(
max_length=255,
verbose_name='nombre del producto'
)

@property
def is_entrance(self):
return self.register_type == ENTRANCE_TYPE
Expand Down
1 change: 1 addition & 0 deletions sales/templates/sales/create_expense.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create_expense.html
File renamed without changes.
Empty file added sales/templates/sales/home.html
Empty file.
21 changes: 20 additions & 1 deletion sales/urls.py
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'
),
]
93 changes: 91 additions & 2 deletions sales/views.py
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,
})

0 comments on commit 615d50e

Please sign in to comment.