Skip to content

Commit

Permalink
Merge ac1cb0d into 1af0b72
Browse files Browse the repository at this point in the history
  • Loading branch information
eantones committed May 29, 2019
2 parents 1af0b72 + ac1cb0d commit 38e5f60
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
52 changes: 33 additions & 19 deletions l10n_es_aeat_sii/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ def empty_decorator_factory(*argv, **kwargs):
}
SII_MACRODATA_LIMIT = 100000000.0

def round_by_keys(elem, search_keys, prec=2):
""" This uses ``round`` method directly as if has been tested that Odoo's
``float_round`` still returns incorrect amounts for certain values. Try
3 units x 3,77 €/unit with 10% tax and you will be hit by the error
(on regular x86 architectures)."""
if isinstance(elem, dict):
for key, value in elem.items():
if key in search_keys:
elem[key] = round(elem[key], prec)
else:
round_by_keys(value, search_keys)
elif isinstance(elem, list):
for value in elem:
round_by_keys(value, search_keys)

class AccountInvoice(models.Model):
_inherit = 'account.invoice'
Expand Down Expand Up @@ -387,11 +401,6 @@ def _get_sii_tax_line_req(self, tax):
def _get_sii_tax_dict(self, tax_line, sign):
"""Get the SII tax dictionary for the passed tax line.
This uses ``round`` method directly as if has been tested that Odoo's
``float_round`` still returns incorrect amounts for certain values. Try
3 units x 3,77 €/unit with 10% tax and you will be hit by the error
(on regular x86 architectures).
:param self: Single invoice record.
:param tax_line: Tax line that is being analyzed.
:param sign: Sign of the operation (only refund by differences is
Expand All @@ -405,21 +414,21 @@ def _get_sii_tax_dict(self, tax_line, sign):
tax_type = abs(tax.amount)
tax_dict = {
'TipoImpositivo': str(tax_type),
'BaseImponible': sign * abs(round(tax_line.base_company, 2)),
'BaseImponible': sign * abs(tax_line.base_company),
}
if self.type in ['out_invoice', 'out_refund']:
key = 'CuotaRepercutida'
else:
key = 'CuotaSoportada'
tax_dict[key] = sign * abs(round(tax_line.amount_company, 2))
tax_dict[key] = sign * abs(tax_line.amount_company)
# Recargo de equivalencia
re_tax_line = self._get_sii_tax_line_req(tax)
if re_tax_line:
tax_dict['TipoRecargoEquivalencia'] = (
abs(re_tax_line.tax_id.amount)
)
tax_dict['CuotaRecargoEquivalencia'] = (
sign * abs(round(re_tax_line.amount_company, 2))
sign * abs(re_tax_line.amount_company)
)
return tax_dict

Expand Down Expand Up @@ -490,7 +499,7 @@ def _get_sii_out_taxes(self):
if exempt_cause:
det_dict['CausaExencion'] = exempt_cause
det_dict['BaseImponible'] += (
round(tax_line.base_company, 2) * sign)
tax_line.base_company * sign)
else:
sub_dict.setdefault('NoExenta', {
'TipoNoExenta': (
Expand All @@ -516,7 +525,7 @@ def _get_sii_out_taxes(self):
'NoSujeta', {default_no_taxable_cause: 0},
)
nsub_dict[default_no_taxable_cause] += (
round(tax_line.base_company, 2) * sign)
tax_line.base_company * sign)
if tax in (taxes_sfess + taxes_sfesse + taxes_sfesns):
type_breakdown = taxes_dict.setdefault(
'DesgloseTipoOperacion', {
Expand All @@ -536,7 +545,7 @@ def _get_sii_out_taxes(self):
if exempt_cause:
det_dict['CausaExencion'] = exempt_cause
det_dict['BaseImponible'] += (
round(tax_line.base_company, 2) * sign)
tax_line.base_company * sign)
if tax in taxes_sfess:
# TODO l10n_es_ no tiene impuesto ISP de servicios
# if tax in taxes_sfesisps:
Expand Down Expand Up @@ -568,6 +577,13 @@ def _get_sii_out_taxes(self):
taxes_dict['DesgloseTipoOperacion']['Entrega'] = \
taxes_dict['DesgloseFactura']
del taxes_dict['DesgloseFactura']
round_by_keys(taxes_dict, [
'BaseImponible', 'CuotaRepercutida', 'CuotaSoportada',
'TipoRecargoEquivalencia', 'CuotaRecargoEquivalencia',
'ImportePorArticulos7_14_Otros', 'ImporteTAIReglasLocalizacion',
'ImporteTotal', 'BaseRectificada', 'CuotaRectificada',
'CuotaDeducible'
])
return taxes_dict

@api.multi
Expand Down Expand Up @@ -609,7 +625,7 @@ def _get_sii_in_taxes(self):
'DesgloseIVA', {'DetalleIVA': []},
)
sfrns_dict['DetalleIVA'].append({
'BaseImponible': sign * round(tax_line.base_company, 2),
'BaseImponible': sign * tax_line.base_company,
})
elif tax in taxes_sfrsa:
sfrsa_dict = taxes_dict.setdefault(
Expand Down Expand Up @@ -728,7 +744,7 @@ def _get_sii_invoice_dict_out(self, cancel=False):
"DescripcionOperacion": self.sii_description,
"TipoDesglose": self._get_sii_out_taxes(),
"ImporteTotal": abs(
round(self.amount_total_company_signed, 2)
self.amount_total_company_signed
) * sign,
}
if self.sii_macrodata:
Expand Down Expand Up @@ -762,14 +778,12 @@ def _get_sii_invoice_dict_out(self, cancel=False):
if self.sii_refund_type == 'S':
origin = self.refund_invoice_id
exp_dict['ImporteRectificacion'] = {
'BaseRectificada': round(
abs(origin.amount_untaxed_signed), 2,
'BaseRectificada': abs(
origin.amount_untaxed_signed
),
'CuotaRectificada': round(
abs(
'CuotaRectificada': abs(
origin.amount_total_company_signed -
origin.amount_untaxed_signed
), 2,
),
}
return inv_dict
Expand Down Expand Up @@ -831,7 +845,7 @@ def _get_sii_invoice_dict_in(self, cancel=False):
},
"FechaRegContable": reg_date,
"ImporteTotal": abs(self.amount_total_company_signed) * sign,
"CuotaDeducible": round(tax_amount * sign, 2),
"CuotaDeducible": tax_amount * sign,
}
if self.sii_macrodata:
inv_dict["FacturaRecibida"].update(Macrodato="S")
Expand Down
1 change: 1 addition & 0 deletions l10n_es_aeat_sii/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
* Javi Melendez <javimelex@gmail.com>
* Santi Argüeso - Comunitea S.L. <santi@comunitea.com>
* Angel Moya - PESOL <angel.moya@pesol.es>
* Eric Antonés - NuoBiT Solutions, S.L. <eantones@nuobit.com>

0 comments on commit 38e5f60

Please sign in to comment.