From a8a00c8cc4dea8bcbfea01481505443316e86cd9 Mon Sep 17 00:00:00 2001 From: Alex Comba Date: Fri, 22 Dec 2017 08:26:57 +0100 Subject: [PATCH] [FIX] account_vat_period_end_statement: get migration script multi company compliant (#428) [FIX] account_vat_period_end_statement: check move_id exists to get statement_draft properly working (#435) move_id needs to be checked if exists in the computed fields, otherwise the method unlink, during the fields recomputation, raises a MissingError for them [FIX] account_vat_period_end_statement: post move + cancel move (#436) [IMP] account_vat_period_end_statement: allow to adviser to manage date.range and date.range.type Otherwise a user who belongs to adviser group cannot add a date.range to vat statement [FIX] Move menu related to date range to l10n_it_account module --- .../__manifest__.py | 2 +- account_vat_period_end_statement/i18n/it.po | 26 +++++++------- account_vat_period_end_statement/i18n/sl.po | 26 +++++++------- .../post-migrate.py | 21 ++++++++---- .../models/account.py | 34 +++++++++++-------- .../security/ir.model.access.csv | 20 ++++++----- 6 files changed, 72 insertions(+), 57 deletions(-) rename account_vat_period_end_statement/migrations/{10.0.1.2.0 => 10.0.1.3.0}/post-migrate.py (68%) diff --git a/account_vat_period_end_statement/__manifest__.py b/account_vat_period_end_statement/__manifest__.py index efdac80af5a1..475f5421fa02 100644 --- a/account_vat_period_end_statement/__manifest__.py +++ b/account_vat_period_end_statement/__manifest__.py @@ -26,7 +26,7 @@ { "name": "Period End VAT Statement", - "version": "10.0.1.2.0", + "version": "10.0.1.4.2", 'category': 'Generic Modules/Accounting', 'license': 'AGPL-3', "depends": [ diff --git a/account_vat_period_end_statement/i18n/it.po b/account_vat_period_end_statement/i18n/it.po index 9e6757367604..4d824ca16e8e 100644 --- a/account_vat_period_end_statement/i18n/it.po +++ b/account_vat_period_end_statement/i18n/it.po @@ -8,8 +8,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 10.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-12-08 03:45+0000\n" -"PO-Revision-Date: 2017-12-08 03:45+0000\n" +"POT-Creation-Date: 2018-01-16 06:17+0000\n" +"PO-Revision-Date: 2018-01-16 06:17+0000\n" "Last-Translator: OCA Transbot , 2017\n" "Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\n" "MIME-Version: 1.0\n" @@ -169,7 +169,7 @@ msgid "Credit Account Lines" msgstr "Righe conti di credito" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:347 +#: code:addons/account_vat_period_end_statement/models/account.py:352 #: model:ir.model.fields,field_description:account_vat_period_end_statement.field_account_vat_period_end_statement_credit_vat_account_line_ids #, python-format msgid "Credit VAT" @@ -198,7 +198,7 @@ msgid "Debit Account Lines" msgstr "Righe conti di debito" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:328 +#: code:addons/account_vat_period_end_statement/models/account.py:333 #: model:ir.model.fields,field_description:account_vat_period_end_statement.field_account_vat_period_end_statement_debit_vat_account_line_ids #, python-format msgid "Debit VAT" @@ -242,7 +242,7 @@ msgid "Draft" msgstr "Bozza" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:423 +#: code:addons/account_vat_period_end_statement/models/account.py:428 #: model:ir.model.fields,field_description:account_vat_period_end_statement.field_account_vat_period_end_statement_interests_debit_vat_account_id #: model:ir.ui.view,arch_db:account_vat_period_end_statement.report_vatperiodendstatement_document #: model:ir.ui.view,arch_db:account_vat_period_end_statement.view_account_vat_period_end_statement @@ -343,7 +343,7 @@ msgid "Last printed page" msgstr "Ultima pagina stampata" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:442 +#: code:addons/account_vat_period_end_statement/models/account.py:447 #, python-format msgid "Other VAT Credits / Debits" msgstr "Altri Crediti / Debiti per IVA" @@ -407,7 +407,7 @@ msgid "Periods" msgstr "Periodi" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:366 +#: code:addons/account_vat_period_end_statement/models/account.py:371 #: model:ir.model.fields,field_description:account_vat_period_end_statement.field_account_vat_period_end_statement_previous_credit_vat_account_id #: model:ir.ui.view,arch_db:account_vat_period_end_statement.view_account_vat_period_end_statement #, python-format @@ -420,7 +420,7 @@ msgid "Previous Credits VAT Amount" msgstr "Importo IVA crediti precedenti" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:404 +#: code:addons/account_vat_period_end_statement/models/account.py:409 #: model:ir.model.fields,field_description:account_vat_period_end_statement.field_account_vat_period_end_statement_previous_debit_vat_account_id #: model:ir.ui.view,arch_db:account_vat_period_end_statement.view_account_vat_period_end_statement #, python-format @@ -521,7 +521,7 @@ msgid "Tax Authority Partner" msgstr "Partner Erario" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:458 +#: code:addons/account_vat_period_end_statement/models/account.py:463 #, python-format msgid "Tax Authority VAT" msgstr "IVA Erario" @@ -532,7 +532,7 @@ msgid "Tax Authority VAT Account" msgstr "Conto IVA Erario" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:385 +#: code:addons/account_vat_period_end_statement/models/account.py:390 #, python-format msgid "Tax Credits" msgstr "Crediti d'imposta" @@ -550,7 +550,7 @@ msgid "Tax credits Amount" msgstr "Importo crediti d'imposta" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:623 +#: code:addons/account_vat_period_end_statement/models/account.py:629 #, python-format msgid "The account for vat interest must be configurated" msgstr "Il conto per gli interessi IVA deve essere configurato" @@ -595,7 +595,7 @@ msgid "Undeductible" msgstr "Non detraibile" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:316 +#: code:addons/account_vat_period_end_statement/models/account.py:321 #: model:ir.model.fields,field_description:account_vat_period_end_statement.field_date_range_vat_statement_id #: model:ir.model.fields,field_description:account_vat_period_end_statement.field_statement_credit_account_line_statement_id #: model:ir.model.fields,field_description:account_vat_period_end_statement.field_statement_debit_account_line_statement_id @@ -628,7 +628,7 @@ msgid "Vat statement" msgstr "Liquidazione IVA" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:274 +#: code:addons/account_vat_period_end_statement/models/account.py:278 #, python-format msgid "You cannot delete a confirmed or paid statement" msgstr "Non è possibile eliminare una liquidazione confermata o pagata" diff --git a/account_vat_period_end_statement/i18n/sl.po b/account_vat_period_end_statement/i18n/sl.po index f32688f2dfcb..93b3e3d3d721 100644 --- a/account_vat_period_end_statement/i18n/sl.po +++ b/account_vat_period_end_statement/i18n/sl.po @@ -8,8 +8,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 10.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-12-08 03:45+0000\n" -"PO-Revision-Date: 2017-12-08 03:45+0000\n" +"POT-Creation-Date: 2018-01-16 06:17+0000\n" +"PO-Revision-Date: 2018-01-16 06:17+0000\n" "Last-Translator: OCA Transbot , 2017\n" "Language-Team: Slovenian (https://www.transifex.com/oca/teams/23907/sl/)\n" "MIME-Version: 1.0\n" @@ -169,7 +169,7 @@ msgid "Credit Account Lines" msgstr "Postavke konta terjatev" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:347 +#: code:addons/account_vat_period_end_statement/models/account.py:352 #: model:ir.model.fields,field_description:account_vat_period_end_statement.field_account_vat_period_end_statement_credit_vat_account_line_ids #, python-format msgid "Credit VAT" @@ -198,7 +198,7 @@ msgid "Debit Account Lines" msgstr "Postavke konta obveznosti" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:328 +#: code:addons/account_vat_period_end_statement/models/account.py:333 #: model:ir.model.fields,field_description:account_vat_period_end_statement.field_account_vat_period_end_statement_debit_vat_account_line_ids #, python-format msgid "Debit VAT" @@ -242,7 +242,7 @@ msgid "Draft" msgstr "Osnutek" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:423 +#: code:addons/account_vat_period_end_statement/models/account.py:428 #: model:ir.model.fields,field_description:account_vat_period_end_statement.field_account_vat_period_end_statement_interests_debit_vat_account_id #: model:ir.ui.view,arch_db:account_vat_period_end_statement.report_vatperiodendstatement_document #: model:ir.ui.view,arch_db:account_vat_period_end_statement.view_account_vat_period_end_statement @@ -343,7 +343,7 @@ msgid "Last printed page" msgstr "Zadnja natisnjena stran" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:442 +#: code:addons/account_vat_period_end_statement/models/account.py:447 #, python-format msgid "Other VAT Credits / Debits" msgstr "Druge DDV terjatve / obveznosti" @@ -407,7 +407,7 @@ msgid "Periods" msgstr "Obdobja" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:366 +#: code:addons/account_vat_period_end_statement/models/account.py:371 #: model:ir.model.fields,field_description:account_vat_period_end_statement.field_account_vat_period_end_statement_previous_credit_vat_account_id #: model:ir.ui.view,arch_db:account_vat_period_end_statement.view_account_vat_period_end_statement #, python-format @@ -420,7 +420,7 @@ msgid "Previous Credits VAT Amount" msgstr "Znesek prejšnjih DDV v dobro" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:404 +#: code:addons/account_vat_period_end_statement/models/account.py:409 #: model:ir.model.fields,field_description:account_vat_period_end_statement.field_account_vat_period_end_statement_previous_debit_vat_account_id #: model:ir.ui.view,arch_db:account_vat_period_end_statement.view_account_vat_period_end_statement #, python-format @@ -521,7 +521,7 @@ msgid "Tax Authority Partner" msgstr "Partner davčni organ" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:458 +#: code:addons/account_vat_period_end_statement/models/account.py:463 #, python-format msgid "Tax Authority VAT" msgstr "DDV davčnega organa" @@ -532,7 +532,7 @@ msgid "Tax Authority VAT Account" msgstr "Konto DDV davčnega organa" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:385 +#: code:addons/account_vat_period_end_statement/models/account.py:390 #, python-format msgid "Tax Credits" msgstr "" @@ -550,7 +550,7 @@ msgid "Tax credits Amount" msgstr "" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:623 +#: code:addons/account_vat_period_end_statement/models/account.py:629 #, python-format msgid "The account for vat interest must be configurated" msgstr "Nastaviti morate konto za DDV obresti" @@ -593,7 +593,7 @@ msgid "Undeductible" msgstr "Neodbitni" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:316 +#: code:addons/account_vat_period_end_statement/models/account.py:321 #: model:ir.model.fields,field_description:account_vat_period_end_statement.field_date_range_vat_statement_id #: model:ir.model.fields,field_description:account_vat_period_end_statement.field_statement_credit_account_line_statement_id #: model:ir.model.fields,field_description:account_vat_period_end_statement.field_statement_debit_account_line_statement_id @@ -626,7 +626,7 @@ msgid "Vat statement" msgstr "DDV izjava" #. module: account_vat_period_end_statement -#: code:addons/account_vat_period_end_statement/models/account.py:274 +#: code:addons/account_vat_period_end_statement/models/account.py:278 #, python-format msgid "You cannot delete a confirmed or paid statement" msgstr "Potrjenih ali plačanih izjav ne morete brisati" diff --git a/account_vat_period_end_statement/migrations/10.0.1.2.0/post-migrate.py b/account_vat_period_end_statement/migrations/10.0.1.3.0/post-migrate.py similarity index 68% rename from account_vat_period_end_statement/migrations/10.0.1.2.0/post-migrate.py rename to account_vat_period_end_statement/migrations/10.0.1.3.0/post-migrate.py index b91f7e2b8f1f..a1f0a12ec2d2 100644 --- a/account_vat_period_end_statement/migrations/10.0.1.2.0/post-migrate.py +++ b/account_vat_period_end_statement/migrations/10.0.1.3.0/post-migrate.py @@ -23,22 +23,29 @@ def migrate(cr, version): """SELECT vat_statement_id, company_id, name, date_start, date_stop from account_period """) date_range_model = env['date.range'] - date_range_type = env['date.range.type'] + date_range_type_model = env['date.range.type'] periods = env.cr.fetchall() for period in periods: # if period has vat statement if period[0]: + date_range_type = date_range_type_model.search( + [('name', '=', 'periodo fiscale'), + ('company_id', '=', period[1]) + ]) + if not date_range_type: + date_range_type = date_range_type_model.create( + {'name': 'periodo fiscale', + 'company_id': period[1]}) date_range = date_range_model.search( [('date_start', '=', period[3]), - ('date_end', '=', period[4]) + ('date_end', '=', period[4]), + ('company_id', '=', period[1]) ]) if date_range: - date_range.write({'vat_statement_id': period[0]}) + date_range.write( + {'vat_statement_id': period[0], + 'type_id': date_range_type.id}) else: - if not date_range_type: - date_range_type = env['date.range.type'].create( - {'name': 'periodo fiscale'}) - date_range_type.company_id = period[1] date_range_vals = { 'vat_statement_id': period[0], 'company_id': period[1], diff --git a/account_vat_period_end_statement/models/account.py b/account_vat_period_end_statement/models/account.py index da24e4d12015..1d75c0d33178 100644 --- a/account_vat_period_end_statement/models/account.py +++ b/account_vat_period_end_statement/models/account.py @@ -70,13 +70,16 @@ def _compute_residual(self): precision = self.env.user.company_id.currency_id.decimal_places for statement in self: residual = 0.0 - if not statement.move_id: - statement.residual = 0.0 - statement.reconciled = False - return - for line in statement.move_id.line_ids: - if line.account_id.id == statement.authority_vat_account_id.id: - residual += line.amount_residual + if statement.move_id.exists(): + if not statement.move_id: + statement.residual = 0.0 + statement.reconciled = False + return + for line in statement.move_id.line_ids: + authority_vat_account_id = ( + statement.authority_vat_account_id.id) + if line.account_id.id == authority_vat_account_id: + residual += line.amount_residual statement.residual = abs(residual) if float_is_zero(statement.residual, precision_digits=precision): statement.reconciled = True @@ -88,13 +91,14 @@ def _compute_residual(self): def _compute_lines(self): for statement in self: payment_lines = [] - for line in statement.move_id.line_ids: - payment_lines.extend(filter(None, [ - rp.credit_move_id.id for rp in line.matched_credit_ids - ])) - payment_lines.extend(filter(None, [ - rp.debit_move_id.id for rp in line.matched_debit_ids - ])) + if statement.move_id.exists(): + for line in statement.move_id.line_ids: + payment_lines.extend(filter(None, [ + rp.credit_move_id.id for rp in line.matched_credit_ids + ])) + payment_lines.extend(filter(None, [ + rp.debit_move_id.id for rp in line.matched_debit_ids + ])) statement.payment_ids = self.env['account.move.line'].browse( list(set(payment_lines))) @@ -295,6 +299,7 @@ def _write(self, vals): def statement_draft(self): for statement in self: if statement.move_id: + statement.move_id.button_cancel() statement.move_id.unlink() statement.state = 'draft' @@ -484,6 +489,7 @@ def create_move(self): lines_to_create.append((0, 0, end_debit_vat_data)) move.line_ids = lines_to_create + move.post() statement.state = 'confirmed' return True diff --git a/account_vat_period_end_statement/security/ir.model.access.csv b/account_vat_period_end_statement/security/ir.model.access.csv index 941d4d0096fa..f65f35e23ecf 100644 --- a/account_vat_period_end_statement/security/ir.model.access.csv +++ b/account_vat_period_end_statement/security/ir.model.access.csv @@ -1,9 +1,11 @@ -"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" -"access_account_vat_period_end_statement_accountant","access_account_vat_period_end_statement_accountant","model_account_vat_period_end_statement","account.group_account_user","1","1","1","1" -"access_account_vat_period_end_statement_manager","access_account_vat_period_end_statement_manager","model_account_vat_period_end_statement","account.group_account_manager","1","1","1","1" -"access_statement_debit_account_line_accountant","access_statement_debit_account_line_accountant","model_statement_debit_account_line","account.group_account_user","1","1","1","1" -"access_statement_debit_account_line_manager","access_statement_debit_account_line_manager","model_statement_debit_account_line","account.group_account_manager","1","1","1","1" -"access_statement_credit_account_line_accountant","access_statement_credit_account_line_accountant","model_statement_credit_account_line","account.group_account_user","1","1","1","1" -"access_statement_credit_account_line_manager","access_statement_credit_account_line_manager","model_statement_credit_account_line","account.group_account_manager","1","1","1","1" -"access_statement_generic_account_line_accountant","access_statement_generic_account_line_accountant","model_statement_generic_account_line","account.group_account_user","1","1","1","1" -"access_statement_generic_account_line_manager","access_statement_generic_account_line_manager","model_statement_generic_account_line","account.group_account_manager","1","1","1","1" +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_account_vat_period_end_statement_accountant,access_account_vat_period_end_statement_accountant,model_account_vat_period_end_statement,account.group_account_user,1,1,1,1 +access_account_vat_period_end_statement_manager,access_account_vat_period_end_statement_manager,model_account_vat_period_end_statement,account.group_account_manager,1,1,1,1 +access_statement_debit_account_line_accountant,access_statement_debit_account_line_accountant,model_statement_debit_account_line,account.group_account_user,1,1,1,1 +access_statement_debit_account_line_manager,access_statement_debit_account_line_manager,model_statement_debit_account_line,account.group_account_manager,1,1,1,1 +access_statement_credit_account_line_accountant,access_statement_credit_account_line_accountant,model_statement_credit_account_line,account.group_account_user,1,1,1,1 +access_statement_credit_account_line_manager,access_statement_credit_account_line_manager,model_statement_credit_account_line,account.group_account_manager,1,1,1,1 +access_statement_generic_account_line_accountant,access_statement_generic_account_line_accountant,model_statement_generic_account_line,account.group_account_user,1,1,1,1 +access_statement_generic_account_line_manager,access_statement_generic_account_line_manager,model_statement_generic_account_line,account.group_account_manager,1,1,1,1 +access_statement_date_range_manager,access_statement_date_range_manager,date_range.model_date_range,account.group_account_manager,1,1,1,1 +access_statement_date_range_type_manager,access_statement_date_range_type_manager,date_range.model_date_range_type,account.group_account_manager,1,1,1,1