Debian Codegraph @

addons/l10n_de/migrations/1.1/post-migrate_update_amls.py

raw symbols SCIP
1 # Part of Odoo. See LICENSE file for full copyright and licensing details
2 from odoo import api, SUPERUSER_ID
3
4
5 def migrate(cr, version):
6 # The tax report line 68 has been removed as it does not appear in tax report anymore.
7 # But, it was referenced in the account.sales.report
8 # So, we update amls of this line only, to make this report consistent.
9
10 env = api.Environment(cr, SUPERUSER_ID, {})
11 country = env['res.country'].search([('code', '=', 'DE')], limit=1)
12 tags_68 = env['account.account.tag']._get_tax_tags('68', country.id)
13 tags_60 = env['account.account.tag']._get_tax_tags('60', country.id)
14
15 if tags_68.filtered(lambda tag: tag.tax_negate):
16 cr.execute(
17 """
18 UPDATE account_account_tag_account_move_line_rel
19 SET account_account_tag_id = %s
20 WHERE account_account_tag_id IN %s;
21 """,
22 [
23 tags_60.filtered(lambda tag: tag.tax_negate)[0].id,
24 tuple(tags_68.filtered(lambda tag: tag.tax_negate).ids)
25 ]
26 )
27
28 if tags_68.filtered(lambda tag: not tag.tax_negate):
29 cr.execute(
30 """
31 UPDATE account_account_tag_account_move_line_rel
32 SET account_account_tag_id = %s
33 WHERE account_account_tag_id IN %s;
34 """,
35 [
36 tags_60.filtered(lambda tag: not tag.tax_negate)[0].id,
37 tuple(tags_68.filtered(lambda tag: not tag.tax_negate).ids)
38 ]
39 )