Skip to content

Commit 23589ea

Browse files
committed
ADD l10n_it_fatturapa_in_payment_terms
1 parent 645e427 commit 23589ea

16 files changed

+508
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import models
2+
from . import tests
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2025 Lorenzo Battistini
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
{
5+
'name': 'ITA - Fattura elettronica - Payment Terms from XML',
6+
'version': '12.0.1.0.0',
7+
'category': 'Localization/Italy',
8+
'summary': 'Retrieve payment terms from FatturaPA XML',
9+
'author': 'Odoo Community Association (OCA)',
10+
'website': 'https://github.com/OCA/l10n-italy',
11+
'license': 'AGPL-3',
12+
'depends': [
13+
'l10n_it_fatturapa_in',
14+
'account',
15+
],
16+
'data': [
17+
'views/res_partner_views.xml',
18+
'views/account_invoice_views.xml',
19+
],
20+
'installable': True,
21+
'auto_install': False,
22+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import res_partner
2+
from . import account_invoice
3+
from . import account_payment_term
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright 2025 Lorenzo Battistini
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, fields, models, _
5+
from odoo.exceptions import UserError
6+
7+
8+
class AccountInvoice(models.Model):
9+
_inherit = 'account.invoice'
10+
11+
fatturapa_retrieve_due_dates = fields.Boolean(
12+
string="Retrieve due dates from XML",
13+
help="If set, payment terms will be retrieved from the FatturaPA payment data."
14+
)
15+
16+
@api.onchange('partner_id')
17+
def _onchange_partner_id_fatturapa_payment_terms(self):
18+
if self.partner_id and self.fatturapa_attachment_in_id and self.fatturapa_payments:
19+
self.fatturapa_retrieve_due_dates = self.partner_id.fatturapa_retrieve_due_dates
20+
else:
21+
self.fatturapa_retrieve_due_dates = False
22+
23+
def _get_payment_data_from_fatturapa(self):
24+
"""Extract payment data from fatturapa.payment.data model."""
25+
self.ensure_one()
26+
payment_data = []
27+
payment_data_records = self.fatturapa_payments
28+
29+
for payment_data_record in payment_data_records:
30+
for payment_detail in payment_data_record.payment_methods:
31+
if payment_detail.payment_due_date and payment_detail.payment_amount:
32+
payment_data.append({
33+
'date': payment_detail.payment_due_date,
34+
'amount': payment_detail.payment_amount
35+
})
36+
37+
return payment_data
38+
39+
@api.multi
40+
def action_move_create(self):
41+
"""Override to use payment terms from XML if configured."""
42+
# Process invoices that need XML payment terms
43+
invoices_with_xml_terms = self.env['account.invoice']
44+
invoices_without_xml_terms = self.env['account.invoice']
45+
46+
for invoice in self:
47+
if invoice.fatturapa_retrieve_due_dates:
48+
payment_data = invoice._get_payment_data_from_fatturapa()
49+
if payment_data:
50+
invoices_with_xml_terms |= invoice.with_context(force_totlines=payment_data)
51+
else:
52+
invoices_without_xml_terms |= invoice
53+
else:
54+
invoices_without_xml_terms |= invoice
55+
56+
# Process invoices with XML terms
57+
if invoices_with_xml_terms:
58+
super(AccountInvoice, invoices_with_xml_terms).action_move_create()
59+
60+
# Process remaining invoices
61+
if invoices_without_xml_terms:
62+
super(AccountInvoice, invoices_without_xml_terms).action_move_create()
63+
64+
return True
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2025 Lorenzo Battistini
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, models, fields
5+
6+
7+
class AccountPaymentTerm(models.Model):
8+
_inherit = 'account.payment.term'
9+
10+
def compute(self, value, date_ref=False):
11+
"""Override to use forced payment lines from XML if provided."""
12+
if self.env.context.get('force_totlines'):
13+
# Return the forced payment lines from XML
14+
payment_data = self.env.context.get('force_totlines')
15+
result = []
16+
for payment in payment_data:
17+
result.append((payment['date'], payment['amount']))
18+
return result
19+
20+
# Otherwise use standard computation
21+
return super(AccountPaymentTerm, self).compute(value, date_ref)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2025 Lorenzo Battistini
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class ResPartner(models.Model):
8+
_inherit = 'res.partner'
9+
10+
fatturapa_retrieve_due_dates = fields.Boolean(
11+
string="Retrieve due dates from XML",
12+
help="If set, payment terms will be retrieved from the XML "
13+
"when creating invoices from electronic invoices."
14+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
To configure this module:
2+
3+
1. Go to a partner form
4+
2. Open the "Electronic Invoice" tab
5+
3. Check "Retrieve due dates from XML" to enable automatic payment terms retrieval for this partner
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Lorenzo Battistini
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This module extends the FatturaPA import functionality to automatically retrieve payment terms from the XML invoice.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
When importing an electronic invoice (FatturaPA):
2+
3+
1. If the partner has "Retrieve due dates from XML" enabled, the system will automatically set this option on the invoice
4+
2. When you validate the invoice, the system will:
5+
- Read the DatiPagamento section from the XML
6+
- Extract DataScadenzaPagamento (due date) and ImportoPagamento (amount) for each payment line
7+
- Generate account.move.line entries accordingly
8+
- Validate that the total amount matches the invoice total
9+
10+
The payment data is extracted from:
11+
- DatiPagamento/DettaglioPagamento/DataScadenzaPagamento (due date)
12+
- DatiPagamento/DettaglioPagamento/ImportoPagamento (amount)

0 commit comments

Comments
 (0)