-
-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] l10n_it_fatturapa_out_rc: Migration to 14.0
- Loading branch information
Showing
21 changed files
with
553 additions
and
626 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from . import rc_type | ||
from . import account_invoice | ||
from . import account_move |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
from odoo import _, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class AccountMove(models.Model): | ||
_inherit = "account.move" | ||
|
||
def generate_self_invoice(self): | ||
res = super().generate_self_invoice() | ||
if self.rc_self_invoice_id: | ||
rc_type = self.fiscal_position_id.rc_type_id | ||
if rc_type.fiscal_document_type_id: | ||
self.rc_self_invoice_id.fiscal_document_type_id = ( | ||
rc_type.fiscal_document_type_id.id | ||
) | ||
if self.fatturapa_attachment_in_id: | ||
doc_id = self.fatturapa_attachment_in_id.name | ||
else: | ||
doc_id = self.ref if self.ref else self.name | ||
self.rc_self_invoice_id.related_documents = [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"type": "invoice", | ||
"name": doc_id, | ||
"date": self.invoice_date, | ||
}, | ||
) | ||
] | ||
return res | ||
|
||
def button_draft(self): | ||
super().button_draft() | ||
for inv in self: | ||
if not inv.env.context.get( | ||
"rc_set_to_draft" | ||
) and inv.rc_purchase_invoice_id.state in ["draft", "cancel"]: | ||
raise UserError( | ||
_( | ||
"Vendor invoice that has generated this self invoice isn't " | ||
"validated. " | ||
"Validate vendor invoice before." | ||
) | ||
) | ||
return True | ||
|
||
def preventive_checks(self): | ||
super().preventive_checks() | ||
invoices = self | ||
invoices_with_rc = invoices.filtered(lambda x: x.rc_purchase_invoice_id) | ||
invoices_without_rc = invoices - invoices_with_rc | ||
if invoices_with_rc and invoices_without_rc: | ||
raise UserError( | ||
_( | ||
"Selected invoices are both with and without reverse charge. You " | ||
"should selected a smaller set of invoices" | ||
) | ||
) | ||
invoices_with_document_type_codes = invoices.filtered( | ||
lambda x: x.fiscal_document_type_id.code in ["TD17", "TD18", "TD19"] | ||
) | ||
invoices_without_document_type_codes = ( | ||
invoices - invoices_with_document_type_codes | ||
) | ||
if invoices_with_document_type_codes and invoices_without_document_type_codes: | ||
raise UserError( | ||
_( | ||
"Select invoices are of too many fiscal document types: " | ||
"select invoices exclusively of type 'TD17', 'TD18', 'TD19' " | ||
"or exclusively of other types." | ||
) | ||
) | ||
rc_suppliers = invoices.mapped("rc_purchase_invoice_id.partner_id") | ||
if len(rc_suppliers) > 1: | ||
raise UserError( | ||
_( | ||
"Selected reverse charge invoices have different suppliers. Please " | ||
"select invoices with same supplier" | ||
) | ||
) | ||
# --- preventive checks related to set CedentePrestatore.DatiAnagrafici --- # | ||
partner = rc_suppliers[0] | ||
fiscal_document_type_codes = invoices.mapped("fiscal_document_type_id.code") | ||
# Se vale IT , il sistema verifica che il TipoDocumento sia diverso da | ||
# TD17, TD18 e TD19; in caso contrario il file viene scartato | ||
if partner.vat: | ||
if partner.vat[0:2] == "IT" and any( | ||
[x in ["TD17", "TD18", "TD19"] for x in fiscal_document_type_codes] | ||
): | ||
raise UserError( | ||
_( | ||
"A self-invoice cannot be issued with IT country code and " | ||
"fiscal document type in 'TD17', 'TD18', 'TD19'." | ||
) | ||
) | ||
if partner.vat[0:2] not in self.env["res.country"].search([]).mapped( | ||
"code" | ||
): | ||
raise ValueError( | ||
_( | ||
"Country code does not exist or it is not mapped in countries: " | ||
"%s" % partner.vat[0:2] | ||
) | ||
) | ||
elif not partner.country_id.code or partner.country_id.code == "IT": | ||
raise UserError( | ||
_("Impossible to set IdFiscaleIVA for %s") % partner.display_name | ||
) | ||
# --- preventive checks related to set CedentePrestatore.Sede --- # | ||
if not partner.street: | ||
raise UserError(_("Partner %s, Street is not set.") % partner.display_name) | ||
if not partner.city: | ||
raise UserError(_("Partner %s, City is not set.") % partner.display_name) | ||
if not partner.country_id: | ||
raise UserError(_("Partner %s, Country is not set.") % partner.display_name) | ||
if not partner.zip: | ||
raise UserError(_("Partner %s, ZIP is not set.") % partner.display_name) | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
* `TAKOBI <https://takobi.online>`_: | ||
|
||
* Lorenzo Battistini | ||
* `Agile Business Group <https://agilebg.com>`_: | ||
|
||
* Alex Comba <alex.comba@agilebg.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import test_e_invoice_out_rc | ||
from . import fatturapa_common | ||
from . import test_fatturapa_xml_validation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from odoo.addons.l10n_it_fatturapa_out.tests.fatturapa_common import ( | ||
FatturaPACommon as _FatturaPACommon, | ||
) | ||
|
||
|
||
class FatturaPACommon(_FatturaPACommon): | ||
def setUp(self): | ||
super().setUp() | ||
|
||
def _fix_payability(tax, ref): | ||
reftax = self.env.ref(ref).sudo() | ||
tax.payability = reftax.payability | ||
|
||
# XXX - to be moved to l10n_it_fatturapa_out.tests.fatturapa_common ? | ||
_fix_payability(self.tax_22, "l10n_it_fatturapa.tax_22") | ||
_fix_payability(self.tax_10, "l10n_it_fatturapa.tax_10") | ||
_fix_payability(self.tax_22_SP, "l10n_it_fatturapa.tax_22_SP") | ||
|
||
def getAttachment(self, name, module_name=None): | ||
if module_name is None: | ||
module_name = "l10n_it_fatturapa_out_rc" | ||
return super().getAttachment(name, module_name) | ||
|
||
def getFile(self, filename, module_name=None): | ||
if module_name is None: | ||
module_name = "l10n_it_fatturapa_out_rc" | ||
return super().getFile(filename, module_name) |
Oops, something went wrong.