Skip to content

Commit

Permalink
Merge pull request #46 from abgfbr/feature/rpa-contabilidade
Browse files Browse the repository at this point in the history
Feature Contabilização dos holerite de autônomos
  • Loading branch information
hendrixcosta authored Aug 16, 2018
2 parents 9a970bc + aae7408 commit 2981e76
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 17 deletions.
2 changes: 1 addition & 1 deletion l10n_br_hr_payroll/views/hr_payslip_autonomo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@
<field name="arch" type="xml">
<tree string="Recibo de Pagamento a Autônomoa">
<field name="contract_id"/>
<field name="mes_do_ano"/>
<field name="state"/>
<field name="mes_do_ano"/>
<field name="company_id"/>
</tree>
</field>
Expand Down
1 change: 1 addition & 0 deletions l10n_br_hr_payroll_account/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'data/journal_data.xml',
'views/l10n_br_hr_payroll_account_view.xml',
'views/l10n_br_hr_payroll_run_account_view.xml',
'views/l10n_br_hr_payroll_autonomo.xml',
],
'demo': [
],
Expand Down
1 change: 1 addition & 0 deletions l10n_br_hr_payroll_account/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
from . import l10n_br_hr_salary_rule
from . import l10n_br_hr_payroll_account
from . import l10n_br_hr_payroll_run_account
from . import l10n_br_hr_payroll_autonomo
12 changes: 12 additions & 0 deletions l10n_br_hr_payroll_account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ class AccountMove(models.Model):
ondelete='cascade',
)

payslip_autonomo_id = fields.Many2one(
comodel_name="hr.payslip.autonomo",
string="Payslip Autonomo",
ondelete='cascade',
)

payslip_run_id = fields.Many2one(
comodel_name="hr.payslip.run",
string="Payslip Run",
Expand Down Expand Up @@ -42,6 +48,12 @@ class AccountMoveLine(models.Model):
string="Payslip",
)

payslip_autonomo_id = fields.Many2one(
comodel_name="hr.payslip.autonomo",
string="Payslip Autonomo",
ondelete='cascade',
)

payslip_run_id = fields.Many2one(
comodel_name="hr.payslip.run",
string="Payslip Run",
Expand Down
16 changes: 0 additions & 16 deletions l10n_br_hr_payroll_account/models/l10n_br_hr_payroll_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,6 @@ def _buscar_lancamentos(self):
default=_buscar_diario_fopag
)

@api.multi
def _verificar_lancamentos_anteriores(self, tipo_folha, period_id):
for payslip in self:
move_id = self.env['account.move'].search(
[
('name', 'like', NOME_LANCAMENTO[tipo_folha]),
('name', 'like', payslip.contract_id.nome_contrato),
('period_id', '!=', period_id)
],
limit=1
)
if not move_id:
return False
else:
return move_id

@api.multi
def _valor_lancamento_anterior_rubrica(self, move_id, rubrica_id):
for line in move_id.line_id:
Expand Down
164 changes: 164 additions & 0 deletions l10n_br_hr_payroll_account/models/l10n_br_hr_payroll_autonomo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2018 ABGF <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

import time

from openerp import api, models, fields, _
from openerp.exceptions import Warning

NOME_LANCAMENTO = {
'normal': u'Holerite Normal - ',
'rescisao': u'Rescisão - ',
'ferias': u'Férias - ',
'decimo_terceiro': u'Décimo Terceiro - ',
'aviso_previo': u'Aviso Prévio - ',
'provisao_ferias': u'Provisão de Férias - ',
'provisao_decimo_terceiro': u'Provisão de Décimo Terceiro - ',
}


class L10nBrHrPayslipAutonomo(models.Model):
_inherit = 'hr.payslip.autonomo'

move_id = fields.One2many(
comodel_name='account.move',
inverse_name='payslip_autonomo_id',
string='Accounting Entry',
)

move_lines_id = fields.One2many(
comodel_name='account.move.line',
string=u'Lançamentos',
inverse_name='payslip_autonomo_id',
)

journal_id = fields.Many2one(
comodel_name='account.journal',
string=u"Diário",
default=lambda self:
self.env.ref('l10n_br_hr_payroll_account.payroll_account_journal'),
)

@api.multi
def _valor_lancamento_anterior_rubrica(self, move_id, rubrica_id):
for line in move_id.line_id:
if rubrica_id.id == line.id:
return line.debit, line.credit, line.period_id
return 0, 0, 0

@api.multi
def _buscar_contas(self, salary_rule):
if self.tipo_de_folha == "provisao_ferias":
return salary_rule.provisao_ferias_account_debit, salary_rule.\
provisao_ferias_account_credit
elif self.tipo_de_folha == "provisao_decimo_terceiro":
return salary_rule.provisao_13_account_debit, salary_rule.\
provisao_13_account_credit
elif self.tipo_de_folha == "normal":
return salary_rule.holerite_normal_account_debit, salary_rule.\
holerite_normal_account_credit
else:
return False, False

@api.multi
def processar_contabilizacao_payslip(self):
for holerite in self:
move_obj = self.env['account.move']
period_obj = self.env['account.period']
timenow = time.strftime('%Y-%m-%d')
period_id = period_obj.find(holerite.date_to)
contador_lancamentos = 1

if not holerite.journal_id:
raise Warning(
_('Erro de Dados!'),
_('O campo Diário neste holerite não foi definido, '
'por favor escolha o Diário antes de calcular o '
'Lançamento Contábil!')
)

# Exclui os Lançamento Contábeis anteriors
holerite.move_id.unlink()

# Roda as Rubricas e Cria os lançamentos contábeis
for line in holerite.line_ids:
linhas = []
if line.total > 0:
conta_credito, conta_debito = False, False
credito, debito = 0, 0
if holerite.tipo_de_folha == 'normal':
if line.salary_rule_id.holerite_normal_account_debit:
debito = line.total
conta_debito = \
line.salary_rule_id.\
holerite_normal_account_debit
if line.salary_rule_id.holerite_normal_account_credit:
credito = line.total
conta_credito = \
line.salary_rule_id.\
holerite_normal_account_credit


#
# Cria o Lançamento Contábil para esta Rubrica
#
if conta_credito or conta_debito:
move = self.criar_lancamento_contabil(
period_id, holerite, contador_lancamentos
)

# Cria a linha do lançamento contábil para Crédito
if conta_credito:
credit_line = (0, 0, {
'name': line.name,
'date': timenow,
'account_id': conta_credito.id,
'journal_id': holerite.journal_id.id,
'period_id': period_id.id,
'debit': 0,
'credit': credito,
'payslip_autonomo_id': holerite.id,
})
linhas.append(credit_line)

# Cria a linha do lançamento contábil para Débito
if conta_debito:
debit_line = (0, 0, {
'name': line.name,
'date': timenow,
'account_id': conta_debito.id,
'journal_id': holerite.journal_id.id,
'period_id': period_id.id,
'debit': debito,
'credit': 0,
'payslip_autonomo_id': holerite.id,
})
linhas.append(debit_line)

# Fecha e Posta o Lançamento Contábil
move.update({'line_id': linhas})
move_id = move_obj.create(move)
if holerite.journal_id.entry_posted:
move_obj.post(move_id)

# Incrementa o contador para a próxima linha
contador_lancamentos += 1

def criar_lancamento_contabil(self, period_id, slip, contador_lancamento):
name = \
NOME_LANCAMENTO[slip.tipo_de_folha] \
+ str(slip.mes_do_ano) + "/" + str(slip.ano) \
+ " - " + slip.contract_id.nome_contrato + " - " + \
str("%03d" % contador_lancamento)
move = {
'name': name,
'display_name': name,
'narration': name,
'date': slip.date_from,
'ref': slip.number,
'journal_id': slip.journal_id.id,
'period_id': period_id.id,
'payslip_autonomo_id': slip.id,
}
return move
25 changes: 25 additions & 0 deletions l10n_br_hr_payroll_account/views/l10n_br_hr_payroll_autonomo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" ?>
<openerp>
<data>

<record id="view_hr_payslip_autonomo_form" model="ir.ui.view">
<field name="name">hr.payslip.autonomo.form in (l10n_br_hr_payroll_account)</field>
<field name="model">hr.payslip.autonomo</field>
<field name="inherit_id" ref="l10n_br_hr_payroll.hr_payslip_autonomo_form_view"/>
<field name="arch" type="xml">
<xpath expr="//notebook" position="inside">
<page string="Contabilização">
<button type="object" name="processar_contabilizacao_payslip" string="Gerar contabilização"/>
<group>
<field name="journal_id" options="{'no_create': 1}"/>
</group>
<group>
<field name="move_lines_id"/>
</group>
</page>
</xpath>
</field>
</record>

</data>
</openerp>

0 comments on commit 2981e76

Please sign in to comment.