Global invoice, get max payment type

This commit is contained in:
Mauricio Baeza 2020-03-03 22:24:00 -06:00
parent 6b4eb36795
commit 82af00fedf
3 changed files with 30 additions and 1 deletions

View File

@ -559,6 +559,7 @@ class Configuracion(BaseModel):
'chk_ticket_edit_cant',
'chk_ticket_total_up',
'chk_ticket_user_show_doc',
'chk_config_invoice_by_ticket',
)
data = (Configuracion
.select()
@ -3823,11 +3824,16 @@ class Facturas(BaseModel):
obj.acuse = result['Acuse'] or ''
self._actualizar_saldo_cliente(self, obj, True)
self._update_inventory(self, obj, True)
# ~ self._uncancel_tickets(self, obj)
else:
obj.error = data['msg']
obj.save()
return data
@utils.run_in_thread
def _uncancel_tickets(self, invoice):
return
def _cancel_signature(self, id):
msg = 'Factura cancelada correctamente'
auth = Emisor.get_auth()
@ -7244,12 +7250,15 @@ class Tickets(BaseModel):
data = {'ok': False, 'msg': msg}
return data
payment_type = cls._get_payment_type(cls, tickets)
emisor = Emisor.select()[0]
data = {}
data['cliente'] = client
data['serie'] = cls._get_serie(cls, user, True)
data['folio'] = cls._get_folio_invoice(cls, data['serie'])
data['forma_pago'] = client.forma_pago.key
# ~ data['forma_pago'] = client.forma_pago.key
data['forma_pago'] = payment_type
data['tipo_cambio'] = 1.00
data['lugar_expedicion'] = emisor.cp_expedicion or emisor.codigo_postal
if client.uso_cfdi is None:
@ -7276,6 +7285,19 @@ class Tickets(BaseModel):
data = {'ok': True, 'msg': msg, 'id': obj.id}
return data
def _get_payment_type(self, ids):
"""Get max of payment type"""
query = (Tickets.select(
Tickets.forma_pago,
fn.Sum(Tickets.subtotal).alias('total'))
.where(Tickets.id.in_(ids))
.group_by(Tickets.forma_pago)
.order_by(SQL('total').desc())
.limit(1)
.scalar()
)
return query
def _update_inventory_if_cancel(self, id):
products = TicketsDetalle.select().where(TicketsDetalle.ticket==id)
for p in products:

View File

@ -122,6 +122,8 @@ var controllers = {
$$('chk_config_tax_locales_truncate').attachEvent('onItemClick', chk_config_item_click)
$$('chk_config_decimales_precios').attachEvent('onItemClick', chk_config_item_click)
$$('chk_config_user_show_doc').attachEvent('onItemClick', chk_config_item_click)
$$('chk_config_invoice_by_ticket').attachEvent('onItemClick', chk_config_item_click)
$$('chk_config_anticipo').attachEvent('onItemClick', chk_config_item_click)
$$('chk_usar_punto_de_venta').attachEvent('onItemClick', chk_config_item_click)

View File

@ -682,6 +682,11 @@ var options_admin_otros = [
{view: 'checkbox', id: 'chk_config_user_show_doc', labelWidth: 0,
labelRight: 'Usuarios pueden ver todos los documentos'},
]},
{cols: [{maxWidth: 15},
{view: 'checkbox', id: 'chk_config_invoice_by_ticket', labelWidth: 0,
labelRight: 'Factura global por ticket'},
{},
]},
{maxHeight: 15},
{cols: [{maxWidth: 15},
{view: 'richselect', id: 'lst_pac', name: 'lst_pac', width: 300,