123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- # -*- coding: utf-8 -*-
- ##############################################################################
- #
- # OpenERP, Open Source Management Solution
- # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU Affero General Public License as
- # published by the Free Software Foundation, either version 3 of the
- # License, or (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU Affero General Public License for more details.
- #
- # You should have received a copy of the GNU Affero General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- #
- ##############################################################################
- 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):
- _name = 'account.invoice'
- _inherit = 'account.invoice'
- _description = 'Add extra data to SET in account invoice'
- 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')
- importacion = fields.Boolean(string='Fact. 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
- def action_invoice_open(self):
- for invoice in self:
- 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())
|