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

[14.0][ADD] l10n_br_account_withholding: add new module and extract/refactor features from l10n_br_account #3005

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion l10n_br_account/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Brazilian Localization Account
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c220a94f15382b53d8e28cc1df5904ea3658173a752127e2d59ba4e6834f218f
!! source digest: sha256:5fcbfbac6b08faeb2d2d9b964598e935db50e27b9372aa82b2422d02e434c4e8
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
2 changes: 1 addition & 1 deletion l10n_br_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "AGPL-3",
"author": "Akretion, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-brazil",
"version": "14.0.10.5.0",
"version": "14.0.10.6.0",
"development_status": "Beta",
"maintainers": ["renatonlima", "rvalyi"],
"depends": [
Expand Down
65 changes: 0 additions & 65 deletions l10n_br_account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (C) 2020 - TODAY Luis Felipe Mileo - KMEE
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from dateutil.relativedelta import relativedelta

from odoo import _, api, fields, models
from odoo.exceptions import UserError
Expand Down Expand Up @@ -592,33 +591,6 @@ def _reverse_moves(self, default_values_list=None, cancel=False):

return new_moves

def _prepare_wh_invoice(self, move_line, fiscal_group):
wh_date_invoice = move_line.move_id.date
wh_due_invoice = wh_date_invoice.replace(day=fiscal_group.wh_due_day)
values = {
"partner_id": fiscal_group.partner_id.id,
"date": wh_date_invoice,
"date_due": wh_due_invoice + relativedelta(months=1),
"type": "in_invoice",
"account_id": fiscal_group.partner_id.property_account_payable_id.id,
"journal_id": move_line.journal_id.id,
"origin": move_line.move_id.name,
}
return values

def _prepare_wh_invoice_line(self, invoice, move_line):
values = {
"name": move_line.name,
"quantity": move_line.quantity,
"uom_id": move_line.product_uom_id,
"price_unit": abs(move_line.balance),
"move_id": invoice.id,
"account_id": move_line.account_id.id,
"wh_move_line_id": move_line.id,
"account_analytic_id": move_line.analytic_account_id.id,
}
return values

def _finalize_invoices(self, invoices):
for invoice in invoices:
invoice.compute_taxes()
Expand All @@ -627,40 +599,6 @@ def _finalize_invoices(self, invoices):
line._set_additional_fields(invoice)
invoice._onchange_cash_rounding()

def create_wh_invoices(self):
for move in self:
for line in move.line_ids.filtered(lambda line: line.tax_line_id):
# Create Wh Invoice only for supplier invoice
if line.move_id and line.move_id.type != "in_invoice":
continue

account_tax_group = line.tax_line_id.tax_group_id
if account_tax_group and account_tax_group.fiscal_tax_group_id:
fiscal_group = account_tax_group.fiscal_tax_group_id
if fiscal_group.tax_withholding:
invoice = self.env["account.move"].create(
self._prepare_wh_invoice(line, fiscal_group)
)

self.env["account.move.line"].create(
self._prepare_wh_invoice_line(invoice, line)
)

self._finalize_invoices(invoice)
invoice.action_post()

def _withholding_validate(self):
for m in self:
invoices = (
self.env["account.move.line"]
.search([("wh_move_line_id", "in", m.mapped("line_ids").ids)])
.mapped("move_id")
)
invoices.filtered(lambda i: i.state == "open").button_cancel()
invoices.filtered(lambda i: i.state == "cancel").button_draft()
invoices.invalidate_cache()
invoices.filtered(lambda i: i.state == "draft").unlink()

def post(self, invoice=False):
# TODO FIXME migrate: no more invoice keyword
result = super().post()
Expand All @@ -677,9 +615,6 @@ def post(self, invoice=False):
def button_cancel(self):
for doc in self.filtered(lambda d: d.document_type_id):
doc.fiscal_document_id.action_document_cancel()
# Esse método é responsavel por verificar se há alguma fatura de impostos
# retidos associada a essa fatura e cancela-las também.
self._withholding_validate()
return super().button_cancel()

# TODO: Por ora esta solução contorna o problema
Expand Down
16 changes: 1 addition & 15 deletions l10n_br_account/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
# pylint: disable=api-one-deprecated

from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo import api, fields, models

from .account_move import InheritsCheckMuteLogger

Expand Down Expand Up @@ -101,12 +100,6 @@ class AccountMoveLine(models.Model):
compute="_compute_allow_csll_irpj",
)

wh_move_line_id = fields.Many2one(
comodel_name="account.move.line",
string="WH Account Move Line",
ondelete="restrict",
)

discount = fields.Float(
compute="_compute_discounts",
store=True,
Expand Down Expand Up @@ -245,13 +238,6 @@ def write(self, values):
result = super().write(values)

for line in self:
if line.wh_move_line_id and (
"quantity" in values or "price_unit" in values
):
raise UserError(
_("You cannot edit an invoice related to a withholding entry")
)

cleaned_vals = line.move_id._cleanup_write_orm_values(line, values)
if not cleaned_vals:
continue
Expand Down
3 changes: 2 additions & 1 deletion l10n_br_account/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -366,7 +367,7 @@ <h1 class="title">Brazilian Localization Account</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c220a94f15382b53d8e28cc1df5904ea3658173a752127e2d59ba4e6834f218f
!! source digest: sha256:5fcbfbac6b08faeb2d2d9b964598e935db50e27b9372aa82b2422d02e434c4e8
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/l10n-brazil/tree/14.0/l10n_br_account"><img alt="OCA/l10n-brazil" src="https://img.shields.io/badge/github-OCA%2Fl10n--brazil-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/l10n-brazil-14-0/l10n-brazil-14-0-l10n_br_account"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/l10n-brazil&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module was written to extend the functionality of … to support …
Expand Down
174 changes: 174 additions & 0 deletions l10n_br_account_withholding/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
===========================
L10n Br Account Withholding
===========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5c0ff360aaaac0ccdb8df17732f0037b84a591b5262bd3f9ddca44429fb23196
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--brazil-lightgray.png?logo=github
:target: https://github.com/OCA/l10n-brazil/tree/14.0/l10n_br_account_withholding
:alt: OCA/l10n-brazil
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/l10n-brazil-14-0/l10n-brazil-14-0-l10n_br_account_withholding
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/l10n-brazil&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Automatize a conformidade fiscal brasileira, simplificando a criação de
faturas a pagar para impostos retidos em compras de fornecedores.
Garanta a precisão e eficiência no gerenciamento de obrigações fiscais
com o módulo ``l10n_br_account_withholding`` para Odoo.

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

Automatize a conformidade fiscal, reduza erros de entrada manual e
aprimore seus processos financeiros relacionados à retenção de impostos
de fornecedores.

- **Automatize a Conformidade Fiscal:** Crie contas a pagar para
impostos retidos em compras de fornecedores automaticamente.
- **Reduza Erros:** Minimize erros manuais e assegure a precisão nas
retenções de impostos.
- **Aprimore a Eficiência:** Melhore seus processos financeiros para
lidar com retenções de impostos de fornecedores.

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

Para instalar o módulo ``l10n_br_account_withholding`` em seu projeto
Odoo:

1. **Adicione o Repositório:**

- Adicione o repositório ``l10n-brazil`` da OCA no seu projeto
adicionando a URL: ``https://github.com/OCA/l10n-brazil``.
- Verifique os arquivos requirements.txt e oca_dependencies.txt
localizados na raiz do repositório ``l10n-brazil``. Estes arquivos
contêm, respectivamente, as dependências Python necessárias para o
Odoo e os repositórios da OCA dos quais os módulos da localização
brasileira dependem.

2. **Configure o Caminho dos Addons:**

- Adicione o caminho do repositório na configuração do Odoo em
``addons-path``.

3. **Atualize a Lista de Módulos:**

- Atualize sua lista de módulos para que o Odoo reconheça o novo
módulo.

4. **Busque pelo Módulo:**

- Pesquise por ``"L10n Br Account Withholding"`` nos addons do Odoo
para localizar o módulo.

5. **Instale o Módulo:**

- Prossiga com a instalação do módulo no ambiente Odoo.

Configuration
=============

Configure a geração de faturas de retenção de impostos no Odoo seguindo
estes passos:

1. **Acesse Configurações Fiscais:** Vá até
``Fiscal -> Configurações -> Grupos de Impostos``. Procure por
impostos retidos do tipo entrada.

2. **Configure os Impostos Retidos:** Para cada imposto que requer uma
fatura de retenção, garanta que esteja corretamente configurado.
Defina um fornecedor e o diário para a geração da fatura do imposto
se necessário. Se um diário não for especificado, o módulo usará o
diário da fatura de compra original.

Usage
=====

Siga estes passos para utilizar a geração de faturas de retenção de
impostos no Odoo:

1. **Criando uma Fatura de Compra:** Ao criar uma fatura de compra,
aplique o imposto retido nas linhas necessárias.

2. **Confirmação da Fatura:** Ao confirmar a fatura de compra, o módulo
gera automaticamente as faturas de retenção de impostos.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-brazil/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/l10n-brazil/issues/new?body=module:%20l10n_br_account_withholding%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Escodoo
* Akretion

Contributors
------------

- ``Escodoo <https://www.escodoo.com.br>``\ \_:

- Marcel Savegnago marcel.savegnago@escodoo.com.br

- ``Akretion <https://www.akretion.com.br>``\ \_:

- Renato Lima renato.lima@akretion.com.br

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-marcelsavegnago| image:: https://github.com/marcelsavegnago.png?size=40px
:target: https://github.com/marcelsavegnago
:alt: marcelsavegnago
.. |maintainer-renatonlima| image:: https://github.com/renatonlima.png?size=40px
:target: https://github.com/renatonlima
:alt: renatonlima

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-marcelsavegnago| |maintainer-renatonlima|

This module is part of the `OCA/l10n-brazil <https://github.com/OCA/l10n-brazil/tree/14.0/l10n_br_account_withholding>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions l10n_br_account_withholding/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
23 changes: 23 additions & 0 deletions l10n_br_account_withholding/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2024 Escodoo
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "L10n Br Account Withholding",
"summary": """
Brazilian Withholding Invoice Generator""",
"version": "14.0.1.0.0",
marcelsavegnago marked this conversation as resolved.
Show resolved Hide resolved
"license": "AGPL-3",
"author": "Escodoo,Akretion,Odoo Community Association (OCA)",
"maintainers": ["marcelsavegnago", "renatonlima"],
"website": "https://github.com/OCA/l10n-brazil",
"depends": [
"l10n_br_account",
],
"data": [
"views/l10n_br_fiscal_tax_group.xml",
"views/account_move.xml",
],
"demo": [
"demo/ir.property.xml",
],
}
36 changes: 36 additions & 0 deletions l10n_br_account_withholding/demo/ir.property.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2024 Marcel Savegnago - Escodoo (https://www.escodoo.com.br)
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo noupdate="1">

<record id="property_tax_group_pis_wh_generate_wh_invoice" model="ir.property">
<field name="name">generate_wh_invoice</field>
<field
name="fields_id"
search="[('model','=','l10n_br_fiscal.tax.group'),('name','=','generate_wh_invoice')]"
/>
<field name="value">1</field>
<field name="type" eval="'integer'" />
<field
eval="'l10n_br_fiscal.tax.group,'+str(ref('l10n_br_fiscal.tax_group_pis_wh'))"
name="res_id"
/>
<field name="company_id" ref="l10n_br_base.empresa_lucro_presumido" />
</record>

<record id="property_tax_group_cofins_wh_generate_wh_invoice" model="ir.property">
<field name="name">generate_wh_invoice</field>
<field
name="fields_id"
search="[('model','=','l10n_br_fiscal.tax.group'),('name','=','generate_wh_invoice')]"
/>
<field name="value">1</field>
<field name="type" eval="'integer'" />
<field
eval="'l10n_br_fiscal.tax.group,'+str(ref('l10n_br_fiscal.tax_group_cofins_wh'))"
name="res_id"
/>
<field name="company_id" ref="l10n_br_base.empresa_lucro_presumido" />
</record>

</odoo>
Loading
Loading