Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10.0 migrate #148

Open
wants to merge 21 commits into
base: 10.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions nfe_mde/README.rst → nfe/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

============================
Manifestação do Destinatário
============================

Implementa a consulta de nfe periodicamente no SEFAZ

Este módulo serve para efetuar download de notas em que são destinada a empresa.
======================
Nota Fiscal Eletrônica
======================

Manifesta a ciência ou desconhecimento da NF-e
Esse módulo implementa as interações de documentos eletrônicos com o SEFAZ.

Com ele é possível transmitir e consultar NF-e, fazer cartas de correção, inutilizar faixas de numeração,
importar documentos eletrônicos a partir de arquivos TXT e XML, consultar MD-e, manifestar ciência ou desconhecimento da
MD-e e importar a NF-e diretamente da MD-e.

Installation
============

This module depends on :
* nfe
* l10n_br_account_product
* barcodes

This modules is part of the odoo-brazil/odoo-brazil-eletronic-documents suite.

Expand Down
2 changes: 2 additions & 0 deletions nfe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
from . import models
from . import wizard
from . import report
from . import service
from . import tests
22 changes: 20 additions & 2 deletions nfe/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,40 @@
Instalando geraldo
sudo pip install geraldo
""",
'external_dependencies': {
'python': [
'pysped'
],
},
'depends': [
'l10n_br_account_product',
'barcodes',
],
'data': [
'data/nfe_attach_email.xml',
'security/ir.model.access.csv',
'wizard/nfe_xml_periodic_export.xml',
'wizard/nfe_invoice_cancel_view.xml',
'wizard/nfe_invoice_cce_view.xml',
'wizard/nfe_invoice_cancel_view.xml',
'account_invoice_workflow.xml',
'wizard/l10n_br_account_invoice_import.xml',
'data/nfe_schedule.xml',
# 'account_invoice_workflow.xml',
'views/l10n_br_account_view.xml',
'views/account_invoice_view.xml',
'views/res_partner_view.xml',
'views/res_company_view.xml',
'views/nfe_mde_view.xml',
'views/account_fiscal_position_view.xml',
'views/nfe_import_view.xml',
'report/report_print_button_view.xml',
'report/report_danfe.xml',
'wizard/wizard_nfe_import_xml_view.xml',
],
'css': [
'static/src/css/nfe_import.css'
],
'demo': [],
'test': [],
'installable': False,
'installable': True,
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<openerp>
<data noupdate="1">
<record id="email_template_nfe" model="email.template">
<record id="email_template_nfe" model="mail.template">
<field name="name">NF-E - Send by Email</field>
<field name="email_from">${(object.user_id.email or object.company_id.email or 'noreply@localhost')|safe}</field>
<field name="subject">${object.company_id.name} NF ${object.document_serie_id.code}/${object.number or 'n/a'}</field>
Expand Down
8 changes: 3 additions & 5 deletions nfe_mde/data/nfe_schedule.xml → nfe/data/nfe_schedule.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" ?>
<openerp>
<data>
<odoo>


<record id="ir_cron_download_nfe_scheduler0" model="ir.cron">
Expand Down Expand Up @@ -55,8 +54,7 @@

<menuitem id="menu_l10n_br_accouunt_periodic_processing_nfe_export"
name="Verificar NFe para download"
parent="nfe_attach.menu_l10n_br_account_processamento_periodico"
parent="nfe.menu_l10n_br_account_processamento_periodico"
action="action_nfe_schedule_download_nfe"/>

</data>
</openerp>
</odoo>
4 changes: 4 additions & 0 deletions nfe/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
from . import l10n_br_account
from . import res_company
from . import res_partner
from . import nfe_schedule
from . import nfe_mde
from . import account_fiscal_position
from . import nfe_import_edit
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
###############################################################################


from openerp import api, fields, models, _
from openerp.exceptions import Warning as UserError, except_orm
from odoo import api, fields, models, _
from odoo.exceptions import Warning as UserError, except_orm

TOO_MANY_FISCAL_POSITIONS_MSG = _(
u'''Fiscal Category {fc.name} ({fc!r}) has multiple Fiscal Positions
Expand Down
130 changes: 118 additions & 12 deletions nfe/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@
import os
import logging
import datetime

from openerp.tools.translate import _
from openerp import models, fields, api
from openerp.exceptions import RedirectWarning

from openerp.addons.nfe.sped.nfe.nfe_factory import NfeFactory
from openerp.addons.nfe.sped.nfe.validator.xml import XMLValidator
from openerp.addons.nfe.sped.nfe.processing.xml import send, cancel
from openerp.addons.nfe.sped.nfe.processing.xml import monta_caminho_nfe
from openerp.addons.nfe.sped.nfe.processing.xml import check_key_nfe
from openerp.addons.nfe.sped.nfe.validator.config_check import \
import base64

from odoo.tools.translate import _
from odoo import models, fields, api
from odoo.exceptions import RedirectWarning

from odoo.addons.nfe.sped.nfe.nfe_factory import NfeFactory
from odoo.addons.nfe.sped.nfe.validator.xml import XMLValidator
from odoo.addons.nfe.sped.nfe.processing.xml import send, cancel
from odoo.addons.nfe.sped.nfe.processing.xml import monta_caminho_nfe
from odoo.addons.nfe.sped.nfe.processing.xml import check_key_nfe
from odoo.addons.nfe.sped.nfe.validator.config_check import \
validate_nfe_configuration, validate_invoice_cancel

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -60,7 +61,112 @@ def attach_file_event(self, seq, att_type, ext):
:param context:
:return:
"""
return False
if seq is None:
seq = 1

for inv in self:
company = inv.company_id
nfe_key = inv.nfe_access_key

if att_type != 'nfe' and att_type is not None:
str_aux = nfe_key + '-%02d-%s.%s' % (seq, att_type, ext)
save_dir = os.path.join(
monta_caminho_nfe(
company,
chave_nfe=nfe_key) +
str_aux)

elif att_type is None and ext == 'pdf':
str_aux = nfe_key + '.%s' % (ext)
save_dir = os.path.join(
monta_caminho_nfe(
company,
chave_nfe=nfe_key) +
str_aux)

elif att_type == 'nfe' and ext == 'xml':
str_aux = nfe_key + '-%s.%s' % (att_type, ext)
save_dir = os.path.join(
monta_caminho_nfe(
company,
chave_nfe=nfe_key) +
str_aux)


try:
file_attc = open(save_dir, 'r')
attc = file_attc.read()

self.env['ir.attachment'].create({
'name': str_aux.format(nfe_key),
'datas': base64.b64encode(attc),
'datas_fname': str_aux.format(nfe_key),
'description': '' or _('No Description'),
'res_model': 'account.invoice',
'res_id': inv.id,
'type': 'binary',
})
except IOError:
pass
else:
file_attc.close()

return True

def action_confirm_invoice(self):
self.nfe_check()
self.action_date_assign()
self.action_number()
self.action_move_create()
self.nfe_export()
return True

def action_invoice_sent(self, cr, uid, ids, context=None):

assert len(ids) == 1, \
'This option should only be used for a single id at a time.'
ir_model_data = self.pool.get('ir.model.data')
attach_obj = self.pool.get('ir.attachment')
attachment_ids = attach_obj.search(
cr, uid, [
('res_model', '=', 'account.invoice'),
('res_id', '=', ids[0])], context=context)
try:
template_id = ir_model_data.get_object_reference(
cr,
uid,
'nfe_attach',
'email_template_nfe')[1]
except ValueError:
template_id = False
try:
compose_form_id = ir_model_data.get_object_reference(
cr,
uid,
'mail',
'email_compose_message_wizard_form')[1]
except ValueError:
compose_form_id = False
ctx = dict(context)
ctx.update({
'default_model': 'account.invoice',
'default_res_id': ids[0],
'default_use_template': bool(template_id),
'default_template_id': template_id,
'default_composition_mode': 'comment',
'mark_invoice_as_sent': True,
'attachment_ids': [(6, 0, attachment_ids)],
})
return {
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'mail.compose.message',
'views': [(compose_form_id, 'form')],
'view_id': compose_form_id,
'target': 'new',
'context': ctx,
}

def _get_nfe_factory(self, nfe_version):
return NfeFactory().get_nfe(nfe_version)
Expand Down
57 changes: 51 additions & 6 deletions nfe/models/l10n_br_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
###############################################################################

import os
import base64
import commands
import datetime
import logging
from openerp import models, fields, api
from openerp.exceptions import RedirectWarning
from openerp.tools.translate import _
from openerp.addons.nfe.sped.nfe.validator.config_check import \
from odoo import models, fields, api
from odoo.exceptions import RedirectWarning
from odoo.tools.translate import _
from odoo.addons.nfe.sped.nfe.validator.config_check import \
validate_nfe_configuration, validate_nfe_invalidate_number
from openerp.addons.nfe.sped.nfe.processing.xml import invalidate
from odoo.addons.nfe.sped.nfe.processing.xml import invalidate, \
monta_caminho_nfe, monta_caminho_inutilizacao

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -57,7 +61,48 @@ def attach_file_event(self, seq, att_type, ext):
:param context:
:return:
"""
return False
if seq is None:
seq = 1
# monta_caminho_inutilizacao
for obj in self:
company = obj.company_id
number_start = obj.number_start
number_end = obj.number_end
number_serie = self.document_serie_id.code

if att_type == 'inu':
save_dir = monta_caminho_inutilizacao(
company,
None,
number_serie,
number_start,
number_end)
comando = 'ls ' + save_dir + \
'*-inu.xml| grep -E "[0-9]{41}-inu.xml"'
if os.system(comando) == 0:
arquivo = commands.getoutput(comando)
key = arquivo[-49:-8]
str_aux = arquivo[-49:]


try:
file_attc = open(arquivo, 'r')
attc = file_attc.read()

self.env['ir.attachment'].create({
'name': str_aux.format(key),
'datas': base64.b64encode(attc),
'datas_fname': str_aux.format(key),
'description': '' or _('No Description'),
'res_model': 'l10n_br_account.invoice.invalid.number',
'res_id': obj.id
})
except IOError:
key = 'erro'
else:
file_attc.close()

return True

@api.multi
def action_draft_done(self):
Expand Down
Loading