Skip to content

Commit

Permalink
[MIG] l10n_it_account_stamp: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jado95 committed Apr 2, 2021
1 parent 14a5821 commit 5fcd1c0
Show file tree
Hide file tree
Showing 16 changed files with 312 additions and 238 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repos:
language: fail
files: "\\.rej$"
- repo: https://github.com/oca/maintainer-tools
rev: 1b5c7ad
rev: ab1d7f6
hooks:
# update the NOT INSTALLABLE ADDONS section above
- id: oca-update-pre-commit-excluded-addons
Expand Down
24 changes: 13 additions & 11 deletions l10n_it_account_stamp/README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=======================================
Italian Localization - Imposta di bollo
=======================================
======================
ITA - Imposta di bollo
======================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
Expand All @@ -14,13 +14,13 @@ Italian Localization - Imposta di bollo
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github
:target: https://github.com/OCA/l10n-italy/tree/12.0/l10n_it_account_stamp
:target: https://github.com/OCA/l10n-italy/tree/14.0--add-14.0-mig-l10n_it_account_stamp/l10n_it_account_stamp
:alt: OCA/l10n-italy
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/l10n-italy-12-0/l10n-italy-12-0-l10n_it_account_stamp
:target: https://translation.odoo-community.org/projects/l10n-italy-14-0--add-14-0-mig-l10n_it_account_stamp/l10n-italy-14-0--add-14-0-mig-l10n_it_account_stamp-l10n_it_account_stamp
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/122/12.0
:target: https://runbot.odoo-community.org/runbot/122/14.0--add-14.0-mig-l10n_it_account_stamp
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -53,7 +53,7 @@ Modalità manuale:

- andare sul prodotto "Imposta di bollo 2 euro" e deselezionare la casella "Calcolo automatico".

- per ciascuna fattura, abilitare manualmente la casella di selezione "Imposta di bollo".
- per ciascuna fattura, abilitare manualmente la casella di selezione "Imposta di bollo". L'applicabilità dell'imposta di bollo verrà calcolata in base alla somma degli imponibili relativi alle imposte selezionate.

Impostare i conti di ricavo/costo nella scheda "Contabilità", generalmente ricavo="Debiti per bolli" e costo="Valori bollati".

Expand All @@ -63,13 +63,13 @@ Automatic mode:

- Go to 'Tax Stamp 2 euro' product and configure 'Stamp taxes' (exemption taxes).

- For each invoice, the base amount for each selected tax will be added up and used to determine the application of the account stamp.
- For each invoice, the base amount for each selected tax will be added up and used to automatically determine the application of the account stamp.

Manual mode:

- Go to 'Tax Stamp 2 euro' product and deselect 'Auto-compute' checkbox.

- For each invoice, manually enable 'Tax Stamp' checkbox.
- For each invoice, manually enable 'Tax Stamp' checkbox. The base amount for each selected tax will be added up and used to determine the application of the account stamp.

Also set income/expense accounts, typically income = 'Debiti per bolli' and expense = 'Valori bollati'.

Expand All @@ -94,7 +94,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-italy/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/l10n-italy/issues/new?body=module:%20l10n_it_account_stamp%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/l10n-italy/issues/new?body=module:%20l10n_it_account_stamp%0Aversion:%2014.0--add-14.0-mig-l10n_it_account_stamp%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.

Expand All @@ -116,6 +116,8 @@ Contributors
* Ermanno Gnan
* Enrico Ganzaroli
* Sergio Zanchetta <https://github.com/primes2h>
* Marco Colombo <https://github.com/TheMule71>
* Gianmarco Conte <gconte@dinamicheaziendali.it>

Maintainers
~~~~~~~~~~~
Expand All @@ -130,6 +132,6 @@ 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.

This module is part of the `OCA/l10n-italy <https://github.com/OCA/l10n-italy/tree/12.0/l10n_it_account_stamp>`_ project on GitHub.
This module is part of the `OCA/l10n-italy <https://github.com/OCA/l10n-italy/tree/14.0--add-14.0-mig-l10n_it_account_stamp/l10n_it_account_stamp>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
9 changes: 5 additions & 4 deletions l10n_it_account_stamp/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
# Copyright 2018 Enrico Ganzaroli (enrico.gz@gmail.com)
# Copyright 2018 Ermanno Gnan (ermannognan@gmail.com)
# Copyright 2018 Lorenzo Battistini (https://github.com/eLBati)
# Copyright 2018-2019 Sergio Zanchetta (https://github.com/primes2h)
# Copyright 2018-2020 Sergio Zanchetta (https://github.com/primes2h)
# Copyright 2021 Gianmarco Conte <gconte@dinamicheaziendali.it>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

{
"name": "Italian Localization - Imposta di bollo",
"version": "12.0.1.1.2",
"name": "ITA - Imposta di bollo",
"version": "14.0.1.0.0",
"category": "Localization/Italy",
"summary": "Gestione automatica dell'imposta di bollo",
"author": "Ermanno Gnan, Sergio Corato, Enrico Ganzaroli, "
Expand All @@ -20,7 +21,7 @@
],
"data": [
"data/data.xml",
"views/invoice_view.xml",
"views/account_move_view.xml",
"views/product_view.xml",
"views/company_view.xml",
],
Expand Down
7 changes: 4 additions & 3 deletions l10n_it_account_stamp/data/data.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<openerp>
<odoo>
<data noupdate="1">

<record id="l10n_it_account_stamp_2_euro" model="product.product">
Expand All @@ -10,7 +10,8 @@
<field
name="description_sale"
>Stamp duty payment under the terms of Art. 6, Subsection 2 of MEF Decree June
17, 2014</field>
17, 2014
</field>
<field name="is_stamp" eval="True" />
<field name="auto_compute" eval="True" />
<field name="stamp_apply_min_total_base" eval="77.47" />
Expand All @@ -26,4 +27,4 @@
</record>

</data>
</openerp>
</odoo>
2 changes: 1 addition & 1 deletion l10n_it_account_stamp/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

from . import invoice
from . import account_move
from . import product
from . import company
187 changes: 187 additions & 0 deletions l10n_it_account_stamp/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

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


class AccountMove(models.Model):
_inherit = "account.move"

tax_stamp = fields.Boolean(
"Tax Stamp", readonly=False, compute="_compute_tax_stamp", store=True
)
auto_compute_stamp = fields.Boolean(
related="company_id.tax_stamp_product_id.auto_compute"
)
manually_apply_tax_stamp = fields.Boolean("Apply tax stamp")

def is_tax_stamp_applicable(self):
stamp_product_id = self.env.company.with_context(
lang=self.partner_id.lang
).tax_stamp_product_id
if not stamp_product_id:
raise Warning(_("Missing tax stamp product in company settings!"))
total_tax_base = sum(
(
inv_tax.price_subtotal
for inv_tax in self.line_ids.filtered(
lambda line: set(line.tax_ids.ids)
& set(stamp_product_id.stamp_apply_tax_ids.ids)
)
),
0.0,
)
return total_tax_base >= stamp_product_id.stamp_apply_min_total_base

@api.depends(
"invoice_line_ids.price_subtotal",
"line_ids.price_total",
"currency_id",
"company_id",
"invoice_date",
"move_type",
"manually_apply_tax_stamp",
"invoice_line_ids.tax_ids",
)
def _compute_tax_stamp(self):
for invoice in self:
invoice.tax_stamp = False
if invoice.auto_compute_stamp:
invoice.tax_stamp = invoice.is_tax_stamp_applicable()
else:
if invoice.manually_apply_tax_stamp:
invoice.tax_stamp = True

def add_tax_stamp_line(self):
for inv in self:
if not inv.tax_stamp:
raise Warning(_("Tax stamp is not applicable"))
stamp_product_id = self.env.company.with_context(
lang=inv.partner_id.lang
).tax_stamp_product_id
if not stamp_product_id:
raise Warning(_("Missing tax stamp product in company settings!"))
for line in inv.invoice_line_ids:
if line.product_id and line.product_id.is_stamp:
raise Warning(
_("Tax sss stamp line %s already present. " "Remove it first.")
% line.name
)
stamp_account = stamp_product_id.property_account_income_id
if not stamp_account:
raise Warning(
_("Missing account income configuration for" " %s")
% stamp_product_id.name
)
invoice_line_vals = {
"move_id": inv.id,
"product_id": stamp_product_id.id,
"name": stamp_product_id.description_sale,
"sequence": 99999,
"account_id": stamp_account.id,
"price_unit": stamp_product_id.list_price,
"quantity": 1,
"product_uom_id": stamp_product_id.uom_id.id,
"tax_ids": [(6, 0, stamp_product_id.taxes_id.ids)],
"analytic_account_id": None,
}
inv.write({"invoice_line_ids": [(0, 0, invoice_line_vals)]})

def is_tax_stamp_line_present(self):
for line in self.line_ids:
if line.is_stamp_line:
return True
return False

def is_tax_stamp_product_present(self):
product_stamp = self.invoice_line_ids.filtered(
lambda line: line.product_id.is_stamp
)
if product_stamp:
return True
return False

def _build_tax_stamp_lines(self, product):
if (
not product.property_account_income_id
or not product.property_account_expense_id
):
raise Warning(
_("Product %s must have income and expense accounts") % product.name
)

income_vals = {
"name": _("Tax Stamp Income"),
"is_stamp_line": True,
"partner_id": self.partner_id.id,
"account_id": product.property_account_income_id.id,
"journal_id": self.journal_id.id,
"date": self.invoice_date,
"debit": 0,
"credit": product.list_price,
"exclude_from_invoice_tab": True,
}
if self.move_type == "out_refund":
income_vals["debit"] = product.list_price
income_vals["credit"] = 0

expense_vals = {
"name": _("Tax Stamp Expense"),
"is_stamp_line": True,
"partner_id": self.partner_id.id,
"account_id": product.property_account_expense_id.id,
"journal_id": self.journal_id.id,
"date": self.invoice_date,
"debit": product.list_price,
"credit": 0,
"exclude_from_invoice_tab": True,
}
if self.move_type == "out_refund":
income_vals["debit"] = 0
income_vals["credit"] = product.list_price

return income_vals, expense_vals

def _post(self, soft=True):
res = super(AccountMove, self)._post(soft=soft)
for inv in self:
posted = False
if (
inv.tax_stamp
and not inv.is_tax_stamp_line_present()
and not inv.is_tax_stamp_product_present()
):
if inv.state == "posted":
posted = True
inv.state = "draft"
line_model = self.env["account.move.line"]
stamp_product_id = self.env.company.with_context(
lang=inv.partner_id.lang
).tax_stamp_product_id
if not stamp_product_id:
raise Warning(_("Missing tax stamp product in company settings!"))
income_vals, expense_vals = inv._build_tax_stamp_lines(stamp_product_id)
income_vals["move_id"] = inv.id
expense_vals["move_id"] = inv.id
line_model.with_context(check_move_validity=False).create(income_vals)
line_model.with_context(check_move_validity=False).create(expense_vals)
if posted:
inv.state = "posted"
return res

def button_draft(self):
res = super(AccountMove, self).button_draft()
for account_move in self:
move_line_tax_stamp_ids = account_move.line_ids.filtered(
lambda line: line.is_stamp_line
)
move_line_tax_stamp_ids.unlink()
return res


class AccountInvoiceLine(models.Model):
_inherit = "account.move.line"

is_stamp_line = fields.Boolean(
readonly=True
) # used only with automatic tax stamp active
16 changes: 1 addition & 15 deletions l10n_it_account_stamp/models/company.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

from odoo import api, fields, models
from odoo import fields, models


class ResCompany(models.Model):
Expand All @@ -22,17 +22,3 @@ class AccountConfigSettings(models.TransientModel):
help="Product used as Tax Stamp in customer invoices.",
readonly=False,
)

@api.onchange("company_id")
def onchange_company_id(self):
res = super(AccountConfigSettings, self).onchange_company_id()
if self.company_id:
company = self.company_id
self.tax_stamp_product_id = (
company.tax_stamp_product_id
and company.tax_stamp_product_id.id
or False
)
else:
self.tax_stamp_product_id = False
return res
Loading

0 comments on commit 5fcd1c0

Please sign in to comment.