| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- # -*- coding: utf-8 -*-
- from odoo import _, api, fields, models
- from odoo.exceptions import UserError, ValidationError
- import logging
- _logger = logging.getLogger(__name__)
- class AccountCfdiXml(models.TransientModel):
- _name = 'account.cfdi.xml'
- _description = 'Importación por XML'
- company_id = fields.Many2one(comodel_name='res.company', string='Compañía', default=lambda self: self.env.company, readonly=True)
- filedata_file = fields.Many2many(comodel_name='ir.attachment', string='Archivos XML')
- filedata_name = fields.Char(string="Nombre de archivo")
- def import_file(self):
- if len(self.filedata_file) > 0:
- attachment_list = []
- for content in self.filedata_file:
- try:
- attachment_data = {
- 'name': content.name,
- 'type': 'binary',
- 'company_id': self.company_id.id,
- 'datas': content.datas,
- 'store_fname': content.name,
- 'mimetype': 'application/xml'
- }
- data_uuid = {
- "xml": attachment_data,
- }
- attachment_list.append(data_uuid)
- except Exception as e:
- _logger.info(e)
- if attachment_list:
- cfdi_ids = self.env['account.cfdi'].create_cfdis(attachment_list)
- if cfdi_ids:
- return {
- "name": _("CFDIs importados"),
- "view_mode": "list,form",
- "res_model": "account.cfdi",
- "type": "ir.actions.act_window",
- "target": "current",
- "domain": [("id", "=", cfdi_ids.ids)]
- }
- else:
- return {
- 'type': 'ir.actions.client',
- 'tag': 'display_notification',
- 'params': {
- 'title': _("No se cargaron nuevos CFDIs al sistema ya que estos ya existen o no pertenecen a la empresa, favor de validar."),
- 'type': 'warning',
- 'sticky': True,
- },
- }
- else:
- raise ValidationError(_('No ha subido ningún archivo XML'))
|