Script de OpenUpgrade para migrar l10n_es_pos
de Odoo 10.0 a 11.0. En caso de haber instalado en Odoo 10.0 esta PR.
Last active
April 23, 2020 18:30
-
-
Save LuqueDaniel/701d82288e09382599a51179f95b3201 to your computer and use it in GitHub Desktop.
Script de OpenUpgrade para migrar l10n_es_pos de Odoo 10.0 a 11.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | |
from openupgradelib import openupgrade | |
@openupgrade.migrate() | |
def migrate(env, version): | |
sequence = env["ir.sequence"] | |
pos_configs = env["pos.config"].search([]) | |
vals = {} | |
env.cr.execute( | |
""" | |
SELECT | |
id, | |
simple_invoice_prefix, | |
simple_invoice_number, | |
simple_invoice_padding | |
FROM pos_config;""" | |
) | |
for record in env.cr.fetchall(): | |
vals[record[0]] = { | |
"prefix": record[1], | |
"padding": record[3], | |
"number": record[2] + 1, # Next number | |
} | |
# From: https://github.com/OCA/l10n-spain/blob/11.0/l10n_es_pos/hooks.py#L15 | |
for pos in pos_configs: | |
pos_vals = vals.get(pos.id, {}) | |
pos.l10n_es_simplified_invoice_sequence_id = sequence.create( | |
{ | |
"name": ( | |
pos.with_context( | |
{"lang": env.user.lang} | |
)._get_l10n_es_sequence_name() % pos.name | |
), | |
"prefix": pos_vals.get( | |
"prefix", "%s%s" % (pos.name, pos._get_default_prefix()) | |
), | |
"padding": pos_vals.get("padding", pos._get_default_padding()), | |
"number_next_actual": pos_vals.get("number", 1), | |
"implementation": pos_vals.get("implementation", "no_gap"), | |
"code": "pos.config.simplified_invoice", | |
"company_id": pos_vals.get("company_id", pos.company_id.id), | |
} | |
) | |
openupgrade.drop_columns( | |
env.cr, | |
[ | |
("pos_config", "simple_invoice_prefix"), | |
("pos_config", "simple_invoice_number"), | |
("pos_config", "simple_invoice_padding"), | |
] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment