forked from elmau/empresa-libre
Factura de pago, envío por correo
This commit is contained in:
parent
d1b94cab57
commit
e8f27904d9
|
@ -9,6 +9,8 @@ git pull origin master
|
|||
|
||||
cd source/app/models
|
||||
|
||||
python main.py -bk
|
||||
|
||||
python main.py -m
|
||||
```
|
||||
|
||||
|
|
|
@ -5586,6 +5586,53 @@ class CfdiPagos(BaseModel):
|
|||
opt = values.pop('opt')
|
||||
return getattr(cls, '_get_{}'.format(opt))(cls, values)
|
||||
|
||||
def _send(self, values):
|
||||
id = int(values['id'])
|
||||
|
||||
values = Configuracion.get_({'fields': 'correo'})
|
||||
if not values:
|
||||
msg = 'No esta configurado el servidor de correo de salida'
|
||||
return {'ok': False, 'msg': msg}
|
||||
|
||||
obj = CfdiPagos.get(CfdiPagos.id==id)
|
||||
if obj.uuid is None:
|
||||
msg = 'La factura no esta timbrada'
|
||||
return {'ok': False, 'msg': msg}
|
||||
|
||||
to = obj.socio.correo_facturas
|
||||
if not to:
|
||||
msg = 'El cliente no tiene configurado el correo para facturas'
|
||||
return {'ok': False, 'msg': msg}
|
||||
|
||||
files = (self.get_file_pdf(id), self.get_file_xml(id))
|
||||
|
||||
fields = util.make_fields(obj.xml)
|
||||
server = {
|
||||
'servidor': values['correo_servidor'],
|
||||
'puerto': values['correo_puerto'],
|
||||
'ssl': bool(int(values['correo_ssl'])),
|
||||
'usuario': values['correo_usuario'],
|
||||
'contra': values['correo_contra'],
|
||||
}
|
||||
options = {
|
||||
'para': to,
|
||||
'copia': values.get('correo_copia', ''),
|
||||
'confirmar': util.get_bool(values.get('correo_confirmacion', '0')),
|
||||
'asunto': util.make_info_mail(values['correo_asunto'], fields),
|
||||
'mensaje': util.make_info_mail(values['correo_mensaje'], fields),
|
||||
'files': files,
|
||||
}
|
||||
data= {
|
||||
'server': server,
|
||||
'options': options,
|
||||
}
|
||||
result = util.send_mail(data)
|
||||
if not result['ok'] or result['msg']:
|
||||
return {'ok': False, 'msg': result['msg']}
|
||||
|
||||
msg = 'Factura enviada correctamente'
|
||||
return {'ok': True, 'msg': msg}
|
||||
|
||||
|
||||
class PreFacturasImpuestos(BaseModel):
|
||||
factura = ForeignKeyField(PreFacturas)
|
||||
|
|
|
@ -892,6 +892,42 @@ function cmd_pay_stamp_click(){
|
|||
|
||||
|
||||
function cmd_pay_cancel_click(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
function send_cfdi_email(row){
|
||||
if(!row.uuid){
|
||||
msg_error('La factura no esta timbrada')
|
||||
return
|
||||
}
|
||||
|
||||
msg = '¿Estás seguro de enviar por correo esta factura?'
|
||||
webix.confirm({
|
||||
title: 'Enviar Factura',
|
||||
ok: 'Si',
|
||||
cancel: 'No',
|
||||
type: 'confirm-error',
|
||||
text: msg,
|
||||
callback:function(result){
|
||||
if(result){
|
||||
webix.ajax().post('/cfdipay', {'opt': 'send', 'id': row.id}, {
|
||||
error:function(text, data, XmlHttpRequest){
|
||||
msg = 'Ocurrio un error, consulta a soporte técnico'
|
||||
msg_error(msg)
|
||||
},
|
||||
success:function(text, data, XmlHttpRequest){
|
||||
values = data.json();
|
||||
if(values.ok){
|
||||
msg_ok(values.msg)
|
||||
}else{
|
||||
msg_error(values.msg)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
@ -903,7 +939,7 @@ function grid_cfdi_pay_click(id, e, node){
|
|||
}else if(id.column == 'pdf'){
|
||||
window.open('/doc/pdfpago/' + row.id, '_blank')
|
||||
}else if(id.column == 'email'){
|
||||
//~ enviar_correo(row)
|
||||
send_cfdi_email(row)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue