From 99ef61b665053089dc76c2616e73ce6ef46ae919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Garc=C3=ADa?= Date: Thu, 30 Jan 2020 12:45:14 +0100 Subject: [PATCH 1/2] Fixes VAT in new model 193 records Fixes VAT in new model 193 records --- .../wizard/wizard_aeat193_from_gkwh_invoices.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/som_generationkwh/wizard/wizard_aeat193_from_gkwh_invoices.py b/som_generationkwh/wizard/wizard_aeat193_from_gkwh_invoices.py index 09c94beb..a90f3c1f 100644 --- a/som_generationkwh/wizard/wizard_aeat193_from_gkwh_invoices.py +++ b/som_generationkwh/wizard/wizard_aeat193_from_gkwh_invoices.py @@ -96,8 +96,11 @@ def do_action(self, cursor, uid, ids, context=None): _(u"L'adreça amb ID {} pel partner amb VAT {} no té definida província. " u"Aquesta és necessària pel procés. Si us plau revisi les dades."). format(part_add_id, partner_vat)) + + partner_nif = partner_vat.replace('ES', '') + search_params = [ - ('partner_vat', '=', partner_vat), + ('partner_vat', 'ilike', '%{}%'.format(partner_nif)), ('report_id', '=', report.id), ('tax_percent', '=', abs(wiz.tax_id.amount) * 100) ] @@ -105,7 +108,7 @@ def do_action(self, cursor, uid, ids, context=None): vals = common_vals.copy() vals.update({ 'partner_id': partner_id, - 'partner_vat': partner_vat, + 'partner_vat': partner_nif, 'amount': amount, 'amount_base': amount, 'amount_tax': amount * abs(wiz.tax_id.amount), From bafdc0fc327561ae11ebc80fcd6e71ab9447a7ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Garc=C3=ADa?= Date: Thu, 30 Jan 2020 20:06:01 +0100 Subject: [PATCH 2/2] It's not necessary to add amount to existing lines, just create new ones It's not necessary to add amount to existing lines, just create new ones --- .../wizard_aeat193_from_gkwh_invoices.py | 30 +++---------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/som_generationkwh/wizard/wizard_aeat193_from_gkwh_invoices.py b/som_generationkwh/wizard/wizard_aeat193_from_gkwh_invoices.py index a90f3c1f..71421670 100644 --- a/som_generationkwh/wizard/wizard_aeat193_from_gkwh_invoices.py +++ b/som_generationkwh/wizard/wizard_aeat193_from_gkwh_invoices.py @@ -79,7 +79,6 @@ def do_action(self, cursor, uid, ids, context=None): cursor.execute(query, dict(start=dates['start'], end=dates['end'])) new_linies = 0 - updated_lines = 0 for data in cursor.fetchall(): partner_id = data[0] partner_vat = data[1] @@ -98,13 +97,6 @@ def do_action(self, cursor, uid, ids, context=None): format(part_add_id, partner_vat)) partner_nif = partner_vat.replace('ES', '') - - search_params = [ - ('partner_vat', 'ilike', '%{}%'.format(partner_nif)), - ('report_id', '=', report.id), - ('tax_percent', '=', abs(wiz.tax_id.amount) * 100) - ] - vals = common_vals.copy() vals.update({ 'partner_id': partner_id, @@ -118,24 +110,10 @@ def do_action(self, cursor, uid, ids, context=None): 'fiscal_address_id': part_add_id[0] }) - record_ids = record_obj.search(cursor, uid, search_params) - if record_ids: - if len(record_ids) > 1: - raise osv.except_osv("Error", - _(u"S'ha trobat més d'una línia per al client amb VAT '{0}'. I per la taxa" - u"Revisin les dades si us plau."). - format(partner_vat)) - record_vals = record_obj.read(cursor, uid, record_ids[0], ['amount', 'amount_base', 'amount_tax']) - record_vals.pop('id') - for key, value in record_vals: - record_vals[key] = value + vals[key] - record_obj.write(cursor, uid, record_ids[0], record_vals) - updated_lines += 1 - else: - record_obj.create(cursor, uid, vals) - new_linies += 1 - - txt += u'\nAfegides {} línies al model 193 i modificades {} de les existents'.format(new_linies, updated_lines) + record_obj.create(cursor, uid, vals) + new_linies += 1 + + txt += u'\nAfegides {} línies al model 193.'.format(new_linies) wiz.write({'info': txt, 'state': 'done'})