Skip to content

Commit

Permalink
[IMP] l10n_es_aeat_mod349: Don't mangle VAT number
Browse files Browse the repository at this point in the history
There's a VAT formatting method that adds country code if not present
in the partner vat. This method is not useful at all, as all European
VAT numbers should have country prefix for being validated in invoices,
so there's not too much sense to try to reformat it. There are also
cases where a big company has one country VAT number, but has fiscal
address in other country, resulting in an incorrect reformating.

Not even that, there are old style onchanges that are not ever
triggered, as the XML declaration disappeared or is not effective as the
view is readonly, becoming dead code.

This commit removes all this stuff, with no expected side effects.
  • Loading branch information
pedrobaeza committed Sep 10, 2021
1 parent 5544690 commit 467afaa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 46 deletions.
48 changes: 3 additions & 45 deletions l10n_es_aeat_mod349/models/mod349.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,19 @@
# Copyright 2004-2011 - Pexego Sistemas Informáticos. (http://pexego.es)
# Copyright 2013 - Top Consultant Software Creations S.L.
# - (http://www.topconsultant.es/)
# Copyright 2014-2020 Tecnativa - Pedro M. Baeza
# Copyright 2014-2021 Tecnativa - Pedro M. Baeza
# Copyright 2016 - Tecnativa - Angel Moya <odoo@tecnativa.com>
# Copyright 2017 - Tecnativa - Luis M. Ontalba <luis.martinez@tecnativa.com>
# Copyright 2017 - Eficent Business and IT Consulting Services, S.L.
# <contact@eficent.com>
# Copyright 2018 - Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import math
import re
from odoo import models, fields, api, exceptions, _
from odoo.fields import first
from odoo.tools import float_is_zero


def _format_partner_vat(partner_vat=None, country=None):
"""Formats VAT to match XXVATNUMBER (where XX is country code).
An exception is made with Greece, that has a different prefix than its
country code.
"""
if country.code:
code = country.code
if code == 'GR':
code = 'EL'
country_pattern = "%s|%s.*" % (code, code.lower())
vat_regex = re.compile(country_pattern, re.UNICODE | re.X)
if partner_vat and not vat_regex.match(partner_vat):
partner_vat = code + partner_vat
return partner_vat


class Mod349(models.Model):
_inherit = "l10n.es.aeat.report"
_name = "l10n.es.aeat.mod349.report"
Expand Down Expand Up @@ -159,10 +141,7 @@ def _create_349_invoice_records(self):
record_created = rec_obj.create({
'report_id': self.id,
'partner_id': partner.id,
'partner_vat': _format_partner_vat(
partner_vat=partner.vat,
country=partner.country_id,
),
'partner_vat': partner.vat,
'operation_key': op_key,
'country_id': partner.country_id.id,
})
Expand Down Expand Up @@ -258,10 +237,7 @@ def _create_349_refund_records(self):
partner_refund = obj.create({
'report_id': self.id,
'partner_id': partner.id,
'partner_vat': _format_partner_vat(
partner_vat=partner.vat,
country=partner.country_id,
),
'partner_vat': partner.vat,
'operation_key': op_key,
'country_id': partner.country_id.id,
'total_origin_amount': key_vals['original_amount'],
Expand Down Expand Up @@ -429,15 +405,6 @@ def _compute_total_operation_amount(self):
record.mapped('record_detail_ids.amount_untaxed')
)

@api.multi
def onchange_format_partner_vat(self, partner_vat, country_id):
"""Formats VAT to match XXVATNUMBER (where XX is country code)"""
if country_id:
country = self.env['res.country'].browse(country_id)
partner_vat = _format_partner_vat(partner_vat=partner_vat,
country=country)
return {'value': {'partner_vat': partner_vat}}


class Mod349PartnerRecordDetail(models.Model):
"""AEAT 349 Model - Partner record detail
Expand Down Expand Up @@ -549,15 +516,6 @@ def _compute_total_operation_amount(self):
record.total_origin_amount - rectified_amount
)

@api.multi
def onchange_format_partner_vat(self, partner_vat, country_id):
"""Formats VAT to match XXVATNUMBER (where XX is country code)"""
if country_id:
country = self.env['res.country'].browse(country_id)
partner_vat = _format_partner_vat(partner_vat=partner_vat,
country=country)
return {'value': {'partner_vat': partner_vat}}


class Mod349PartnerRefundDetail(models.Model):
_name = 'l10n.es.aeat.mod349.partner_refund_detail'
Expand Down
2 changes: 1 addition & 1 deletion l10n_es_aeat_mod349/views/mod349_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<field name="operation_key"/>
<field name="partner_id"/>
<field name="country_id"/>
<field name="partner_vat" on_change="onchange_format_partner_vat(partner_vat,country_id)"/>
<field name="partner_vat"/>
<field name="total_operation_amount"/>
</group>
</page>
Expand Down

0 comments on commit 467afaa

Please sign in to comment.