11# © 2017 FactorLibre - Hugo Santos <hugo.santos@factorlibre.com>
22# © 2018 FactorLibre - Victor Rodrigo <victor.rodrigo@factorlibre.com>
33# © 2022 ProcessControl - David Ramia <david.ramia@processcontrol.es>
4+ # Copyright 2026 Tecnativa - Carlos Dauden
45# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
5- from odoo import _ , exceptions , fields , models
6+ from odoo import _ , fields , models
67
78
89class AccountMove (models .Model ):
@@ -12,54 +13,40 @@ class AccountMove(models.Model):
1213 sii_invoice_summary_start = fields .Char ("SII Invoice Summary: First Invoice" )
1314 sii_invoice_summary_end = fields .Char ("SII Invoice Summary: Last Invoice" )
1415
16+ def _is_aeat_summary_invoice (self ):
17+ if (
18+ self .is_invoice_summary
19+ and self .is_sale_document ()
20+ and self .sii_invoice_summary_start != self .sii_invoice_summary_end
21+ ):
22+ return True
23+ return False
24+
25+ def _is_aeat_simplified_invoice (self ):
26+ # En el SII, una factura resumen (F4) debe considerarse, a efectos de estructura
27+ # y validaciones, equivalente a una factura simplificada (F2), compartiendo
28+ # todas sus restricciones y campos obligatorios, con la única diferencia de
29+ # requerir la clave TipoFactura = F4 y el campo adicional
30+ # NumSerieFacturaEmisorResumenFin
31+ return self .is_invoice_summary or super ()._is_aeat_simplified_invoice ()
32+
1533 def _get_sii_invoice_type (self ):
16- if self .is_invoice_summary and self .is_sale_document ():
17- if self .move_type == "out_refund" :
18- # TODO: It may not be necessary since a summary invoice implies
19- # simplified invoice
20- invoice_type = "R5"
21- elif self .sii_invoice_summary_start == self .sii_invoice_summary_end :
22- invoice_type = "F2"
23- else :
24- invoice_type = "F4"
25- else :
26- invoice_type = super ()._get_sii_invoice_type ()
34+ invoice_type = super ()._get_sii_invoice_type ()
35+ if self ._is_aeat_summary_invoice () and invoice_type == "F2" :
36+ invoice_type = "F4"
2737 return invoice_type
2838
2939 def _get_aeat_invoice_dict_out (self , cancel = False ):
3040 inv_dict = super ()._get_aeat_invoice_dict_out (cancel = cancel )
31- if self .is_invoice_summary and self .is_sale_document ():
32- if self .sii_invoice_summary_start != self .sii_invoice_summary_end :
33- inv_dict ["IDFactura" ][
34- "NumSerieFacturaEmisor"
35- ] = self .sii_invoice_summary_start
36- inv_dict ["IDFactura" ][
37- "NumSerieFacturaEmisorResumenFin"
38- ] = self .sii_invoice_summary_end
39- # TODO: It may not be necessary since a summary invoice implies
40- # simplified invoice
41- if inv_dict .get ("FacturaExpedida" , {}).get ("Contraparte" ):
42- del inv_dict ["FacturaExpedida" ]["Contraparte" ]
41+ if inv_dict .get ("FacturaExpedida" , {}).get ("TipoFactura" , "" ) == "F4" :
42+ inv_dict ["IDFactura" ][
43+ "NumSerieFacturaEmisor"
44+ ] = self .sii_invoice_summary_start
45+ inv_dict ["IDFactura" ][
46+ "NumSerieFacturaEmisorResumenFin"
47+ ] = self .sii_invoice_summary_end
4348 return inv_dict
4449
45- def _aeat_check_exceptions (self ):
46- """Inheritable method for exceptions control when sending SII invoices."""
47- res = False
48- try :
49- res = super ()._aeat_check_exceptions ()
50- except exceptions .UserError as e :
51- if (
52- e .args [0 ] == _ ("The partner has not a VAT configured." )
53- and self .is_invoice_summary
54- ):
55- pass
56- else :
57- raise
58-
59- if self .is_invoice_summary and self .is_purchase_document ():
60- raise exceptions .UserError (_ ("You can't make a supplier summary invoice." ))
61- return res
62-
6350 def write (self , vals ):
6451 """Cannot let change sii_invoice_summary fields
6552 values in a SII registered supplier invoice"""
0 commit comments