diff --git a/l10n_es_aeat_sii/models/account_invoice.py b/l10n_es_aeat_sii/models/account_invoice.py index e7ac1459eaf..f2b4c3960e0 100755 --- a/l10n_es_aeat_sii/models/account_invoice.py +++ b/l10n_es_aeat_sii/models/account_invoice.py @@ -618,6 +618,14 @@ def _get_sii_in_taxes(self): ) return taxes_dict, tax_amount + @api.multi + def _is_sii_simplified_invoice(self): + """Inheritable method to allow control when an + invoice are simplified or normal""" + partner = self.partner_id.commercial_partner_id + is_simplified = partner.sii_simplified_invoice + return is_simplified + @api.multi def _sii_check_exceptions(self): """Inheritable method for exceptions control when sending SII invoices. @@ -626,12 +634,14 @@ def _sii_check_exceptions(self): gen_type = self._get_sii_gen_type() partner = self.partner_id.commercial_partner_id country_code = self._get_sii_country_code() - if partner.sii_simplified_invoice and self.type[:2] == 'in': + is_simplified_invoice = self._is_sii_simplified_invoice() + + if is_simplified_invoice and self.type[:2] == 'in': raise exceptions.Warning( _("You can't make a supplier simplified invoice.") ) if ((gen_type != 3 or country_code == 'ES') and - not partner.vat and not partner.sii_simplified_invoice): + not partner.vat and not is_simplified_invoice): raise exceptions.Warning( _("The partner has not a VAT configured.") ) @@ -679,6 +689,7 @@ def _get_sii_invoice_dict_out(self, cancel=False): company = self.company_id ejercicio = fields.Date.to_date(self.date).year periodo = '%02d' % fields.Date.to_date(self.date).month + is_simplified_invoice = self._is_sii_simplified_invoice() inv_dict = { "IDFactura": { "IDEmisorFactura": { @@ -698,14 +709,13 @@ def _get_sii_invoice_dict_out(self, cancel=False): if not cancel: # Check if refund type is 'By differences'. Negative amounts! sign = self._get_sii_sign() - simplied = partner.sii_simplified_invoice if self.type == 'out_refund': if self.sii_refund_specific_invoice_type: tipo_factura = self.sii_refund_specific_invoice_type else: - tipo_factura = 'R5' if simplied else 'R1' + tipo_factura = 'R5' if is_simplified_invoice else 'R1' else: - tipo_factura = 'F2' if simplied else 'F1' + tipo_factura = 'F2' if is_simplified_invoice else 'F1' inv_dict["FacturaExpedida"] = { "TipoFactura": tipo_factura, "ClaveRegimenEspecialOTrascendencia": ( @@ -736,7 +746,7 @@ def _get_sii_invoice_dict_out(self, cancel=False): } } exp_dict = inv_dict['FacturaExpedida'] - if not partner.sii_simplified_invoice: + if not is_simplified_invoice: # Simplified invoices don't have counterpart exp_dict["Contraparte"] = { "NombreRazon": partner.name[0:120], diff --git a/l10n_es_aeat_sii/tests/test_l10n_es_aeat_sii.py b/l10n_es_aeat_sii/tests/test_l10n_es_aeat_sii.py index 4c44604548b..a887eb2d99e 100755 --- a/l10n_es_aeat_sii/tests/test_l10n_es_aeat_sii.py +++ b/l10n_es_aeat_sii/tests/test_l10n_es_aeat_sii.py @@ -357,3 +357,19 @@ def test_refund_sii_refund_type_write(self): self.assertFalse(invoice.sii_refund_type) invoice.type = 'out_refund' self.assertEqual(invoice.sii_refund_type, 'I') + + def test_is_sii_simplified_invoice(self): + self.assertFalse(self.invoice._is_sii_simplified_invoice()) + self.partner.sii_simplified_invoice = True + self.assertTrue(self.invoice._is_sii_simplified_invoice()) + + def test_sii_check_exceptions_case_supplier_simplified(self): + self.partner.is_simplified_invoice = True + invoice = self.env['account.invoice'].create({ + 'partner_id': self.partner.id, + 'date_invoice': '2018-02-01', + 'type': 'in_invoice', + 'account_id': self.partner.property_account_payable_id.id, + }) + with self.assertRaises(exceptions.Warning): + invoice._sii_check_exceptions()