Permalink
Browse files

ajustes do orçamento

  • Loading branch information...
1 parent 12aa9ad commit 252b5a5e6532a7fafa69f62924f997ac46cfe2e3 @wpjunior committed Feb 12, 2014
View
Binary file not shown.
View
@@ -2,10 +2,59 @@
import locale
locale.setlocale(locale.LC_ALL, 'pt_BR.utf8')
from django.db import models
-
from MCD.produto.models import Produto
+class Orcamento(models.Model):
+ cliente = models.CharField(
+ verbose_name="Cliente",
+ max_length=250)
+
+ telefone = models.CharField(
+ verbose_name="Telefone",
+ max_length=20,
+ blank=True, null=True)
+
+ endr = models.CharField(
+ verbose_name=u"Endereço",
+ max_length=300,
+ blank=True, null=True)
+
+ condicao_pagto = models.CharField(
+ verbose_name="Condição pagto",
+ max_length=1,
+ default='v',
+ choices=(
+ ('v', "à vista"),
+ ('p', "a prazo"),
+ ('c', "cartão"))
+ )
+
+ data = models.DateTimeField(auto_now=True)
+
+ def get_absolute_url(self):
+ return '/orcamento/%d/' % self.id
+
+ def items(self, *args, **kwargs):
+ return Item.objects.filter(
+ orcamento=self).order_by('-pk')
+
+ def valor_total(self, *args, **kwargs):
+ valor_total = self.items().aggregate(models.Sum(
+ 'valor_total')).get('valor_total__sum', 0)
+
+ if valor_total:
+ if self.condicao_pagto == 'c':
+ valor_total = valor_total * 1.04
+
+ return locale.format(
+ '%0.2f', valor_total, 1)
+
+
class Item(models.Model):
+ orcamento = models.ForeignKey(
+ Orcamento,
+ verbose_name=u"Orçamento")
+
produto = models.ForeignKey(
Produto,
verbose_name="Produto")
View
@@ -6,6 +6,7 @@
from django.http import HttpResponse
from django.template.loader import get_template
from django.template import Context
+
import ho.pisa as pisa
try:
@@ -62,10 +62,6 @@ $(document).ready(function () {
e.preventDefault();
var data = {
- cliente: $('#id_cliente').val(),
- telefone: $('#id_telefone').val(),
- endr: $('#id_endr').val(),
- cond_pagto: $('#id_cond_pagto').val(),
cmd: 'print_orcamento'
}
@@ -15,7 +15,7 @@
{% block content %}
<div class="page-header">
- <h3>Novo Orçamento</h3>
+ <h3>Orçamento / Pedido</h3>
</div>
<div class="well">
@@ -59,24 +59,20 @@
<div id="form" class="pull-right">
<div class="pull-left">
<label>Cliente</label>
- <input id="id_cliente" type="text" />
+ <input id="id_cliente" type="text" value="{{ object.cliente }}" disabled />
</div>
<div class="pull-left" style="padding-left: 10px">
<label>Telefone</label>
- <input id="id_telefone" type="text" class="input-medium" />
+ <input id="id_telefone" type="text" class="input-medium" value="{{ object.telefone }}" disabled />
</div>
<br clear="all"/>
<div class="pull-left">
<label>Endereço</label>
- <input id="id_endr" type="text" />
+ <input id="id_endr" type="text" value="{{ object.endr }}" disabled />
</div>
<div class="pull-left" style="padding-left: 10px">
<label>Condições pagto</label>
- <select id="id_cond_pagto" class="input-small">
- <option value="v">Á Vista</option>
- <option value="p">A Prazo</option>
- <option value="c">Cartão</option>
- </select>
+ <input id="id_telefone" type="text" class="input-medium" value="{{ object.get_condicao_pagto_display }}" disabled />
</div>
</div>
<br clear="all"/>
@@ -0,0 +1,21 @@
+{% extends "base.html" %}
+
+{% block content %}
+<div class="page-header">
+ <h3>
+ {% if object %}Editando{% else %}Adicionando{% endif %} orçamento
+ <small>* são obrigatórios</small>
+ </h3>
+</div>
+
+<form action="." method="POST">
+ {% include "form_snippet.html" %}
+
+ <p class="btn-group">
+ <button type="button" class="btn" onclick="history.go(-1)">
+ Voltar
+ </button>
+ <input type="submit" value="Salvar" class="btn btn-primary"></input>
+ </p>
+</form>
+{% endblock %}
@@ -0,0 +1,52 @@
+{% extends "base.html" %}
+{% block title %}Orçamentos{% endblock %}
+{% block header %}
+<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.dataTables.js"></script>
+<script type="text/javascript" src="{{ STATIC_URL }}js/lethus.bootstrapListBuilder.js"></script>
+<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/lethus.bootstrapListBuilder.css" />
+
+<script type="text/javascript">
+$(document).ready( function (e) {
+ $("#list table").listbuilder({iDisplayLength: 100});
+});
+</script>
+
+
+{% endblock %}
+{% block content %}
+<div class="page-header">
+ <h3>Gerenciando orçamentos</h3>
+</div>
+
+<div id="toolbar" class="btn-group">
+ <a id="add-btn" class="btn" href="/orcamento/add/">
+ <i class="icon-plus"></i> Adicionar
+ </a>
+ <a id="edit-btn" class="btn alone-action dblclick" href="/orcamento/update/%d/">
+ <i class="icon-pencil"></i> Editar
+ </a>
+ <a id="delete-btn" class="alone-action btn" href="/orcamento/%d/">
+ <i class="icon-pencil"></i> Produtos
+ </a>
+
+ <a id="edit-btn" class="btn alone-action" href="/orcamento/%d/?cmd=print_orcamento">
+ <i class="icon-print"></i> Imprimir
+ </a>
+</div>
+
+<div id="list">
+ <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered">
+ <thead>
+ <tr>
+ <th scope="col">ID</th>
+ <th scope="col">Cliente</th>
+ <th scope="col">Data</th>
+ <th scope="col">Valor</th>
+ </tr>
+ </thead>
+ <tbody class="ui-corner-all">
+ </tbody>
+ </table>
+</div>
+
+{% endblock %}
@@ -40,35 +40,25 @@ <h1 style="padding: 0px; border: 0px;">DUTRA Materias para construção</h1>
<tbody>
<tr>
<td style="width: 110px;">Cliente</td>
- <td>{{ cliente }}</td>
+ <td>{{ object.cliente }}</td>
<td style="width: 90px;">Tel.</td>
- <td style="width: 150px;">{{ telefone }}</td>
+ <td style="width: 150px;">{{ object.telefone }}</td>
</tr>
<tr>
<td style="width: 110px;">Endereço</td>
- <td colspan="3">{{ endr }}</td>
+ <td colspan="3">{{ object.endr }}</td>
</tr>
<tr>
<td style="width: 110px;">Condições pgto.</td>
<td colspan="3">
- {% if cond_pagto == 'v' %}
- Á vista
- {% endif %}
-
- {% if cond_pagto == 'p' %}
- Á prazo
- {% endif %}
-
- {% if cond_pagto == 'c' %}
- Cartão
- {% endif %}
+ {{ object.get_condicao_pagto_display }}
</td>
</tr>
<tr>
<td>Vendedor</td>
<td>&nbsp</td>
<td style="width: 110px;">Data</td>
- <td>{% now "d/m/Y" %}</td>
+ <td>{{ object.data|date:"SHORT_DATE_FORMAT" }}</td>
</tr>
</tbody>
</table>
@@ -86,21 +76,21 @@ <h1 style="padding: 0px; border: 0px;">DUTRA Materias para construção</h1>
</tr>
</thead>
<tbody>
- {% for item in items %}
+ {% for item in object.items %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ item.produto.desc }}</td>
<td>{% firstof item.produto.marca "-" %}</td>
<td>{{ item.qtde }}</td >
<td>
- {% if cond_pagto == "c" %}
+ {% if object.condicao_pagto == "c" %}
{{ item.valor_item_cartao_display }}
{% else %}
{{ item.valor_item_display }}
{% endif %}
</td>
<td>
- {% if cond_pagto == "c" %}
+ {% if object.condicao_pagto == "c" %}
{{ item.valor_total_cartao_display }}
{% else %}
{{ item.valor_total_display }}
@@ -114,10 +104,10 @@ <h1 style="padding: 0px; border: 0px;">DUTRA Materias para construção</h1>
</tr>
{% endfor %}
</tbody>
- {% if items %}
+ {% if object.items %}
<tfoot>
<th colspan="5">Valor total</th>
- <td>{{ valor_total }}</td>
+ <td>{{ object.valor_total }}</td>
</tfoot>
{% endif %}
</table>
@@ -13,7 +13,7 @@
</tr>
</thead>
<tbody>
- {% for item in items %}
+ {% for item in object.items %}
<tr rel="{{ item.id }}">
<td>{{ forloop.counter }}</td>
<td>{{ item.produto.desc }}</td>
@@ -46,11 +46,11 @@
</tr>
{% endfor %}
</tbody>
- {% if items %}
+ {% if object.items %}
<tfoot>
<th colspan="7">Valor total</th>
<td>
- {{ valor_total }}
+ {{ object.valor_total }}
</td>
</tfoot>
{% endif %}
Oops, something went wrong.

0 comments on commit 252b5a5

Please sign in to comment.