Skip to content

Commit

Permalink
Merge branch '11.0' into 11.0-account_group_melhorias
Browse files Browse the repository at this point in the history
  • Loading branch information
danimaribeiro committed Dec 11, 2018
2 parents c6bf9e0 + e149fb2 commit 7a14ece
Show file tree
Hide file tree
Showing 23 changed files with 293 additions and 159 deletions.
3 changes: 2 additions & 1 deletion br_account_payment/models/payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ def mark_order_line_processed(self, cnab_code, cnab_message,
rejected=False, statement_id=None):
pass

def mark_order_line_paid(self, cnab_code, cnab_message, statement_id=None):
def mark_order_line_paid(self, cnab_code, cnab_message, statement_id=None,
autenticacao=None, protocolo=None):
pass

@api.multi
Expand Down
6 changes: 4 additions & 2 deletions br_cnab/models/payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ def create_receivable_move_and_reconcile(self, order_line):
(counterpart_aml + order_line.move_line_id).reconcile()
return move

def mark_order_line_paid(self, cnab_code, cnab_message, statement_id=None):
def mark_order_line_paid(self, cnab_code, cnab_message, statement_id=None,
autenticacao=None, protocolo=None):
if self.type != 'receivable':
return super(PaymentOrderLine, self).mark_order_line_paid(
cnab_code, cnab_message, statement_id)
cnab_code, cnab_message, statement_id,
autenticacao=autenticacao, protocolo=protocolo)

bank_account_ids = self.mapped('src_bank_account_id')
for account in bank_account_ids:
Expand Down
16 changes: 10 additions & 6 deletions br_payment_cnab/bancos/bradesco.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ def _get_header_lot(self, line, num_lot, lot):
})
return header

def _get_segmento(self, line, lot_sequency, num_lot):
def _get_segmento(self, line, lot_sequency, num_lot, nome_segmento):
segmento = super(Bradesco240, self)._get_segmento(
line, lot_sequency, num_lot)
line, lot_sequency, num_lot, nome_segmento)
ignore = not self.is_doc_or_ted(
line.payment_information_id.payment_type)
if ((nome_segmento == "SegmentoW") and
(not line.payment_information_id.cod_recolhimento_fgts)):
return None
segmento.update({
'tipo_movimento': int(segmento.get('tipo_movimento')),
'codigo_camara_compensacao': self._string_to_num(
Expand All @@ -68,16 +71,17 @@ def _get_segmento(self, line, lot_sequency, num_lot):
'favorecido_cep': self._string_to_num(
str(segmento.get('favorecido_cep'))[:5]),
'finalidade_ted': get_ted_doc_finality(
'bradesco', '01',
segmento.get('finalidade_doc_ted'), ignore),
'bradesco',
segmento.get('finalidade_doc_ted'), '01', ignore),
'finalidade_doc': get_ted_doc_finality(
'bradesco', '02',
segmento.get('finalidade_doc_ted'), ignore),
'bradesco',
segmento.get('finalidade_doc_ted'), '02', ignore),
})
return segmento

def segments_per_operation(self):
segments = super(Bradesco240, self).segments_per_operation()

segments.update({
"41": ["SegmentoA", "SegmentoB"],
"43": ["SegmentoA", "SegmentoB"],
Expand Down
10 changes: 6 additions & 4 deletions br_payment_cnab/bancos/itau.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ def _get_header_lot(self, line, num_lot, lot):
})
return header

def _get_segmento(self, line, lot_sequency, num_lot):
def _get_segmento(self, line, lot_sequency, num_lot, nome_segmento):
segmento = super(Itau240, self)._get_segmento(
line, lot_sequency, num_lot)
line, lot_sequency, num_lot, nome_segmento)

ignore = not self.is_doc_or_ted(
line.payment_information_id.payment_type)
del(segmento['codigo_camara_compensacao'])
segmento.update({
'identificador_fgts': self._string_to_num(
segmento.get('identificador_fgts')),
'tipo_movimento': int(segmento.get('tipo_movimento')),
'favorecido_endereco_rua':
segmento.get('favorecido_endereco_rua')[:30],
Expand All @@ -93,9 +95,9 @@ def _get_segmento(self, line, lot_sequency, num_lot):
segmento.get('valor_real_pagamento')),
'favorecido_banco': int(line.bank_account_id.bank_id.bic),
'finalidade_ted': get_ted_doc_finality(
'itau', '01', segmento.get('finalidade_doc_ted'), ignore),
'itau', segmento.get('finalidade_doc_ted'), '01', ignore),
'finalidade_doc': get_ted_doc_finality(
'itau', '02', segmento.get('finalidade_doc_ted'), ignore),
'itau', segmento.get('finalidade_doc_ted'), '02', ignore),
'codigo_receita_tributo': int(
segmento.get('codigo_receita_tributo') or 0)
})
Expand Down
17 changes: 10 additions & 7 deletions br_payment_cnab/bancos/santander.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ def _get_header_lot(self, line, num_lot, lot):
})
return header

def _get_segmento(self, line, lot_sequency, num_lot):
def _get_segmento(self, line, lot_sequency, num_lot, nome_segmento):
segmento = super(Santander240, self)._get_segmento(
line, lot_sequency, num_lot)
line, lot_sequency, num_lot, nome_segmento)
ignore = not self.is_doc_or_ted(
line.payment_information_id.payment_type)
if ((nome_segmento == "SegmentoW") and
(not line.payment_information_id.cod_recolhimento_fgts)):
return None
segmento.update({
'tipo_identificacao_contribuinte': 2, # CNPJ
'tipo_identificacao_contribuinte_alfa': '2', # CNPJ
Expand Down Expand Up @@ -93,11 +96,11 @@ def _get_segmento(self, line, lot_sequency, num_lot):
'nome_concessionaria':
segmento.get('nome_concessionaria', '')[:30],
'finalidade_ted': get_ted_doc_finality(
'santander', '01',
segmento.get('finalidade_doc_ted'), ignore),
'santander',
segmento.get('finalidade_doc_ted'), '01', ignore),
'finalidade_doc': get_ted_doc_finality(
'santander', '02',
segmento.get('finalidade_doc_ted'), ignore),
'santander',
segmento.get('finalidade_doc_ted'), '02', ignore),
})
return segmento

Expand All @@ -110,7 +113,7 @@ def segments_per_operation(self):
"03": ["SegmentoA", "SegmentoB"],
'30': ["SegmentoJ"],
'31': ["SegmentoJ"],
'11': ["SegmentoO"],
'11': ["SegmentoO", "SegmentoW"],
"17": ["SegmentoN_GPS"],
"16": ["SegmentoN_DarfNormal"],
"18": ["SegmentoN_DarfSimples"],
Expand Down
13 changes: 9 additions & 4 deletions br_payment_cnab/bancos/sicoob.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ def _get_header_lot(self, line, num_lot, lot):
})
return header

def _get_segmento(self, line, lot_sequency, num_lot):
def _get_segmento(self, line, lot_sequency, num_lot, nome_segmento):
segmento = super(Sicoob240, self)._get_segmento(
line, lot_sequency, num_lot)
line, lot_sequency, num_lot, nome_segmento)
ignore = not self.is_doc_or_ted(
line.payment_information_id.payment_type)
if (line.payment_information_id.payment_type == "08"):
segmento.update({'nome_concessionaria': ''})
segmento.update({
'tipo_movimento': int(segmento.get('tipo_movimento')),
'favorecido_nome': segmento.get('favorecido_nome')[:30],
Expand All @@ -72,9 +74,12 @@ def _get_segmento(self, line, lot_sequency, num_lot):
'codigo_camara_compensacao': self._string_to_num(
segmento.get('codigo_camara_compensacao')),
'finalidade_ted': get_ted_doc_finality(
'sicoob', '01', segmento.get('finalidade_doc_ted'), ignore),
'sicoob', segmento.get('finalidade_doc_ted'), '01', ignore),
'finalidade_doc': get_ted_doc_finality(
'sicoob', '02', segmento.get('finalidade_doc_ted'), ignore)
'sicoob', segmento.get('finalidade_doc_ted'), '02', ignore),
'nome_concessionaria': (
'' if line.payment_information_id.payment_type == '10'
else segmento.get('nome_concessionaria'))
})
return segmento

Expand Down
7 changes: 6 additions & 1 deletion br_payment_cnab/models/payment_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def name_get(self):
('03', 'Pagamento de Títulos'),
('04', 'Tributos com código de barras'),
('05', 'GPS - Guia de previdencia Social'),
('06', 'DARF Normal'),
('06', 'DARF Nomal'),
('08', 'FGTS com Código de Barras'),
('09', 'ICMS')],
string="Tipo de Operação")

Expand Down Expand Up @@ -150,6 +151,10 @@ def name_get(self):

codigo_receita = fields.Char('Código da Receita')

cod_recolhimento_fgts = fields.Integer('Código de Recolhimento do FGTS')

identificacao_fgts = fields.Integer('Número de Identificação do FGTS')

tax_identification = fields.Selection(
[('16', 'DARF Normal'),
('18', 'DARF Simples'),
Expand Down
5 changes: 5 additions & 0 deletions br_payment_cnab/models/payment_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class PaymentMode(models.Model):
('04', 'Tributos com código de barras'),
('05', 'GPS - Guia de previdencia Social'),
('06', 'DARF Normal'),
('08', 'FGTS com Código de Barras'),
('09', 'ICMS')],
string="Tipo de Operação")

Expand Down Expand Up @@ -58,6 +59,10 @@ class PaymentMode(models.Model):

numero_referencia = fields.Char('Número de Referência')

identificacao_fgts = fields.Char('Número de Identificação do FGTS')

cod_recolhimento = fields.Integer('Código de Recolhimento do FGTS')

percentual_receita_bruta_acumulada = fields.Char(
string='Percentual de Receita Bruta Acumulada',
help='Percentual decorrente da receita bruta acumulada a ser aplicado\
Expand Down
11 changes: 9 additions & 2 deletions br_payment_cnab/models/payment_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ def get_information_vals(self, payment_mode_id, vals):
'fine_value': vals.get('fine_value'),
'interest_value': vals.get('interest_value'),
'numero_referencia': payment_mode_id.numero_referencia,
'cod_recolhimento_fgts': payment_mode_id.cod_recolhimento,
'identificacao_fgts': payment_mode_id.identificacao_fgts,
'l10n_br_environment': payment_mode_id.l10n_br_environment
}

Expand Down Expand Up @@ -345,10 +347,12 @@ def mark_order_line_processed(self, cnab_code, cnab_message,
})
return statement_id

def mark_order_line_paid(self, cnab_code, cnab_message, statement_id=None):
def mark_order_line_paid(self, cnab_code, cnab_message, statement_id=None,
autenticacao=None, protocolo=None):
if self.filtered(lambda x: x.type != 'payable'):
return super(PaymentOrderLine, self).mark_order_line_paid(
cnab_code, cnab_message, statement_id)
cnab_code, cnab_message, statement_id,
autenticacao=autenticacao, protocolo=protocolo)

bank_account_ids = self.mapped('src_bank_account_id')
for account in bank_account_ids:
Expand All @@ -368,6 +372,9 @@ def mark_order_line_paid(self, cnab_code, cnab_message, statement_id=None):
})
for item in order_lines:
move_id = self.create_move_and_reconcile(item)
item.write({
'autenticacao_pagamento': autenticacao,
'protocolo_pagamento': protocolo})
self.env['l10n_br.payment.statement.line'].create({
'statement_id': statement_id.id,
'date': date.today(),
Expand Down
2 changes: 1 addition & 1 deletion br_payment_cnab/reports/cnab_payment_receipt_report.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<span> Comprovante de pagamento de </span> <span t-field="line.payment_mode_id.payment_type"/>
</div>
</div>
<div class="row" name="account_infos" style="margin-bottom:20px;margin-left:30px;margin-right:90px">
<div class="row" name="account_infos" style="margin-bottom:20px;margin-left:30px;margin-right:30px">
<t t-set="acc" t-value="line.src_bank_account_id"/>
<div class="col-xs-6" style="font-size:20">
<span>Conta: </span> <span t-field="acc.acc_number"/> -
Expand Down
12 changes: 7 additions & 5 deletions br_payment_cnab/serialize/cnab240.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ def _get_header_arq(self):
}
return headerArq

def _get_segmento(self, line, lot_sequency, num_lot):
def _get_segmento(self, line, lot_sequency, num_lot, nome_segmento):
information_id = line.payment_information_id
segmento = {
"identificador_fgts": information_id.identificacao_fgts,
"controle_lote": num_lot,
"sequencial_registro_lote": lot_sequency,
"tipo_movimento": information_id.mov_type,
Expand Down Expand Up @@ -265,10 +266,11 @@ def create_detail(self, operation, event, lot_sequency, num_lot):
if not segments:
raise Exception(
'Pelo menos um segmento por tipo deve ser implementado!')
for segment in segments:
self._cnab_file.add_segment(
segment, self._get_segmento(
event, lot_sequency, num_lot))
for nome_segmento in segments:
vals = self._get_segmento(
event, lot_sequency, num_lot, nome_segmento)
if vals is not None:
self._cnab_file.add_segment(nome_segmento, vals)
lot_sequency += 1
self._cnab_file.get_active_lot().get_active_event(None).close_event()
return lot_sequency
Expand Down
11 changes: 11 additions & 0 deletions br_payment_cnab/tests/test_cnab.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def setUp(self):
self.titulos_payment = self.env['l10n_br.payment.mode']
self.tributo_payment = self.env['l10n_br.payment.mode']
self.gps_payment = self.env['l10n_br.payment.mode']
self.fgts_payment = self.env['l10n_br.payment.mode']
self.darf_payment = self.env['l10n_br.payment.mode']
self.icms_gare_payment = self.env['l10n_br.payment.mode']

Expand Down Expand Up @@ -145,6 +146,16 @@ def setUp(self):
'codigo_receita': '0561', # IRRF - Retido na fonte
'journal_id': journal.id,
})
self.fgts_payment |= self.env['l10n_br.payment.mode'].create({
'name': 'FGTS com Código de barras',
'type': 'payable',
'payment_type': '08',
'service_type': '22',
'codigo_receita': '0181',
'identificacao_fgts': '123456',
'cod_recolhimento': '0181',
'journal_id': journal.id,
})
self.icms_gare_payment |= self.env['l10n_br.payment.mode'].create({
'name': 'ICMS Gare',
'type': 'payable',
Expand Down
8 changes: 5 additions & 3 deletions br_payment_cnab/views/payment_mode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
<page string="Informações Adicionais">
<group>
<group>
<field name="service_type" />
<field name="service_type" attrs="{'invisible': [('payment_type', 'not in', ('01', '02', '03', '04', '05', '06', '07', '09'))]}"/>
<field name="mov_finality" attrs="{'invisible': [('payment_type', 'not in', ('01', '02'))]}"/>
<field name="codigo_receita" attrs="{'invisible': [('payment_type', 'not in', ('04', '05', '06', '07', '08', '09'))]}" />
<field name="numero_referencia" attrs="{'invisible': [('payment_type', 'not in', ('04', '05', '06', '07', '08', '09'))]}" />
<field name="codigo_receita" attrs="{'invisible': [('payment_type', 'not in', ('04', '05', '06', '07', '09', '08'))]}" />
<field name="numero_referencia" attrs="{'invisible': [('payment_type', 'not in', ('04', '05', '06', '07', '09'))]}" />
<field name="percentual_receita_bruta_acumulada" attrs="{'invisible': [('payment_type', '!=', '07')]}" />
<field name="identificacao_fgts" attrs="{'invisible': [('payment_type', '!=', '08')]}" />
<field name="cod_recolhimento" attrs="{'invisible': [('payment_type', '!=', '08')]}" />
</group>
<div>
<h4>Manuais de configuração</h4>
Expand Down
2 changes: 2 additions & 0 deletions br_payment_cnab/views/payment_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
<field name="barcode" />
<field name="cnab_code" />
<field name="cnab_message" />
<field name="autenticacao_pagamento" />
<field name="protocolo_pagamento"/>
</field>
<field name="emission_date" position="after">
<field name="invoice_date"/>
Expand Down
13 changes: 8 additions & 5 deletions br_payment_cnab/wizard/payment_cnab_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,26 @@ def do_import(self, cnab_file):
'ignored': True,
})
continue

protocol = event.protocolo_pagamento or None
autentication = event.autenticacao_pagamento or None
self.select_routing(
payment_line, cnab_code, bank, message, statement)
payment_line, cnab_code, bank, message, statement,
protocolo=protocol, autenticacao=autentication)

action = self.env.ref(
'br_account_payment.action_payment_statement_tree')
return action.read()[0]

def select_routing(self, pay_line, cnab_code, bank, message, statement):
def select_routing(self, pay_line, cnab_code, bank, message,
statement, protocolo=None, autenticacao=None):
if cnab_code == 'BD': # Inclusão OK
pay_line.mark_order_line_processed(
cnab_code, message, statement_id=statement
)
elif cnab_code in ('00', '03'): # Débito
pay_line.mark_order_line_paid(
cnab_code, message, statement_id=statement
)
cnab_code, message, statement_id=statement,
autenticacao=autenticacao, protocolo=protocolo)
else:
pay_line.mark_order_line_processed(
cnab_code, message, rejected=True,
Expand Down
7 changes: 6 additions & 1 deletion br_payment_cnab_voucher/models/account_voucher.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AccountVoucher(models.Model):
('05', 'GPS - Guia de previdencia Social'),
('06', 'DARF Normal'),
('07', 'DARF Simples'),
('08', 'FGTS'),
('08', 'FGTS com Código de Barras'),
('09', 'ICMS')],
string="Tipo de Operação", readonly=True,
states={'draft': [('readonly', False)]})
Expand All @@ -48,6 +48,11 @@ class AccountVoucher(models.Model):
fine_value = fields.Float(
'Fine Value', readonly=True, states={'draft': [('readonly', False)]})

conec_social_fgts = fields.Char(
string='Lacre Conectividade Social', size=16)
conec_social_dv_fgts = fields.Char(
string='Dígito do Lacre CS', size=9)

_sql_constraints = [
('account_voucher_barcode_uniq', 'unique (barcode)',
_('O código de barras deve ser único!'))
Expand Down

0 comments on commit 7a14ece

Please sign in to comment.