Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions addons/account/migrations/13.0.1.1/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 37 additions & 1 deletion addons/account/migrations/13.0.1.1/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion addons/point_of_sale/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
57 changes: 57 additions & 0 deletions addons/point_of_sale/migrations/13.0.1.0.1/end-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<record id="product_product_tip" model="product.product">
<!-- <field name="taxes_id" eval="[(5,)]"/>-->
<field name="weight">0.01</field>
<!-- trobz migrate: not null name:/>-->
<field name="name">Tips</field>
</record>
<record id="seq_pos_session" model="ir.sequence">
<field name="padding">5</field>
Expand Down
3 changes: 2 additions & 1 deletion addons/point_of_sale/migrations/13.0.1.0.1/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]


Expand Down
9 changes: 9 additions & 0 deletions addons/product/migrations/13.0.1.2/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
# <record forcecreate="True" id="decimal_volume" model="decimal.precision">
# <field name="name">Volume</field>
# <field name="digits">2</field>
# </record>
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):
Expand All @@ -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)
3 changes: 2 additions & 1 deletion addons/stock/migrations/13.0.1.1/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion addons/stock_account/migrations/13.0.1.1/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading