From a2ff33faac67af5cd2169b1679673b87a6517b25 Mon Sep 17 00:00:00 2001 From: qdp-odoo Date: Thu, 21 Jan 2016 17:34:54 +0100 Subject: [PATCH] [IMP] account: added some functions to help updating VAT reports in localization modules. [FIX] l10n_ch: better tags on taxes in order to have an enhanced VAT report --- addons/account/models/chart_template.py | 21 ++ addons/l10n_ch/__init__.py | 2 +- addons/l10n_ch/__openerp__.py | 2 +- addons/l10n_ch/chart/vat2011.xml | 227 ++++++++---------- .../9.0/post-migrate_tags_on_taxes.py | 6 + .../9.0/pre-set_tags_and_taxes_updatable.py | 7 + 6 files changed, 138 insertions(+), 127 deletions(-) create mode 100644 addons/l10n_ch/migrations/9.0/post-migrate_tags_on_taxes.py create mode 100644 addons/l10n_ch/migrations/9.0/pre-set_tags_and_taxes_updatable.py diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index 9d98c6eaab0..3b95fa9851b 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -9,10 +9,31 @@ from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT from openerp.exceptions import AccessError, UserError, ValidationError import openerp.addons.decimal_precision as dp from openerp import api, fields, models, _ +from openerp import SUPERUSER_ID import logging _logger = logging.getLogger(__name__) +def migrate_set_tags_and_taxes_updatable(cr, registry, module): + ''' This is a utility function used to manually set the flag noupdate to False on tags and account tax templates on localization modules + that need migration (for example in case of VAT report improvements) + ''' + xml_record_ids = registry['ir.model.data'].search(cr, SUPERUSER_ID, [('model', 'in', ['account.tax.template', 'account.account.tag']), ('module', 'like', module)]) + cr.execute("update ir_model_data set noupdate = 'f' where id in %s", (tuple(xml_record_ids),)) + +def migrate_tags_on_taxes(cr, registry): + ''' This is a utiliy function to help migrate the tags of taxes when the localization has been modified on stable version. If + called accordingly in a post_init_hooked function, it will reset the tags set on taxes as per their equivalent template. + + Note: This unusual decision has been made in order to help the improvement of VAT reports on version 9.0, to have them more flexible + and working out of the box when people are creating/using new taxes. + ''' + xml_record_ids = registry['ir.model.data'].search(cr, SUPERUSER_ID, [('model', '=', 'account.tax.template'), ('module', 'like', 'l10n_%')]) + tax_template_ids = [x['res_id'] for x in registry['ir.model.data'].read(cr, SUPERUSER_ID, xml_record_ids, ['res_id'])] + for tax_template in registry['account.tax.template'].browse(cr, SUPERUSER_ID, tax_template_ids): + tax_id = registry['account.tax'].search(cr, SUPERUSER_ID, [('name', '=', tax_template.name), ('type_tax_use', '=', tax_template.type_tax_use), ('description', '=', tax_template.description)]) + if len(tax_id) == 1: + registry['account.tax'].write(cr, SUPERUSER_ID, tax_id, {'tag_ids': [(6,0,[x.id for x in tax_template.tag_ids])]}) # --------------------------------------------------------------- # Account Templates: Account, Tax, Tax Code and chart. + Wizard diff --git a/addons/l10n_ch/__init__.py b/addons/l10n_ch/__init__.py index f7bd52fa93d..aa929c1aadd 100644 --- a/addons/l10n_ch/__init__.py +++ b/addons/l10n_ch/__init__.py @@ -10,4 +10,4 @@ from openerp import SUPERUSER_ID def load_translations(cr, registry): chart_template = registry['ir.model.data'].xmlid_to_object(cr, SUPERUSER_ID, 'l10n_ch.l10nch_chart_template') - chart_template.process_coa_translations() \ No newline at end of file + chart_template.process_coa_translations() diff --git a/addons/l10n_ch/__openerp__.py b/addons/l10n_ch/__openerp__.py index d01526e5d51..abda331a020 100644 --- a/addons/l10n_ch/__openerp__.py +++ b/addons/l10n_ch/__openerp__.py @@ -38,7 +38,7 @@ The swiss localization addons are organized this way: ``l10n_ch`` is located in the core Odoo modules. The other modules are in: https://github.com/OCA/l10n-switzerland """, - 'version': '8.0', + 'version': '9.0', 'author': 'Camptocamp', 'category': 'Localization/Account Charts', 'website': 'http://www.camptocamp.com', diff --git a/addons/l10n_ch/chart/vat2011.xml b/addons/l10n_ch/chart/vat2011.xml index a06ac948157..a9dacd98253 100644 --- a/addons/l10n_ch/chart/vat2011.xml +++ b/addons/l10n_ch/chart/vat2011.xml @@ -1,115 +1,93 @@ - - - 8.0% + + + Switzerland VAT Form: grid 200 + taxes + + + Switzerland VAT Form: grid 220 + taxes + + + Switzerland VAT Form: grid 221 + taxes + + + Switzerland VAT Form: grid 225 + taxes + + + Switzerland VAT Form: grid 230 + taxes + + + Switzerland VAT Form: grid 235 + taxes + + + Switzerland VAT Form: grid 280 + taxes + + + Switzerland VAT Form: grid 301 base + taxes + + + Switzerland VAT Form: grid 311 base + taxes + + + Switzerland VAT Form: grid 341 base + taxes + + + Switzerland VAT Form: grid 381 base + taxes + + + Switzerland VAT Form: grid 301 tax + taxes + + + Switzerland VAT Form: grid 311 tax + taxes + + + Switzerland VAT Form: grid 341 tax + taxes + + + Switzerland VAT Form: grid 381 tax + taxes + + + Switzerland VAT Form: grid 400 + taxes + + + Switzerland VAT Form: grid 405 + taxes + + + Switzerland VAT Form: grid 410 + taxes + + + Switzerland VAT Form: grid 415 + taxes + + + Switzerland VAT Form: grid 420 taxes - - 8.0% Incl. + + Switzerland VAT Form: 100% dédouanement (base in grid 400) taxes - - 2.5% - taxes - - - 2.5% Incl. - taxes - - - - 3.8% - taxes - - - - 3.8% Incl. - taxes - - - - 8.0% achat - taxes - - - - 8.0% achat Incl. - taxes - - - - 2.5% achat - taxes - - - - 2.5% achat Incl. - taxes - - - - 0% import. - taxes - - - - 100% imp. - taxes - - - - 3.8% achat - taxes - - - - 3.8% achat Incl. - taxes - - - - 8.0% invest. - taxes - - - - 8.0% invest. Incl. - taxes - - - - 2.5% invest. - taxes - - - - 2.5% invest. Incl. - taxes - - - - 3.8% invest - taxes - - - - 3.8% invest Incl. - taxes - - - - 0% - taxes - - - - 0% excl. - taxes - @@ -122,7 +100,7 @@ sale - + TVA due à 2.5% (Incl. TR) @@ -134,7 +112,7 @@ sale - + TVA 2.5% sur achat B&S (TR) @@ -145,7 +123,7 @@ purchase - + TVA 2.5% sur achat B&S (Incl. TR) @@ -157,7 +135,7 @@ purchase - + TVA 2.5% sur invest. et autres ch. (TR) @@ -168,7 +146,7 @@ purchase - + TVA 2.5% sur invest. et autres ch. (Incl. TR) @@ -180,7 +158,7 @@ purchase - + @@ -192,7 +170,7 @@ sale - + TVA due à 3.8% (Incl. TS) @@ -204,7 +182,7 @@ sale - + TVA 3.8% sur achat B&S (TS) @@ -215,7 +193,7 @@ purchase - + TVA 3.8% sur achat B&S (Incl. TS) @@ -227,7 +205,7 @@ purchase - + TVA 3.8% sur invest. et autres ch. (TS) @@ -238,7 +216,7 @@ purchase - + TVA 3.8% sur invest. et autres ch. (Incl. TS) @@ -250,7 +228,7 @@ purchase - + TVA due a 8.0% (TN) @@ -262,7 +240,7 @@ sale - + TVA due à 8.0% (Incl. TN) @@ -275,7 +253,7 @@ sale - + TVA 8.0% sur achat B&S (TN) @@ -287,7 +265,7 @@ purchase - + TVA 8.0% sur achat B&S (Incl. TN) @@ -300,7 +278,7 @@ purchase - + TVA 8.0% sur invest. et autres ch. (TN) @@ -311,7 +289,7 @@ purchase - + TVA 8.0% sur invest. et autres ch. (Incl. TN) @@ -323,7 +301,7 @@ purchase - + TVA due a 0% (Exportations) @@ -334,7 +312,7 @@ sale - + TVA 0% exclue @@ -345,7 +323,7 @@ sale - + TVA 0% Importations de biens et services @@ -356,7 +334,6 @@ purchase - @@ -368,7 +345,7 @@ purchase - + diff --git a/addons/l10n_ch/migrations/9.0/post-migrate_tags_on_taxes.py b/addons/l10n_ch/migrations/9.0/post-migrate_tags_on_taxes.py new file mode 100644 index 00000000000..fa56fd00dfa --- /dev/null +++ b/addons/l10n_ch/migrations/9.0/post-migrate_tags_on_taxes.py @@ -0,0 +1,6 @@ +from openerp.modules.registry import RegistryManager + +def migrate(cr, version): + registry = RegistryManager.get(cr.dbname) + from openerp.addons.account.models.chart_template import migrate_tags_on_taxes + migrate_tags_on_taxes(cr, registry) diff --git a/addons/l10n_ch/migrations/9.0/pre-set_tags_and_taxes_updatable.py b/addons/l10n_ch/migrations/9.0/pre-set_tags_and_taxes_updatable.py new file mode 100644 index 00000000000..6027e831157 --- /dev/null +++ b/addons/l10n_ch/migrations/9.0/pre-set_tags_and_taxes_updatable.py @@ -0,0 +1,7 @@ +from openerp.modules.registry import RegistryManager + +def migrate(cr, version): + registry = RegistryManager.get(cr.dbname) + from openerp.addons.account.models.chart_template import migrate_set_tags_and_taxes_updatable + migrate_set_tags_and_taxes_updatable(cr, registry, 'l10n_ch') +