Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.0][IMP] Crea método para obtener si una factura se enviará como simplificada o completa #1409

Merged
merged 1 commit into from
Jul 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions l10n_es_aeat_sii/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.")
)
Expand Down Expand Up @@ -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": {
Expand All @@ -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": (
Expand Down Expand Up @@ -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],
Expand Down
16 changes: 16 additions & 0 deletions l10n_es_aeat_sii/tests/test_l10n_es_aeat_sii.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()