Skip to content

Commit

Permalink
[ADD] Implement tax closing over a period and create a voucher to pay…
Browse files Browse the repository at this point in the history
… the tax

FIX Simples nacional calculation
  • Loading branch information
danimaribeiro committed Sep 15, 2018
1 parent 998f319 commit b864be0
Show file tree
Hide file tree
Showing 25 changed files with 621 additions and 247 deletions.
1 change: 0 additions & 1 deletion br_account_close/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
from . import wizard
10 changes: 6 additions & 4 deletions br_account_close/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{ # pylint: disable=C8101,C8103
'name': 'Tax Accounting',
'summary': """Executes a monthly tax accouting
'summary': """Executes a period tax computation
- Maintained by Trustcode""",
'description': """Executes a monthly tax accouting""",
'version': '11.0.1.0.0',
Expand All @@ -17,11 +17,13 @@
'Danimar Ribeiro <danimaribeiro@gmail.com>',
],
'depends': [
'account_voucher', 'br_account'
'br_account_voucher', 'br_account'
],
'data': [
'views/simples.xml',
'wizard/account_close.xml',
'security/ir.model.access.csv',
'views/account_tax.xml',
'views/account_voucher.xml',
'views/account_account.xml',
],
'application': True,
}
136 changes: 107 additions & 29 deletions br_account_close/i18n/pt_BR.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-04-17 18:13+0000\n"
"PO-Revision-Date: 2018-04-17 18:13+0000\n"
"POT-Creation-Date: 2018-09-15 19:04+0000\n"
"PO-Revision-Date: 2018-09-15 19:04+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand All @@ -16,69 +16,147 @@ msgstr ""
"Plural-Forms: \n"

#. module: br_account_close
#: model:ir.ui.view,arch_db:br_account_close.view_account_close_wizard
msgid "Cancel"
msgstr "Cancelar"
#: code:addons/br_account_close/models/account_voucher.py:31
#, python-format
msgid "%s - Period from %s to %s"
msgstr "%s - Período de %s até %s"

#. module: br_account_close
#: model:ir.ui.view,arch_db:br_account_close.view_account_close_wizard
msgid "Compute"
msgstr "Calcular"
#: model:ir.model,name:br_account_close.model_account_account
msgid "Account"
msgstr "Conta Contábil"

#. module: br_account_close
#: model:ir.model.fields,field_description:br_account_close.field_account_close_wizard_create_uid
#: model:ir.model,name:br_account_close.model_account_voucher
msgid "Accounting Voucher"
msgstr ""

#. module: br_account_close
#: model:ir.model.fields,field_description:br_account_close.field_l10n_br_taxation_simples_amount_deduction
msgid "Amount to deduct"
msgstr "Montante a deduzir"

#. module: br_account_close
#: model:ir.model,name:br_account_close.model_res_company
msgid "Companies"
msgstr "Empresas"

#. module: br_account_close
#: model:ir.model.fields,field_description:br_account_close.field_l10n_br_taxation_simples_company_id
msgid "Company"
msgstr "Empresa"

#. module: br_account_close
#: model:ir.model.fields,field_description:br_account_close.field_l10n_br_taxation_simples_create_uid
msgid "Created by"
msgstr "Criado por"

#. module: br_account_close
#: model:ir.model.fields,field_description:br_account_close.field_account_close_wizard_create_date
#: model:ir.model.fields,field_description:br_account_close.field_l10n_br_taxation_simples_create_date
msgid "Created on"
msgstr "Criado em"

#. module: br_account_close
#: model:ir.model.fields,field_description:br_account_close.field_account_close_wizard_display_name
#: model:ir.model.fields,field_description:br_account_close.field_account_account_l10n_br_credit_account_id
msgid "Credit Account"
msgstr "Conta de Crédito"

#. module: br_account_close
#: model:ir.model.fields,field_description:br_account_close.field_l10n_br_taxation_simples_display_name
msgid "Display Name"
msgstr "Nome exibido"
msgstr "Nome a exibir"

#. module: br_account_close
#: model:ir.model.fields,field_description:br_account_close.field_l10n_br_taxation_simples_end_revenue
msgid "End Revenue"
msgstr "Receita Final"

#. module: br_account_close
#: model:ir.model.fields,field_description:br_account_close.field_account_close_wizard_end_date
msgid "End Date"
msgstr "Data Final"
#: model:ir.actions.server,name:br_account_close.ir_cron_generate_recurring_ir_actions_server
#: model:ir.cron,cron_name:br_account_close.ir_cron_generate_recurring
#: model:ir.cron,name:br_account_close.ir_cron_generate_recurring
msgid "Generate Recurring Vouchers"
msgstr "Gerar Recibos recorrentes"

#. module: br_account_close
#: model:ir.model.fields,field_description:br_account_close.field_account_close_wizard_id
#: model:ir.model.fields,field_description:br_account_close.field_l10n_br_taxation_simples_id
msgid "ID"
msgstr "ID"

#. module: br_account_close
#: model:ir.model.fields,field_description:br_account_close.field_account_close_wizard___last_update
#: model:ir.model.fields,help:br_account_close.field_account_voucher_l10n_br_tax_id
msgid "If selected compute the voucher value according to the tax to pay"
msgstr "Se selectionado calcula o valor do recibo de acordo com o imposto"

#. module: br_account_close
#: model:ir.model.fields,field_description:br_account_close.field_l10n_br_taxation_simples___last_update
msgid "Last Modified on"
msgstr "Última modificação em"

#. module: br_account_close
#: model:ir.model.fields,field_description:br_account_close.field_account_close_wizard_write_uid
#: model:ir.model.fields,field_description:br_account_close.field_l10n_br_taxation_simples_write_uid
msgid "Last Updated by"
msgstr "Última atualização por"
msgstr "Última modificação por"

#. module: br_account_close
#: model:ir.model.fields,field_description:br_account_close.field_account_close_wizard_write_date
#: model:ir.model.fields,field_description:br_account_close.field_l10n_br_taxation_simples_write_date
msgid "Last Updated on"
msgstr "Última atualização em"

#. module: br_account_close
#: model:ir.model.fields,field_description:br_account_close.field_account_close_wizard_start_date
msgid "Start Date"
msgstr "Data de Início"
#: model:ir.model.fields,field_description:br_account_close.field_account_voucher_l10n_br_months_compute
msgid "Period (months)"
msgstr "Período (meses)"

#. module: br_account_close
#: model:ir.model.fields,help:br_account_close.field_account_voucher_l10n_br_months_compute
msgid "Period in months to compute"
msgstr "Período em meses para calcular"

#. module: br_account_close
#: model:ir.model.fields,field_description:br_account_close.field_account_tax_l10n_br_revenue_account_ids
#: model:ir.ui.view,arch_db:br_account_close.view_tax_form
msgid "Revenue Accounts"
msgstr "Contas de Receita"

#. module: br_account_close
#: model:ir.ui.view,arch_db:br_account_close.view_tax_form
msgid "Simples Table"
msgstr "Tabela do Simples Nacional"

#. module: br_account_close
#: model:ir.model.fields,field_description:br_account_close.field_l10n_br_taxation_simples_start_revenue
msgid "Start Revenue"
msgstr "Inicio da Receita"

#. module: br_account_close
#: model:ir.model,name:br_account_close.model_account_tax
#: model:ir.model.fields,field_description:br_account_close.field_l10n_br_taxation_simples_amount_tax
#: model:ir.model.fields,field_description:br_account_close.field_l10n_br_taxation_simples_tax_id
msgid "Tax"
msgstr "Imposto"

#. module: br_account_close
#: model:ir.model.fields,field_description:br_account_close.field_account_tax_l10n_br_tax_interval_ids
msgid "Tax Rules"
msgstr "Regras de Imposto"

#. module: br_account_close
#: model:ir.model.fields,field_description:br_account_close.field_account_voucher_l10n_br_tax_id
msgid "Tax to compute"
msgstr "Imposto a calcular"

#. module: br_account_close
#: model:ir.actions.act_window,name:br_account_close.action_account_close_wizard
#: model:ir.ui.menu,name:br_account_close.menu_account_close
#: model:ir.ui.view,arch_db:br_account_close.view_account_close_wizard
msgid "Tax Closure"
msgstr "Fechamento de Impostos"
#: model:ir.model,name:br_account_close.model_account_tax_template
msgid "Templates for Taxes"
msgstr "Modelos de Impostos"

#. module: br_account_close
#: model:ir.model,name:br_account_close.model_account_close_wizard
msgid "account.close.wizard"
msgstr "account.close.wizard"
msgstr ""

#. module: br_account_close
#: model:ir.model,name:br_account_close.model_l10n_br_taxation_simples
msgid "l10n_br.taxation.simples"
msgstr ""
4 changes: 3 additions & 1 deletion br_account_close/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# © 2018 Danimar Ribeiro <danimaribeiro@gmail.com>, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import res_company
from . import simples
from . import account_tax
from . import account_voucher
from . import account_account
12 changes: 12 additions & 0 deletions br_account_close/models/account_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# © 2018 Danimar Ribeiro <danimaribeiro@gmail.com>, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


from odoo import fields, models


class AccountAccount(models.Model):
_inherit = 'account.account'

l10n_br_credit_account_id = fields.Many2one(
'account.account', string="Credit Account")
73 changes: 73 additions & 0 deletions br_account_close/models/account_tax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# © 2018 Danimar Ribeiro <danimaribeiro@gmail.com>, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


from odoo import fields, models


class AccountTaxTemplate(models.Model):
_inherit = 'account.tax.template'

domain = fields.Selection(selection_add=[('simples', 'Simples Nacional')])


class AccountTax(models.Model):
_inherit = 'account.tax'

domain = fields.Selection(selection_add=[('simples', 'Simples Nacional')])
l10n_br_tax_interval_ids = fields.One2many(
'l10n_br.taxation.simples', 'tax_id', string="Tax Rules")
l10n_br_revenue_account_ids = fields.Many2many(
'account.account', string="Revenue Accounts")

def aggregate_tax_to_pay(self, period):
if self.domain == 'simples':
return self._calculate_simples_nacional_tax()
return self._calulate_amount_tax_period(period)

def _calulate_amount_tax_period(self, period):
if not self.account_id:
return 0
acc_ids = [self.account_id.id]
if self.account_id.l10n_br_credit_account_id:
acc_ids += [self.account_id.l10n_br_credit_account_id.id]
self.env.cr.execute(
"select sum(credit-debit) from account_move_line \
where account_id in %s \
and date >= date_trunc('month', current_date - interval %s month)\
and date < date_trunc('month', current_date)",
(tuple(acc_ids), str(period)))
result = self.env.cr.fetchall()
return result and result[0] and result[0][0] or 0.0

# Necessary because is not a matter of sum the taxes over the month
def _calculate_simples_nacional_tax(self):
acc_ids = self.l10n_br_revenue_account_ids.ids
self.env.cr.execute(
"select sum(debit+credit), account_id from account_move_line \
where account_id in %s \
and date >= date_trunc('month',current_date - interval '13' month)\
and date < date_trunc('month',current_date - interval '1' month)\
group by account_id;", (tuple(acc_ids),))

result = self.env.cr.fetchall()
total_revenue = result and result[0] and result[0][0] or 0.0
if total_revenue <= 0:
return 0.0
self.env.cr.execute(
"select sum(debit+credit), account_id from account_move_line \
where account_id in %s \
and date >= date_trunc('month', current_date - interval '1' month)\
and date < date_trunc('month', current_date)\
group by account_id;", (tuple(acc_ids),))

data = self.env.cr.fetchall()
for tax in self.l10n_br_tax_interval_ids:
revenue = sum([x[0] for x in data if x[1] in acc_ids])
if tax.start_revenue <= total_revenue < tax.end_revenue:
# Cálculo do simples Nacional
fee = total_revenue * (tax.amount_tax / 100)
fee = (fee - tax.amount_deduction) / total_revenue

return fee * revenue
return 0.0
44 changes: 44 additions & 0 deletions br_account_close/models/account_voucher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# © 2018 Danimar Ribeiro <danimaribeiro@gmail.com>, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from datetime import date
from calendar import monthrange
from odoo import fields, models, _
from dateutil.relativedelta import relativedelta


class AccountVoucher(models.Model):
_inherit = 'account.voucher'

l10n_br_tax_id = fields.Many2one(
'account.tax', string="Tax to compute",
help="If selected compute the voucher value \
according to the tax to pay")
l10n_br_months_compute = fields.Integer(
string="Period (months)", help="Period in months to compute",
default=1)

def prepare_voucher_values_to_copy(self, vals):
vals = super(AccountVoucher, self).prepare_voucher_values_to_copy(vals)
# Calculate first and last day of the period
go_back = self.l10n_br_months_compute * -1
last_month = date.today() + relativedelta(months=-1)
last_day = monthrange(last_month.year, last_month.month)[1]
last_month = last_month.replace(day=last_day)
start_month = date.today() + relativedelta(months=go_back)
start_month = start_month.replace(day=1)
if self.l10n_br_tax_id:
description = _("%s - Period from %s to %s") % (
self.l10n_br_tax_id.name, start_month, last_month)
vals.update({
'narration': description,
'account_date': last_month
})
return vals

def calculate_amount_voucher_line(self, line):
voucher = line.voucher_id
if voucher.l10n_br_tax_id:
return voucher.l10n_br_tax_id.aggregate_tax_to_pay(
voucher.l10n_br_months_compute or 1)
return super(AccountVoucher, self).calculate_amount_voucher_line(line)
Loading

0 comments on commit b864be0

Please sign in to comment.