diff --git a/addons/account/migrations/13.0.1.1/post-migration.py b/addons/account/migrations/13.0.1.1/post-migration.py index 33eb4c2eee35..59183d23cbdc 100644 --- a/addons/account/migrations/13.0.1.1/post-migration.py +++ b/addons/account/migrations/13.0.1.1/post-migration.py @@ -1019,12 +1019,25 @@ def _recompute_move_entries_totals(env): def fill_account_move_line_missing_fields(env): - openupgrade.logged_query(env.cr, """ - UPDATE account_move_line aml - SET account_root_id = aa.root_id - FROM account_account aa - WHERE aa.id = aml.account_id - """) + """ + Changes: + 1) account_root_id: No update as it was removed from 18.0. + 2) tax_group_id: No update as it was computed by module + foodcoop_mig18_precompute_fields (12.0). Its value is stored by + mig18_tax_group_id. + So, here, skip if at least 1 record was set tax_group_id. + """ + + # openupgrade.logged_query(env.cr, """ + # UPDATE account_move_line aml + # SET account_root_id = aa.root_id + # FROM account_account aa + # WHERE aa.id = aml.account_id + # """) + if env['account.move.line'].search([('tax_group_id', '!=', False)], limit=1): + # If at least one tax_group_id is set, we consider that the field was + # already filled by module foodcoop_mig18_precompute_fields in 12.0. + return openupgrade.logged_query(env.cr, """ UPDATE account_move_line aml SET tax_group_id = at.tax_group_id diff --git a/addons/account/migrations/13.0.1.1/pre-migration.py b/addons/account/migrations/13.0.1.1/pre-migration.py index 33ac7e9afa59..37f1e005c4a5 100644 --- a/addons/account/migrations/13.0.1.1/pre-migration.py +++ b/addons/account/migrations/13.0.1.1/pre-migration.py @@ -157,12 +157,36 @@ def create_account_move_new_columns(env): def fill_account_move_line(env): """Faster way""" + """ + Changes: + 1) parent_state: straightforward rename from mig18_parent_state. + 2) account_internal_type: skip its value as it was removed from 18.0. + """ + + # Check if mig18_parent_state exists and rename it, otherwise create parent_state + skip_parent_state = False + if openupgrade.column_exists(env.cr, "account_move_line", "mig18_parent_state"): + openupgrade.rename_columns(env.cr, { + 'account_move_line': [ + ('mig18_parent_state', 'parent_state'), + ], + }) + skip_parent_state = True + else: + openupgrade.logged_query( + env.cr, """ + ALTER TABLE account_move_line + ADD COLUMN parent_state varchar""", + ) + openupgrade.logged_query( env.cr, """ ALTER TABLE account_move_line - ADD COLUMN parent_state varchar, ADD COLUMN account_internal_type varchar""", ) + + if skip_parent_state: + return openupgrade.logged_query( env.cr, """ UPDATE account_move_line aml @@ -319,6 +343,18 @@ def migrate(env, version): cr = env.cr openupgrade.copy_columns(cr, _column_copies) openupgrade.rename_columns(cr, _column_renames) + + if openupgrade.column_exists( + cr, "account_move_line", "mig18_tax_group_id"): + # The column mig18_tax_group_id was added and filled by module + # foodcoop_mig18_precompute_fields in 12.0. + _column_renames_if_exists = { + 'account_move_line': [ + ('mig18_tax_group_id', 'tax_group_id'), + ], + } + openupgrade.rename_columns(cr, _column_renames_if_exists) + openupgrade.rename_fields(env, _field_renames) if openupgrade.table_exists(cr, 'sale_order'): openupgrade.rename_fields(env, _field_sale_renames) diff --git a/addons/point_of_sale/__manifest__.py b/addons/point_of_sale/__manifest__.py index 45b36dc7fb7c..415503122a3e 100644 --- a/addons/point_of_sale/__manifest__.py +++ b/addons/point_of_sale/__manifest__.py @@ -8,7 +8,7 @@ 'sequence': 20, 'summary': 'User-friendly PoS interface for shops and restaurants', 'description': "", - 'depends': ['stock_account', 'barcodes', 'web_editor', 'digest'], + 'depends': ['account', 'stock_account', 'barcodes', 'web_editor', 'digest'], 'data': [ 'security/point_of_sale_security.xml', 'security/ir.model.access.csv', diff --git a/addons/point_of_sale/migrations/13.0.1.0.1/end-migration.py b/addons/point_of_sale/migrations/13.0.1.0.1/end-migration.py index 3168c6f5b522..367f2041ea33 100644 --- a/addons/point_of_sale/migrations/13.0.1.0.1/end-migration.py +++ b/addons/point_of_sale/migrations/13.0.1.0.1/end-migration.py @@ -3,6 +3,62 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openupgradelib import openupgrade +# trobz migrate: when run migration, add_default_account_data didn't update properly default_pos_receivable_account_id +# re-run here if necessary +def add_default_account_data(env): + """v13 introduces some new accounts at company level. We need to ensure + that the information is filled on existing companies for avoiding problems + in subsequent modules (like `point_of_sale`). + + Need to be on end-migration for making sure all chart of templates have + their data loaded. + """ + for company in env["res.company"].search([]): + for chart_field, company_field in [ + ("default_pos_receivable_account_id", + "account_default_pos_receivable_account_id"), + ("default_cash_difference_expense_account_id", + "default_cash_difference_expense_account_id"), + ("default_cash_difference_income_account_id", + "default_cash_difference_income_account_id"), + ]: + chart = company.chart_template_id + check_chart = chart + account_template = False + while not account_template and check_chart: + account_template = check_chart[chart_field] + check_chart = check_chart.parent_id + if not account_template: + continue + tmpl_xml_id = account_template.get_external_id()[account_template.id] + module, name = tmpl_xml_id.split('.', 1) + xml_id = "%s.%s_%s" % (module, company.id, name) + account = env.ref(xml_id, False) + if not account: + # Code copied from `generate_account` in `account.chart.template` + # - can't call it directly as it loads all account templates - + code_main = account_template.code and len(account_template.code) or 0 + code_acc = account_template.code or "" + if code_main > 0 and code_main <= chart.code_digits: + code_acc = str(code_acc) + ( + str("0" * (chart.code_digits - code_main))) + account = env['account.account'].search([ + ('code', '=', code_acc), + ('company_id', '=', company.id), + ], limit=1) + # If there's already an account with the same code and company don't create it + # as it is not allowed by "account_account_code_company_uniq" constraint. + if not account: + tax_template_ref = {} + vals = chart._get_account_vals( + company, account_template, code_acc, tax_template_ref) + account = chart._create_records_with_xmlid( + "account.account", [(account_template, vals)], company) + else: + # we add xmlid for such existing account + env["ir.model.data"].sudo()._update_xmlids( + [dict(xml_id=xml_id, noupdate=True, record=account)]) + company[company_field] = account.id def create_pos_payment_methods(env): """We will create a Payment method for each journal used on configurations""" @@ -152,6 +208,7 @@ def fix_pos_payment_method_config_relation(env): @openupgrade.migrate() def migrate(env, version): + add_default_account_data(env) create_pos_payment_methods(env) create_pos_payments(env) fix_pos_payment_method_config_relation(env) diff --git a/addons/point_of_sale/migrations/13.0.1.0.1/noupdate_changes.xml b/addons/point_of_sale/migrations/13.0.1.0.1/noupdate_changes.xml index aa7535510d01..e1956f077b99 100644 --- a/addons/point_of_sale/migrations/13.0.1.0.1/noupdate_changes.xml +++ b/addons/point_of_sale/migrations/13.0.1.0.1/noupdate_changes.xml @@ -15,6 +15,8 @@ 0.01 + + Tips 5 diff --git a/addons/point_of_sale/migrations/13.0.1.0.1/post-migration.py b/addons/point_of_sale/migrations/13.0.1.0.1/post-migration.py index 81b96a6443cf..bb559a491a0d 100644 --- a/addons/point_of_sale/migrations/13.0.1.0.1/post-migration.py +++ b/addons/point_of_sale/migrations/13.0.1.0.1/post-migration.py @@ -7,7 +7,8 @@ # account.journal 'point_of_sale.pos_sale_journal', # ir.sequence - 'point_of_sale.seq_picking_type_posout', + # trobz migrate: for foodcoop, we want to keep this sequence + # 'point_of_sale.seq_picking_type_posout', ] diff --git a/addons/product/migrations/13.0.1.2/pre-migration.py b/addons/product/migrations/13.0.1.2/pre-migration.py index 39b155067afb..2aff9f52665b 100644 --- a/addons/product/migrations/13.0.1.2/pre-migration.py +++ b/addons/product/migrations/13.0.1.2/pre-migration.py @@ -254,6 +254,14 @@ def fill_product_template_attribute_value__attribute_id_related(env): WHERE ptav.attribute_line_id = ptal.id""", ) +def add_xmlid_for_master_data(env): + # + # Volume + # 2 + # + decimal_rec = env['decimal.precision'].search([("name", "=", "Volume")], limit=1) + if decimal_rec: + openupgrade.add_xmlid(env.cr, "product", "decimal_volume", "decimal.precision", decimal_rec.id, noupdate=True) @openupgrade.migrate() def migrate(env, version): @@ -271,3 +279,4 @@ def migrate(env, version): fill_product_template_attribute_value__attribute_id_related(env) calculate_product_product_combination_indices(env) create_and_fill_product_variant_combination(env) + add_xmlid_for_master_data(env) diff --git a/addons/stock/migrations/13.0.1.1/post-migration.py b/addons/stock/migrations/13.0.1.1/post-migration.py index fe135131d60b..29485c2a7dbf 100644 --- a/addons/stock/migrations/13.0.1.1/post-migration.py +++ b/addons/stock/migrations/13.0.1.1/post-migration.py @@ -526,7 +526,8 @@ def migrate(env, version): product_template_responsible_id_to_company_dependent(env) fill_company_id(env.cr) fill_stock_putaway_rule_location_in_id(env) - fill_propagate_date_minimum_delta(env) + # skip fill_propagate_date_minimum_delta as it was removed from 14.0 + # fill_propagate_date_minimum_delta(env) fill_stock_inventory_start_empty(env) map_stock_location_usage(env) map_stock_picking_responsible_responsible_id_to_user_id(env) diff --git a/addons/stock_account/migrations/13.0.1.1/post-migration.py b/addons/stock_account/migrations/13.0.1.1/post-migration.py index e2990ca07b9a..eaecf3dab2dc 100644 --- a/addons/stock_account/migrations/13.0.1.1/post-migration.py +++ b/addons/stock_account/migrations/13.0.1.1/post-migration.py @@ -293,9 +293,10 @@ def generate_stock_valuation_layer(env): # [1] https://github.com/postgres/postgres/blob/master/src/include/utils/memutils.h#L40 # [2] A gentle calculation svl_length = len(all_svl_list) - batch_size = 5_000_000 + batch_size = 200000 _logger.info(f"To create {svl_length} svl records") for offset in range(0, svl_length, batch_size): + _logger.info(f"To create offset: {offset} - {(offset + batch_size)}") query_insert( env.cr, "stock_valuation_layer", all_svl_list[offset:offset + batch_size]