-
-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] l10n_it_sdi_channel: One button to validate, export and send
- Loading branch information
Showing
9 changed files
with
128 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import account_invoice | ||
from . import fatturapa_attachment_out | ||
from . import company | ||
from . import sdi |
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,42 @@ | ||
# Copyright 2022 Simone Rubino - TAKOBI | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models | ||
|
||
|
||
class AccountInvoice (models.Model): | ||
_inherit = 'account.invoice' | ||
|
||
def action_open_export_send_sdi(self): | ||
"""Validate, export and send to SdI the invoices.""" | ||
# Validate | ||
self.action_invoice_open() | ||
|
||
# Export | ||
export_action = self.env['ir.actions.act_window'].for_xml_id( | ||
'l10n_it_fatturapa_out', | ||
'action_wizard_export_fatturapa', | ||
) | ||
export_wizard_model = export_action.get('res_model') | ||
export_wizard = self.env[export_wizard_model] \ | ||
.with_context( | ||
active_model=self._name, | ||
active_ids=self.ids, | ||
) \ | ||
.create([{}]) | ||
export_result = export_wizard.exportFatturaPA() | ||
|
||
# Get the exported attachments | ||
attachment_model = self.env[export_result.get('res_model')] | ||
exported_attachments_domain = export_result.get('domain') | ||
if not exported_attachments_domain: | ||
exported_attachments_domain = [ | ||
('id', '=', export_result.get('res_id')), | ||
] | ||
exported_attachments = attachment_model.search( | ||
exported_attachments_domain, | ||
) | ||
|
||
# Send | ||
send_result = exported_attachments.send_to_sdi() | ||
return send_result |
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,3 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import test_account_invoice |
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,33 @@ | ||
# Copyright 2022 Simone Rubino - TAKOBI | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.addons.l10n_it_fatturapa_out.tests.fatturapa_common import \ | ||
FatturaPACommon | ||
|
||
|
||
class TestAccountInvoice (FatturaPACommon): | ||
|
||
def test_action_open_export_send_sdi(self): | ||
""" | ||
Check that the "Validate, export and send to SdI" button | ||
validates the invoice and exports the attachment. | ||
""" | ||
# Arrange: create a draft invoice with no attachment | ||
invoice = self._create_invoice() | ||
self.assertEqual(invoice.state, 'draft') | ||
self.assertFalse(invoice.fatturapa_attachment_out_id) | ||
|
||
# Act: open, export and send. | ||
# This raises an exception because there is no channel, | ||
# we can't create a channel yet | ||
# because channel types are defined by depending modules | ||
with self.assertRaises(ValueError) as ve: | ||
invoice.action_open_export_send_sdi() | ||
exc_message = ve.exception.args[0] | ||
|
||
# Assert: we are missing the SdI channel, | ||
# but invoice is validated and attachment has been created | ||
self.assertIn('Expected singleton', exc_message) | ||
self.assertIn('sdi.channel', exc_message) | ||
self.assertEqual(invoice.state, 'open') | ||
self.assertTrue(invoice.fatturapa_attachment_out_id) |
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,30 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!-- | ||
~ Copyright 2022 Simone Rubino - TAKOBI | ||
~ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
--> | ||
|
||
<odoo> | ||
<record id="view_invoice_form_fatturapa" model="ir.ui.view"> | ||
<field name="name">Add SdI channel edits to invoice's form view</field> | ||
<field name="model">account.invoice</field> | ||
<field name="inherit_id" ref="l10n_it_fatturapa_out.view_invoice_form_fatturapa"/> | ||
<field name="arch" type="xml"> | ||
<button name="%(l10n_it_fatturapa_out.action_wizard_export_fatturapa)d" position="after"> | ||
<button name="action_open_export_send_sdi" | ||
type="object" | ||
string="Validate, export and send to SdI" | ||
groups="l10n_it_sdi_channel.res_groups_validate_send" | ||
attrs="{ | ||
'invisible': [ | ||
'|', | ||
'|', | ||
('fatturapa_attachment_out_id', '!=', False), | ||
('state' ,'not in', ['draft']), | ||
('electronic_invoice_subjected', '=', False), | ||
]}" | ||
/> | ||
</button> | ||
</field> | ||
</record> | ||
</odoo> |
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