From 8e517aae978c8d199d32b781bfa546f6de38d129 Mon Sep 17 00:00:00 2001 From: gianmarco Date: Fri, 15 Jan 2021 10:52:50 +0100 Subject: [PATCH] [MIG] l10n_it_account_stamp: Migration to 14.0 --- l10n_it_account_stamp/README.rst | 24 ++-- l10n_it_account_stamp/__manifest__.py | 7 +- l10n_it_account_stamp/data/data.xml | 24 ++-- l10n_it_account_stamp/models/__init__.py | 2 +- .../models/{invoice.py => account_move.py} | 121 +++++++++--------- l10n_it_account_stamp/models/company.py | 14 -- l10n_it_account_stamp/models/product.py | 3 +- l10n_it_account_stamp/readme/CONFIGURE.rst | 6 +- l10n_it_account_stamp/readme/CONTRIBUTORS.rst | 2 + .../static/description/index.html | 20 +-- .../views/account_move_view.xml | 38 ++++++ l10n_it_account_stamp/views/invoice_view.xml | 65 ---------- l10n_it_account_stamp/views/product_view.xml | 16 +-- 13 files changed, 153 insertions(+), 189 deletions(-) rename l10n_it_account_stamp/models/{invoice.py => account_move.py} (58%) create mode 100644 l10n_it_account_stamp/views/account_move_view.xml delete mode 100644 l10n_it_account_stamp/views/invoice_view.xml diff --git a/l10n_it_account_stamp/README.rst b/l10n_it_account_stamp/README.rst index cbca5d2605e2..a5df9b31f8b2 100644 --- a/l10n_it_account_stamp/README.rst +++ b/l10n_it_account_stamp/README.rst @@ -1,6 +1,6 @@ -======================================= -Italian Localization - Imposta di bollo -======================================= +====================== +ITA - Imposta di bollo +====================== .. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! @@ -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| @@ -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". @@ -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'. @@ -94,7 +94,7 @@ Bug Tracker Bugs are tracked on `GitHub 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -116,6 +116,8 @@ Contributors * Ermanno Gnan * Enrico Ganzaroli * Sergio Zanchetta +* Marco Colombo +* Gianmarco Conte Maintainers ~~~~~~~~~~~ @@ -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 `_ project on GitHub. +This module is part of the `OCA/l10n-italy `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/l10n_it_account_stamp/__manifest__.py b/l10n_it_account_stamp/__manifest__.py index c0749850902d..ab52d46cc6d4 100644 --- a/l10n_it_account_stamp/__manifest__.py +++ b/l10n_it_account_stamp/__manifest__.py @@ -2,11 +2,12 @@ # 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 # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). { - "name": "Italian Localization - Imposta di bollo", + "name": "ITA - Imposta di bollo", "version": "14.0.1.0.0", "category": "Localization/Italy", "summary": "Gestione automatica dell'imposta di bollo", @@ -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", ], diff --git a/l10n_it_account_stamp/data/data.xml b/l10n_it_account_stamp/data/data.xml index 82c5e3045ee0..9a0220b03ecf 100644 --- a/l10n_it_account_stamp/data/data.xml +++ b/l10n_it_account_stamp/data/data.xml @@ -1,29 +1,29 @@ - + Tax Stamp 2 euro service - - + + Stamp duty payment under the terms of Art. 6, Subsection 2 of MEF Decree June -17, 2014 - - - - - + 17, 2014 + + + + + + + ref="l10n_it_account_stamp.l10n_it_account_stamp_2_euro"/> - + diff --git a/l10n_it_account_stamp/models/__init__.py b/l10n_it_account_stamp/models/__init__.py index 19a47b911516..bfd58fa2f7b9 100644 --- a/l10n_it_account_stamp/models/__init__.py +++ b/l10n_it_account_stamp/models/__init__.py @@ -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 diff --git a/l10n_it_account_stamp/models/invoice.py b/l10n_it_account_stamp/models/account_move.py similarity index 58% rename from l10n_it_account_stamp/models/invoice.py rename to l10n_it_account_stamp/models/account_move.py index 697aa73348fb..cb740c3c7fe5 100644 --- a/l10n_it_account_stamp/models/invoice.py +++ b/l10n_it_account_stamp/models/account_move.py @@ -3,31 +3,28 @@ from odoo import _, api, exceptions, fields, models -class AccountInvoice(models.Model): - _inherit = "account.invoice" - tax_stamp = fields.Boolean( - "Tax Stamp", - readonly=True, - states={"draft": [("readonly", False)]}, - compute="_compute_tax_stamp", - store=True, - ) +class AccountMove(models.Model): + _inherit = "account.move" + + tax_stamp = fields.Boolean("Tax Stamp", readonly=True, + states={"draft": [("readonly", False)]}, + compute="_compute_tax_stamp", store=True) auto_compute_stamp = fields.Boolean( related="company_id.tax_stamp_product_id.auto_compute" ) def is_tax_stamp_applicable(self): - stamp_product_id = self.env.user.with_context( - lang=self.partner_id.lang - ).company_id.tax_stamp_product_id + stamp_product_id = self.env.company.with_context( + lang=self.partner_id.lang).tax_stamp_product_id if not stamp_product_id: raise exceptions.Warning( _("Missing tax stamp product in company settings!") ) total_tax_base = 0.0 - for inv_tax in self.tax_line_ids: - if inv_tax.tax_id.id in stamp_product_id.stamp_apply_tax_ids.ids: - total_tax_base += inv_tax.base + for inv_tax in self.line_ids.filtered(lambda line: line.tax_line_id): + if inv_tax.tax_line_id.id in \ + stamp_product_id.stamp_apply_tax_ids.ids: + total_tax_base += inv_tax.tax_base_amount if total_tax_base >= stamp_product_id.stamp_apply_min_total_base: return True else: @@ -35,26 +32,25 @@ def is_tax_stamp_applicable(self): @api.depends( "invoice_line_ids.price_subtotal", - "tax_line_ids.amount", - "tax_line_ids.amount_rounding", + "line_ids.price_total", "currency_id", "company_id", - "date_invoice", - "type", + "invoice_date", + "move_type", ) 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() - @api.multi def add_tax_stamp_line(self): for inv in self: if not inv.tax_stamp: raise exceptions.Warning(_("Tax stamp is not applicable")) - stamp_product_id = self.env.user.with_context( + stamp_product_id = self.env.company.with_context( lang=inv.partner_id.lang - ).company_id.tax_stamp_product_id + ).tax_stamp_product_id if not stamp_product_id: raise exceptions.Warning( _("Missing tax stamp product in company settings!") @@ -62,7 +58,9 @@ def add_tax_stamp_line(self): for line in inv.invoice_line_ids: if line.product_id and line.product_id.is_stamp: raise exceptions.Warning( - _("Tax stamp line %s already present. " "Remove it first.") + _( + "Tax stamp line %s already present. " + "Remove it first.") % line.name ) stamp_account = stamp_product_id.property_account_income_id @@ -71,21 +69,20 @@ def add_tax_stamp_line(self): _("Missing account income configuration for" " %s") % stamp_product_id.name ) - self.env["account.invoice.line"].create( - { - "invoice_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, - "uom_id": stamp_product_id.uom_id.id, - "invoice_line_tax_ids": [(6, 0, stamp_product_id.taxes_id.ids)], - "account_analytic_id": None, - } - ) - inv.compute_taxes() + 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.invoice_line_ids: @@ -99,7 +96,9 @@ def _build_tax_stamp_lines(self, product): or not product.property_account_expense_id ): raise exceptions.Warning( - _("Product %s must have income and expense accounts") % product.name + _( + "Product %s must have income and expense accounts") + % product.name ) income_vals = { @@ -107,11 +106,12 @@ def _build_tax_stamp_lines(self, product): "partner_id": self.partner_id.id, "account_id": product.property_account_income_id.id, "journal_id": self.journal_id.id, - "date": self.date_invoice, + "date": self.invoice_date, "debit": 0, "credit": product.list_price, + "exclude_from_invoice_tab": True } - if self.type == "out_refund": + if self.move_type == "out_refund": income_vals["debit"] = product.list_price income_vals["credit"] = 0 @@ -120,45 +120,48 @@ def _build_tax_stamp_lines(self, product): "partner_id": self.partner_id.id, "account_id": product.property_account_expense_id.id, "journal_id": self.journal_id.id, - "date": self.date_invoice, + "date": self.invoice_date, "debit": product.list_price, "credit": 0, + "exclude_from_invoice_tab": True } - if self.type == "out_refund": + if self.move_type == "out_refund": income_vals["debit"] = 0 income_vals["credit"] = product.list_price return income_vals, expense_vals - @api.multi - def action_move_create(self): - res = super(AccountInvoice, self).action_move_create() + 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(): - if inv.move_id.state == "posted": + if inv.state == "posted": posted = True - inv.move_id.state = "draft" + inv.state = "draft" line_model = self.env["account.move.line"] - stamp_product_id = self.env.user.with_context( + stamp_product_id = self.env.company.with_context( lang=inv.partner_id.lang - ).company_id.tax_stamp_product_id + ).tax_stamp_product_id if not stamp_product_id: raise exceptions.Warning( _("Missing tax stamp product in company settings!") ) income_vals, expense_vals = self._build_tax_stamp_lines( - stamp_product_id - ) - income_vals["move_id"] = inv.move_id.id - expense_vals["move_id"] = inv.move_id.id - line_model.with_context(check_move_validity=False).create(income_vals) - line_model.with_context(check_move_validity=False).create(expense_vals) + 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.move_id.state = "posted" + inv.state = "posted" return res class AccountInvoiceLine(models.Model): - _inherit = "account.invoice.line" + _inherit = "account.move.line" - is_stamp_line = fields.Boolean(related="product_id.is_stamp", readonly=True) + is_stamp_line = fields.Boolean(related="product_id.is_stamp", + readonly=True) diff --git a/l10n_it_account_stamp/models/company.py b/l10n_it_account_stamp/models/company.py index 3e9f13fc034d..30445eb1f1bd 100644 --- a/l10n_it_account_stamp/models/company.py +++ b/l10n_it_account_stamp/models/company.py @@ -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 diff --git a/l10n_it_account_stamp/models/product.py b/l10n_it_account_stamp/models/product.py index 5f9de3f2b61c..e48364ec5c74 100644 --- a/l10n_it_account_stamp/models/product.py +++ b/l10n_it_account_stamp/models/product.py @@ -2,7 +2,6 @@ from odoo import _, api, exceptions, fields, models -import odoo.addons.decimal_precision as dp class ProductTemplate(models.Model): @@ -25,7 +24,7 @@ def _check_stamp_apply_tax(self): string="Stamp taxes", ) stamp_apply_min_total_base = fields.Float( - "Stamp applicability min total base", digits=dp.get_precision("Account") + "Stamp applicability min total base", digits="Account" ) is_stamp = fields.Boolean("Is a stamp") auto_compute = fields.Boolean("Auto-compute") diff --git a/l10n_it_account_stamp/readme/CONFIGURE.rst b/l10n_it_account_stamp/readme/CONFIGURE.rst index 50ae2b7370c2..6281e2a85ff4 100644 --- a/l10n_it_account_stamp/readme/CONFIGURE.rst +++ b/l10n_it_account_stamp/readme/CONFIGURE.rst @@ -10,7 +10,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". @@ -20,12 +20,12 @@ 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'. diff --git a/l10n_it_account_stamp/readme/CONTRIBUTORS.rst b/l10n_it_account_stamp/readme/CONTRIBUTORS.rst index babf4ab2f964..3f04a95c18b0 100644 --- a/l10n_it_account_stamp/readme/CONTRIBUTORS.rst +++ b/l10n_it_account_stamp/readme/CONTRIBUTORS.rst @@ -3,3 +3,5 @@ * Ermanno Gnan * Enrico Ganzaroli * Sergio Zanchetta +* Marco Colombo +* Gianmarco Conte diff --git a/l10n_it_account_stamp/static/description/index.html b/l10n_it_account_stamp/static/description/index.html index 2eefb6b32aac..39cd6b99704a 100644 --- a/l10n_it_account_stamp/static/description/index.html +++ b/l10n_it_account_stamp/static/description/index.html @@ -4,7 +4,7 @@ -Italian Localization - Imposta di bollo +ITA - Imposta di bollo -
-

Italian Localization - Imposta di bollo

+
+

ITA - Imposta di bollo

-

Beta License: LGPL-3 OCA/l10n-italy Translate me on Weblate Try me on Runbot

+

Beta License: LGPL-3 OCA/l10n-italy Translate me on Weblate Try me on Runbot

Italiano

Questo modulo aggiunge il supporto all’imposta di bollo italiana nelle fatture.

English

@@ -397,19 +397,19 @@

Configuration

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”.

English

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’.

@@ -427,7 +427,7 @@

Bug Tracker

Bugs are tracked on GitHub 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.

+feedback.

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

@@ -448,6 +448,8 @@

Contributors

  • Ermanno Gnan
  • Enrico Ganzaroli
  • Sergio Zanchetta <https://github.com/primes2h>
  • +
  • Marco Colombo <https://github.com/TheMule71>
  • +
  • Gianmarco Conte <gconte@dinamicheaziendali.it>
  • @@ -457,7 +459,7 @@

    Maintainers

    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 project on GitHub.

    +

    This module is part of the OCA/l10n-italy project on GitHub.

    You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

    diff --git a/l10n_it_account_stamp/views/account_move_view.xml b/l10n_it_account_stamp/views/account_move_view.xml new file mode 100644 index 000000000000..a0745d39727d --- /dev/null +++ b/l10n_it_account_stamp/views/account_move_view.xml @@ -0,0 +1,38 @@ + + + + + + + account.move.form.stamp + account.move + + + + + + + CadetBlue:is_stamp_line==True; + + + + + + + + + Tax stamp +