Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX][13.0] stock: Fix bug miss migrate responsible_id field #333

Open
wants to merge 1 commit into
base: 13.0
Choose a base branch
from
Open
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
31 changes: 31 additions & 0 deletions addons/stock/migrations/13.0.1.1/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,39 @@ def prefill_stock_picking_type_sequence_code(env):
)


def convert_field(cr, model, field, target_model):
table = model.replace('.', '_')

cr.execute("""SELECT 1
FROM information_schema.columns
WHERE table_name = %s
AND column_name = %s
""", (table, field))
if not cr.fetchone():
return

cr.execute("SELECT id FROM ir_model_fields WHERE model=%s AND name=%s", (model, field))
[fields_id] = cr.fetchone()

cr.execute("""
INSERT INTO ir_property(name, type, fields_id, company_id, res_id, value_reference)
SELECT %(field)s, 'many2one', %(fields_id)s, company_id, CONCAT('{model},', id),
CONCAT('{target_model},', {field})
FROM {table} t
WHERE {field} IS NOT NULL
AND NOT EXISTS(SELECT 1
FROM ir_property
WHERE fields_id=%(fields_id)s
AND company_id=t.company_id
AND res_id=CONCAT('{model},', t.id))
""".format(**locals()), locals())

cr.execute('ALTER TABLE "{0}" DROP COLUMN "{1}" CASCADE'.format(table, field))


@openupgrade.migrate()
def migrate(env, version):
convert_field(env.cr, 'product.template', 'responsible_id', 'res.users')
openupgrade.copy_columns(env.cr, _column_copies)
if openupgrade.table_exists(env.cr, 'report_stock_quantity'):
# OCA module `stock_forecast_report` was installed
Expand Down