Skip to content

Commit

Permalink
Merge pull request #559 from kmee/10.0-develop
Browse files Browse the repository at this point in the history
10.0 develop
  • Loading branch information
mileo authored Mar 2, 2018
2 parents 409656e + d3f57ba commit db1d85f
Show file tree
Hide file tree
Showing 28 changed files with 887 additions and 126 deletions.
Binary file added l10n_br_base/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion l10n_br_base/views/l10n_br_base_menus_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<menuitem id="menu_cadastro"
name="Cadastro"
sequence="-100"
web_icon="sped,static/description/icon.png"
web_icon="l10n_br_base,static/description/icon.png"
/>

<menuitem id="menu_cadastro_participante"
Expand Down
File renamed without changes.
82 changes: 71 additions & 11 deletions sped/models/sped_documento.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import logging

from odoo import api, fields, models, tools, _
from odoo.exceptions import ValidationError
from odoo import api, fields, models, tools, _
from odoo.exceptions import ValidationError, UserError
from odoo.addons.sped_imposto.models.sped_calculo_imposto import SpedCalculoImposto

from odoo.addons.l10n_br_base.constante_tributaria import *
Expand All @@ -26,6 +26,7 @@
formata_data
from pybrasil.valor.decimal import Decimal as D
from pybrasil.valor import formata_valor
from pybrasil.template import TemplateBrasil

except (ImportError, IOError) as err:
_logger.debug(err)
Expand Down Expand Up @@ -705,6 +706,16 @@ class SpedDocumento(SpedCalculoImposto, models.Model):
compute='_compute_soma_itens',
store=True,
)
vr_pagamentos = fields.Monetary(
string='Valor Pagamentos',
compute='_compute_soma_itens',
store=True,
)
vr_troco = fields.Monetary(
string='Valor troco',
compute='_compute_soma_itens',
store=True,
)
vr_ibpt = fields.Monetary(
string='Valor IBPT',
compute='_compute_soma_itens',
Expand Down Expand Up @@ -1014,7 +1025,8 @@ def _compute_data_hora_separadas(self):
'item_ids.vr_nf', 'item_ids.vr_fatura',
'item_ids.vr_ibpt',
'item_ids.vr_custo_comercial',
'item_ids.peso_bruto', 'item_ids.peso_liquido')
'item_ids.peso_bruto', 'item_ids.peso_liquido',
'pagamento_ids')
def _compute_soma_itens(self):
CAMPOS_SOMA_ITENS = [
'vr_produtos', 'vr_produtos_tributacao',
Expand All @@ -1036,6 +1048,7 @@ def _compute_soma_itens(self):
'vr_ibpt',
'vr_custo_comercial',
'peso_bruto', 'peso_liquido'

]

for documento in self:
Expand All @@ -1047,6 +1060,17 @@ def _compute_soma_itens(self):
for campo in CAMPOS_SOMA_ITENS:
dados[campo] += getattr(item, campo, D(0))

# Calculando o troco
dados['vr_pagamentos'] = D(0)
dados['vr_troco'] = D(0)
for p in documento.pagamento_ids:
# Diferença entre a soma de todos os meios de pagamento
# empregados e o valor total do documento fiscal
valor = dados.get('vr_fatura') or dados.get('vr_nf') or 0
dados['vr_pagamentos'] += p.valor
dados['vr_troco'] = \
dados['vr_pagamentos'] - valor

documento.update(dados)

@api.depends('item_ids')
Expand Down Expand Up @@ -1277,13 +1301,6 @@ def _onchange_operacao_id(self):
valores['modalidade_frete'] = self.operacao_id.modalidade_frete
valores['infadfisco'] = self.operacao_id.infadfisco

if self.infcomplementar:
valores['infcomplementar'] += (
' ' + self.operacao_id.infcomplementar
)
else:
valores['infcomplementar'] = self.operacao_id.infcomplementar

valores['deduz_retencao'] = self.operacao_id.deduz_retencao
valores['pis_cofins_retido'] = self.operacao_id.pis_cofins_retido
valores['al_pis_retido'] = self.operacao_id.al_pis_retido
Expand Down Expand Up @@ -1419,6 +1436,9 @@ def _check_permite_alteracao(self, operacao='create', dados={},
'message_follower_ids',
'documento_impresso',
]
CAMPOS_PERMITIDOS_CONFIRMACAO = [
'infcomplementar',
]
for documento in self:
if documento.permite_alteracao:
continue
Expand All @@ -1428,6 +1448,10 @@ def _check_permite_alteracao(self, operacao='create', dados={},
# Trata alguns campos que é permitido alterar depois da nota
# autorizada
#
if documento.situacao_nfe == SITUACAO_NFE_A_ENVIAR:
permite_alteracao = True
break

if documento.situacao_nfe == SITUACAO_NFE_AUTORIZADA:
for campo in dados:
if campo in CAMPOS_PERMITIDOS:
Expand Down Expand Up @@ -1455,6 +1479,26 @@ def _check_permite_alteracao(self, operacao='create', dados={},

raise ValidationError(_(mensagem))

def confirma_documento(self):
""" Nunca sobrescreva este método, pois ele esta sendo modificado
pelo sped_queue que não chama o super. Para permtir o envio assincrono
do documento fiscal
:return:
"""
for record in self:
infcomplementar = record.infcomplementar or ''
if record.operacao_id.infcomplementar:
infcomplementar += ' ' + record.operacao_id.infcomplementar
record.infcomplementar = infcomplementar
if record.situacao_nfe == SITUACAO_NFE_EM_DIGITACAO:
record.situacao_nfe = SITUACAO_NFE_A_ENVIAR

for item in record.item_ids.filtered('mensagens_complementares'):
infcomplementar = item.infcomplementar or ''
if item.mensagens_complementares:
infcomplementar += ' ' + item.mensagens_complementares
item.infcomplementar = infcomplementar

def envia_documento(self):
""" Nunca sobrescreva este método, pois ele esta sendo modificado
pelo sped_queue que não chama o super. Para permtir o envio assincrono
Expand All @@ -1465,6 +1509,9 @@ def envia_documento(self):

def _envia_documento(self):
for record in self:
if record.situacao_nfe == SITUACAO_NFE_EM_DIGITACAO:
record.confirma_documento()

if not record.numero:
res = record._onchange_serie()['value']
res['data_hora_emissao'] = fields.Datetime.now()
Expand Down Expand Up @@ -1536,7 +1583,7 @@ def executa_depois_inutilizar(self):
# tarefas de integração necessárias depois de autorizar uma NF-e,
# por exemplo, criar lançamentos financeiros, movimentações de
# estoque etc.
self.ensure_one()
self.ensure_one()
self.gera_operacoes_subsequentes()

def executa_antes_denegar(self):
Expand Down Expand Up @@ -1724,3 +1771,16 @@ def _compute_documentos_subsequentes_gerados(self):
subsequente_id.operacao_realizada
for subsequente_id in documento.documento_subsequente_ids
)

def _renderizar_informacoes_template(
self, dados_infcomplementar, infcomplementar):

try:
template = TemplateBrasil(infcomplementar.encode('utf-8'))
infcomplementar = template.render(
**dados_infcomplementar).decode('utf-8')

return infcomplementar
except Exception as e:
raise UserError(
_(""" Erro ao gerar informação adicional do item"""))
15 changes: 14 additions & 1 deletion sped/models/sped_documento_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from odoo import api, fields, models, _
import odoo.addons.decimal_precision as dp
from odoo.exceptions import ValidationError
from odoo.exceptions import ValidationError, UserError
from odoo.addons.l10n_br_base.constante_tributaria import (
REGIME_TRIBUTARIO,
MODELO_FISCAL,
Expand All @@ -28,6 +28,7 @@

try:
from pybrasil.valor.decimal import Decimal as D
from pybrasil.template import TemplateBrasil

except (ImportError, IOError) as err:
_logger.debug(err)
Expand Down Expand Up @@ -245,3 +246,15 @@ def _compute_readonly(self):

def _set_additional_fields(self, sped_documento_id):
pass

def _renderizar_informacoes_template(
self, dados_infcomplementar, infcomplementar):
try:
template = TemplateBrasil(infcomplementar.encode('utf-8'))
informacao_complementar = template.render(
**dados_infcomplementar).decode('utf-8')

return informacao_complementar
except Exception as e:
raise UserError(
_(""" Erro ao gerar informação adicional do item"""))
10 changes: 4 additions & 6 deletions sped/models/sped_documento_pagamento.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class SpedDocumentoPagamento(SpedBase, models.Model):
valor = fields.Monetary(
string='Valor',
)
# Deprecado, utilizar o campo vr_troco do sped.documento
troco = fields.Monetary(
string='Troco',
)
Expand Down Expand Up @@ -104,14 +105,11 @@ def _onchange_condicao_pagamento_id(self):
return res

valor = D(self.valor or 0)
troco = valor - D(self.env.context.get('default_valor', 0))
if troco < 0:
troco = 0

duplicata_ids = self.condicao_pagamento_id.gera_parcela_ids(valor,
self.documento_id.data_emissao)
duplicata_ids = self.condicao_pagamento_id.gera_parcela_ids(
valor, self.documento_id.data_emissao
)
valores['duplicata_ids'] = duplicata_ids
valores['troco'] = troco
valores['forma_pagamento'] = self.condicao_pagamento_id.forma_pagamento
valores['bandeira_cartao'] = self.condicao_pagamento_id.bandeira_cartao
valores['integracao_cartao'] = \
Expand Down
Binary file added sped/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions sped/views/sped_documento_base_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@
<field name="vr_seguro" colspan="2" string="Seguro" />
<newline />
<field name="vr_outras" colspan="2" string="Outras" />
<newline />
<field name="vr_pagamentos" colspan="2"/>
<field name="vr_desconto" colspan="2" string="Desconto" />
<newline />
<field name="vr_troco" colspan="2"/>
<field name="vr_operacao" colspan="2" string="Operação" />
</group>
</group>
Expand Down
4 changes: 0 additions & 4 deletions sped/views/sped_documento_pagamento_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
<group>
<field name="valor" required="1"/>
</group>
<group>
<field name="troco"/>
</group>
<group colspan="4" col="4" name="condicao_pagamento">
<field name="condicao_pagamento_id" context="{'valor': valor}" colspan="4"/>
</group>
Expand Down Expand Up @@ -53,7 +50,6 @@
<field name="sequence" widget="handle"/>
<field name="condicao_pagamento_id" />
<field name="valor" sum="valor" />
<field name="troco" sum="troco" />
</tree>
</field>
</record>
Expand Down
1 change: 1 addition & 0 deletions sped_cfe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
#

from . import models
from . import report
3 changes: 3 additions & 0 deletions sped_cfe/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
'category': u'Fiscal',
'depends': [
'sped_nfe',
'report_py3o',
],
'installable': True,
'application': False,
'license': 'AGPL-3',
'data': [
'report/cfe_report.xml',
'wizard/sped_documento_pagamento.xml',
'security/ir.model.access.csv',
'views/pdv_config.xml',
Expand All @@ -26,6 +28,7 @@
# 'views/web_asset_backend_template.xml',
'views/sped_documento_pagamento_view.xml',
'views/sped_participante_administradora_cartao_view.xml',
'views/inherited_sped_empresa_view.xml',
],
'qweb': [
# 'static/src/xml/*.xml',
Expand Down
1 change: 1 addition & 0 deletions sped_cfe/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
from . import pdv_impressora_config
from . import inherited_res_users
from . import inherited_sped_participante
from . import inherited_sped_empresa
Loading

0 comments on commit db1d85f

Please sign in to comment.