forked from elmau/empresa-libre
Buscar facturas por notas
This commit is contained in:
parent
a0e1f83c25
commit
7e73541c96
|
@ -18,6 +18,7 @@
|
|||
|
||||
import base64
|
||||
import collections
|
||||
import datetime
|
||||
import math
|
||||
import smtplib
|
||||
|
||||
|
@ -28,11 +29,13 @@ from email import encoders
|
|||
from email.utils import formatdate
|
||||
from io import BytesIO
|
||||
|
||||
import lxml.etree as ET
|
||||
import requests
|
||||
|
||||
from cryptography.fernet import Fernet
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
import lxml.etree as ET
|
||||
from dateutil import parser
|
||||
|
||||
|
||||
TIMEOUT = 10
|
||||
|
@ -272,3 +275,9 @@ def get_url(url):
|
|||
r = requests.get(url).text
|
||||
return r
|
||||
|
||||
|
||||
def parse_date(value, next_day=False):
|
||||
d = parser.parse(value)
|
||||
if next_day:
|
||||
return d + datetime.timedelta(days=1)
|
||||
return d
|
||||
|
|
|
@ -384,8 +384,10 @@ class StorageEngine(object):
|
|||
def get_tickets(self, values):
|
||||
return main.Tickets.get_by(values)
|
||||
|
||||
def get_invoices(self, values):
|
||||
return main.Facturas.get_(values)
|
||||
def get_invoices(self, filters):
|
||||
if filters.get('by', ''):
|
||||
return main.Facturas.get_by(filters)
|
||||
return main.Facturas.get_(filters)
|
||||
|
||||
def get_preinvoices(self, values):
|
||||
return main.PreFacturas.get_(values)
|
||||
|
|
|
@ -3719,6 +3719,60 @@ class Facturas(BaseModel):
|
|||
obj.save()
|
||||
return data
|
||||
|
||||
def _get_filters(self, values):
|
||||
if 'start' in values:
|
||||
filters = Facturas.fecha.between(
|
||||
utils.parse_date(values['start']),
|
||||
utils.parse_date(values['end'], True)
|
||||
)
|
||||
else:
|
||||
if values['year'] == '-1':
|
||||
fy = (Facturas.fecha.year > 0)
|
||||
else:
|
||||
fy = (Facturas.fecha.year == int(values['year']))
|
||||
if values['month'] == '-1':
|
||||
fm = (Facturas.fecha.month > 0)
|
||||
else:
|
||||
fm = (Facturas.fecha.month == int(values['month']))
|
||||
filters = (fy & fm)
|
||||
|
||||
if 'client' in values:
|
||||
filters &= (Socios.nombre==values['client'])
|
||||
|
||||
return filters
|
||||
|
||||
def _get_by_notes(self, filters):
|
||||
notes = filters['notes']
|
||||
filters = self._get_filters(self, filters)
|
||||
filters &= (Facturas.notas.contains(notes))
|
||||
|
||||
rows = tuple(Facturas.select(
|
||||
Facturas.id,
|
||||
Facturas.serie,
|
||||
Facturas.folio,
|
||||
Facturas.uuid,
|
||||
Facturas.fecha,
|
||||
Facturas.tipo_comprobante,
|
||||
Facturas.estatus,
|
||||
case(Facturas.pagada, (
|
||||
(True, 'Si'),
|
||||
(False, 'No'),
|
||||
)).alias('paid'),
|
||||
Facturas.total,
|
||||
Facturas.moneda.alias('currency'),
|
||||
Facturas.total_mn,
|
||||
Socios.nombre.alias('cliente'))
|
||||
.where(filters)
|
||||
.join(Socios)
|
||||
.switch(Facturas).dicts()
|
||||
)
|
||||
|
||||
return {'ok': True, 'rows': rows}
|
||||
|
||||
@classmethod
|
||||
def get_by(cls, filters):
|
||||
return getattr(cls, f"_get_by_{filters['by']}")(cls, filters)
|
||||
|
||||
@classmethod
|
||||
def filter_years(cls):
|
||||
data = [{'id': -1, 'value': 'Todos'}]
|
||||
|
@ -4387,7 +4441,7 @@ class Facturas(BaseModel):
|
|||
precio_final = valor_unitario - descuento
|
||||
importe = round(cantidad * precio_final, DECIMALES)
|
||||
|
||||
if use_packing:
|
||||
if use_packing and p.cantidad_empaque:
|
||||
product['empaques'] = utils.round_up(
|
||||
cantidad / float(p.cantidad_empaque))
|
||||
|
||||
|
|
|
@ -82,6 +82,9 @@ var invoices_controllers = {
|
|||
$$('txt_folio_custom').attachEvent('onKeyPress', txt_folio_custom_key_press);
|
||||
$$('txt_folio_custom').attachEvent('onBlur', txt_folio_custom_lost_focus);
|
||||
|
||||
$$('search_by').attachEvent('onKeyPress', search_by_key_press)
|
||||
$$('search_by').attachEvent('onItemClick', search_by_click)
|
||||
|
||||
webix.extend($$('grid_invoices'), webix.ProgressBar)
|
||||
|
||||
init_config_invoices()
|
||||
|
@ -2267,3 +2270,53 @@ function txt_folio_custom_lost_focus(prev){
|
|||
validate_folio_exists(prev.getValue())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function get_filters_invoices(){
|
||||
var filters = $$('filter_dates').getValue()
|
||||
filters['year'] = $$('filter_year').getValue()
|
||||
filters['month'] = $$('filter_month').getValue()
|
||||
filters['client'] = $$('grid_invoices').getFilter('cliente').value
|
||||
return filters
|
||||
}
|
||||
|
||||
|
||||
function search_by(value){
|
||||
var filters = get_filters_invoices()
|
||||
filters['by'] = 'notes'
|
||||
filters['notes'] = value
|
||||
|
||||
|
||||
var grid = $$('grid_invoices')
|
||||
grid.showProgress({type: 'icon'})
|
||||
|
||||
webix.ajax().get('/invoices', filters, {
|
||||
error: function(text, data, xhr) {
|
||||
msg_error('Error al consultar')
|
||||
},
|
||||
success: function(text, data, xhr) {
|
||||
var values = data.json();
|
||||
grid.clearAll();
|
||||
if (values.ok){
|
||||
grid.parse(values.rows, 'json');
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
function search_by_key_press(code, e){
|
||||
var value = this.getValue().trim()
|
||||
if(code == 13 && value.length > 3){
|
||||
search_by(value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function search_by_click(){
|
||||
var value = this.getValue().trim()
|
||||
if(value.length > 3){
|
||||
search_by(value)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -234,6 +234,9 @@ var toolbar_invoices_filter = [
|
|||
labelWidth: 50, width: 200, options: months},
|
||||
{view: 'daterangepicker', id: 'filter_dates', label: 'Fechas',
|
||||
labelAlign: 'right', width: 300},
|
||||
{},
|
||||
{view: 'search', id: 'search_by', name: 'search_by', width: 200,
|
||||
placeholder: 'Captura al menos cuatro letras'},
|
||||
]
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue