|
@@ -20,44 +20,158 @@
|
|
##############################################################################
|
|
##############################################################################
|
|
|
|
|
|
from openerp import models, fields, tools, api, _
|
|
from openerp import models, fields, tools, api, _
|
|
|
|
+import json
|
|
|
|
+import base64
|
|
|
|
+import requests
|
|
|
|
+import io
|
|
|
|
+
|
|
|
|
+try:
|
|
|
|
+ import qrcode
|
|
|
|
+except ImportError:
|
|
|
|
+ qrcode = None
|
|
|
|
|
|
class account_invoice(models.Model):
|
|
class account_invoice(models.Model):
|
|
_name = 'account.invoice'
|
|
_name = 'account.invoice'
|
|
_inherit = 'account.invoice'
|
|
_inherit = 'account.invoice'
|
|
_description = 'Add extra data to SET in account invoice'
|
|
_description = 'Add extra data to SET in account invoice'
|
|
|
|
|
|
- cdc = fields.Char('Código de Control (CDC)')
|
|
|
|
- nro_factura = fields.Char(string='Factura Nº', related='number', store = True)
|
|
|
|
- suc = fields.Char('SUC')
|
|
|
|
- sec = fields.Char('Sec')
|
|
|
|
- talonario = fields.Many2one('ruc.documentos.timbrados', string='Talonario')
|
|
|
|
- timbrado = fields.Char(string='Timbrado', related="talonario.name")
|
|
|
|
- fecha_final = fields.Date(string='Vencimiento de Timbrado', related="talonario.fecha_final")
|
|
|
|
- nro_actual = fields.Integer('Nro Actual')
|
|
|
|
|
|
+ cdc = fields.Char(string='Código de Control (CDC)')
|
|
|
|
+ numero_factura = fields.Char(string='Factura Nº', related='number', store = True)
|
|
|
|
+ sucursal = fields.Char(string='Sucursal', compute='_compute_suc_sec', store=True)
|
|
|
|
+ sec = fields.Char('Sec', compute='_compute_suc_sec', store=True)
|
|
|
|
+ nro_actual = fields.Char('Nro Actual', compute='_compute_suc_sec', store=True)
|
|
|
|
+ talonario_id = fields.Many2one('talonario', string='Talonario')
|
|
|
|
+ timbrado_name = fields.Char(related='talonario_id.name', string='Número de timbrado', readonly=True)
|
|
|
|
+ talonario_tipo_documento = fields.Selection(related='talonario_id.tipo_documento', string='Tipo de documento', readonly=True)
|
|
|
|
+ fecha_final = fields.Date(related='talonario_id.fecha_final', string='Fecha de expiración de timbrado', readonly=True)
|
|
no_mostrar_libro_iva = fields.Boolean(string='No visualizar en el libro IVA')
|
|
no_mostrar_libro_iva = fields.Boolean(string='No visualizar en el libro IVA')
|
|
importacion = fields.Boolean(string='Fact. de importación')
|
|
importacion = fields.Boolean(string='Fact. de importación')
|
|
importacion_gasto = fields.Boolean(string='Fact. de gastos de importación')
|
|
importacion_gasto = fields.Boolean(string='Fact. de gastos de importación')
|
|
|
|
+ tipo_emision = fields.Selection([('1','Normal'),('2','Contingencia')],'Tipo de Emisión')
|
|
|
|
+ tipo_transaccion = fields.Selection([('1','Venta de mercadería'),('2','Prestación de servicios'),('3','Mixto (Venta de mercadería y servicios)'),('4','Venta de activo fijo'),('5','Venta de divisas'),('6','Compra de divisas'),('7','Promoción o entrega de muestras'),('8','Donación'),('9','Anticipo'),('10','Compra de productos'),('11','Compra de servicios'),('12','Venta de crédito fiscal'),('13','Muestras médicas (Art. 3 RG 24/2014)')],'Tipo de transacción')
|
|
|
|
+ tipo_impuesto = fields.Selection([('1','Normal'),('2','Contingencia')],'Tipo de impuesto')
|
|
|
|
+ indicador_presencia = fields.Selection([('1','Operación presencial'),('2','Operación electrónica'),('3','Operación telemarketing'),('4','Venta a domicilio'),('5','Operación bancaria'),('6','Operación cíclica'),('7','ver1'),('8','ver2'),('9','Otros')],'Indicador de Presencia')
|
|
|
|
+ descripcion_indi_presencia = fields.Char('Describir Otros')
|
|
|
|
+ # qr_code = fields.Binary('Código QR', compute='_compute_qr_code')
|
|
|
|
+ # texto_qr = fields.Char(invisible=True)
|
|
|
|
+ dEstRes = fields.Char('Estado de respuesta')
|
|
|
|
+ dProtAut = fields.Char('Código de operación')
|
|
|
|
+ dFecProc = fields.Datetime(string='Fecha de respuesta')
|
|
|
|
+ # mje_resultado_ids = fields.One2many('mje.resultado', 'invoice_id', string='Resultados de mensajes')
|
|
|
|
+ operacion_credito = fields.Selection([('1','Normal'),('2','Contingencia')],'Operación Crédito')
|
|
|
|
+
|
|
|
|
+ estado_de = fields.Selection([
|
|
|
|
+ ('noenviado', 'No enviado'),
|
|
|
|
+ ('enviado', 'Enviado'),
|
|
|
|
+ ('aprobado', 'Aprobado'),
|
|
|
|
+ ('rechazado', 'Rechazado'),
|
|
|
|
+ ('cancelado', 'Cancelado')],
|
|
|
|
+ string='Estado DE',
|
|
|
|
+ default='noenviado'
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @api.onchange('talonario_id')
|
|
|
|
+ def _onchange_talonario_id(self):
|
|
|
|
+ if self.talonario_id:
|
|
|
|
+ self.timbrado_name = self.talonario_id.name
|
|
|
|
+ self.talonario_tipo_documento = self.talonario_id.tipo_documento
|
|
|
|
+ self.fecha_final = self.talonario_id.fecha_final
|
|
|
|
+ else:
|
|
|
|
+ self.timbrado_name = False
|
|
|
|
+ self.talonario_tipo_documento = False
|
|
|
|
+ self.fecha_final = False
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @api.depends('number', 'journal_id', 'state')
|
|
|
|
+ def _compute_suc_sec(self):
|
|
|
|
+ for invoice in self:
|
|
|
|
+ if invoice.state == 'cancel' and invoice.type == 'out_invoice':
|
|
|
|
+ invoice.sucursal = ''
|
|
|
|
+ invoice.sec = ''
|
|
|
|
+ invoice.nro_actual = ''
|
|
|
|
+ elif invoice.journal_id.id == 2 and invoice.number and invoice.type == 'out_invoice':
|
|
|
|
+ parts = invoice.number.split('-')
|
|
|
|
+ invoice.sucursal = parts[0] if len(parts) > 0 else ''
|
|
|
|
+ invoice.sec = parts[1] if len(parts) > 1 else ''
|
|
|
|
+ invoice.nro_actual = parts[2] if len(parts) > 2 else ''
|
|
|
|
+ else:
|
|
|
|
+ invoice.sucursal = ''
|
|
|
|
+ invoice.sec = ''
|
|
|
|
+ invoice.nro_actual = ''
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
@api.multi
|
|
@api.multi
|
|
def action_invoice_open(self):
|
|
def action_invoice_open(self):
|
|
- res = super(AccountInvoice, self).action_invoice_open()
|
|
|
|
for invoice in self:
|
|
for invoice in self:
|
|
- if invoice.type == 'out_invoice':
|
|
|
|
- campo_original = invoice.nro_factura.replace("-", "")
|
|
|
|
- campo1 = campo_original[:3]
|
|
|
|
- campo2 = campo_original[4:7]
|
|
|
|
- campo3 = campo_original[7:]
|
|
|
|
- invoice.suc = campo1
|
|
|
|
- invoice.sec = campo2
|
|
|
|
- invoice.nro_actual = campo3
|
|
|
|
- return res
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- # def separar_cadena (self):
|
|
|
|
- # if self.nro_factura:
|
|
|
|
- # longitud = len(self.nro_factura)
|
|
|
|
- # if longitud >= 3:
|
|
|
|
- # self.sec = self.nro_factura[3:6]
|
|
|
|
- # if longitud >= 6:
|
|
|
|
- # self.nro_actual = self.nro_factura[6:]
|
|
|
|
- # self.suc = self.nro_factura[:3]
|
|
|
|
|
|
+ cdc = self.calcular_cdc(invoice)
|
|
|
|
+ invoice.cdc = cdc
|
|
|
|
+
|
|
|
|
+ return super(AccountInvoice, self).action_invoice_open()
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def calcular_cdc(invoice):
|
|
|
|
+ journal_id = invoice.journal_id.code.zfill(2)
|
|
|
|
+ ruc = invoice.partner_id.ruc
|
|
|
|
+ fecha_factura = invoice.date_invoice.strftime("%Y%m%d")
|
|
|
|
+ cdc = journal_id + ruc + fecha_factura
|
|
|
|
+
|
|
|
|
+ return cdc
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ # class AccountInvoiceLine(models.Model):
|
|
|
|
+ # _inherit = 'account.invoice.line'
|
|
|
|
+ #
|
|
|
|
+ # product_id = fields.Many2one('product.product', 'Producto')
|
|
|
|
+ # quantity = fields.Float('Cantidad')
|
|
|
|
+ # price_unit = fields.Float('Precio de Venta')
|
|
|
|
+ # subtotal = fields.Float('Subtotal', compute='_compute_subtotal')
|
|
|
|
+ #
|
|
|
|
+ # @api.depends('quantity', 'price_unit')
|
|
|
|
+ # def _compute_subtotal(self):
|
|
|
|
+ # for line in self:
|
|
|
|
+ # line.subtotal = line.quantity * line.price_unit
|
|
|
|
+
|
|
|
|
+ # class AccountInvoice(models.Model):
|
|
|
|
+ # _inherit = 'account.invoice'
|
|
|
|
+ #
|
|
|
|
+ # qr_code = fields.Binary('Código QR', compute='_compute_qr_code')
|
|
|
|
+ #
|
|
|
|
+ # @api.depends('partner_id', 'number', 'amount_total', 'invoice_line_ids')
|
|
|
|
+ # def _compute_qr_code(self):
|
|
|
|
+ # for invoice in self:
|
|
|
|
+ # if not qrcode:
|
|
|
|
+ # invoice.qr_code = False
|
|
|
|
+ # continue
|
|
|
|
+ #
|
|
|
|
+ # qr_data = {
|
|
|
|
+ # 'ruc_emisor': invoice.company_id.partner_id.vat,
|
|
|
|
+ # 'ruc_receptor': invoice.partner_id.vat,
|
|
|
|
+ # 'tipo_documento': 'FACT',
|
|
|
|
+ # 'numero_documento': invoice.number,
|
|
|
|
+ # 'monto_total': invoice.amount_total,
|
|
|
|
+ # 'lineas_factura': [],
|
|
|
|
+ # }
|
|
|
|
+ #
|
|
|
|
+ # for line in invoice.invoice_line_ids:
|
|
|
|
+ # linea_factura = {
|
|
|
|
+ # 'producto': line.product_id.name,
|
|
|
|
+ # 'cantidad': line.quantity,
|
|
|
|
+ # 'precio_venta': line.price_unit,
|
|
|
|
+ # 'subtotal': line.subtotal,
|
|
|
|
+ # }
|
|
|
|
+ # qr_data['lineas_factura'].append(linea_factura)
|
|
|
|
+ #
|
|
|
|
+ # qr_string = '|'.join(str(value) for value in qr_data.values())
|
|
|
|
+ # qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_M, box_size=10, border=4)
|
|
|
|
+ # qr.add_data(qr_string)
|
|
|
|
+ # qr.make(fit=True)
|
|
|
|
+ # qr_image = qr.make_image(fill_color="black", back_color="white")
|
|
|
|
+ #
|
|
|
|
+ # qr_image_data = io.BytesIO()
|
|
|
|
+ # qr_image.save(qr_image_data, format='PNG')
|
|
|
|
+ # invoice.qr_code = base64.b64encode(qr_image_data.getvalue())
|