From 5fc88adb4b94dd132a9a0f88471229b08389995f Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Wed, 25 May 2022 17:57:40 +0200 Subject: [PATCH] [FIX] rma: missing migration scripts and version bump Those are needed after making some fields company dependent --- rma/__manifest__.py | 4 +- rma/migrations/14.0.1.1.0/post-migration.py | 126 ++++++++++++++++++++ 2 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 rma/migrations/14.0.1.1.0/post-migration.py diff --git a/rma/__manifest__.py b/rma/__manifest__.py index 030c7cfa..72999929 100644 --- a/rma/__manifest__.py +++ b/rma/__manifest__.py @@ -3,14 +3,14 @@ { "name": "RMA (Return Merchandise Authorization)", - "version": "14.0.1.0.0", + "version": "14.0.1.1.0", "license": "LGPL-3", "category": "RMA", "summary": "Introduces the return merchandise authorization (RMA) process " "in odoo", "author": "ForgeFlow", "website": "https://github.com/ForgeFlow/stock-rma", - "depends": ["stock", "mail", "web", "account"], + "depends": ["stock", "mail", "web"], "demo": ["demo/stock_demo.xml"], "data": [ "security/rma.xml", diff --git a/rma/migrations/14.0.1.1.0/post-migration.py b/rma/migrations/14.0.1.1.0/post-migration.py new file mode 100644 index 00000000..ae792b79 --- /dev/null +++ b/rma/migrations/14.0.1.1.0/post-migration.py @@ -0,0 +1,126 @@ +import logging + +_logger = logging.getLogger(__name__) + + +def set_rma_customer_operation_property(cr): + """ """ + cr.execute( + """ + WITH rma_customer_operation_id_field AS ( + SELECT id FROM ir_model_fields WHERE model='product.template' + AND name='rma_customer_operation_id' + ) + INSERT INTO ir_property(name, type, fields_id, company_id, res_id, + value_reference) + SELECT 'rma_customer_operation_id', 'many2one', rco.id, ro.company_id, + CONCAT('product.template,', t.id), CONCAT('rma.operation,', ro.id) + FROM product_template t JOIN rma_operation ro + ON t.rma_customer_operation_id = ro.id + , rma_customer_operation_id_field rco + WHERE ro.company_id IS NOT NULL + AND NOT EXISTS(SELECT 1 + FROM ir_property + WHERE fields_id=rco.id + AND company_id=ro.company_id + AND res_id=CONCAT('product.template,', t.id)) + """ + ) + _logger.info( + "Added %s rma_customer_operation_id_field product properties", cr.rowcount + ) + + +def set_rma_supplier_operation_property(cr): + """ """ + cr.execute( + """ + WITH rma_supplier_operation_id_field AS ( + SELECT id FROM ir_model_fields WHERE model='product.template' + AND name='rma_supplier_operation_id' + ) + INSERT INTO ir_property(name, type, fields_id, company_id, res_id, + value_reference) + SELECT 'rma_supplier_operation_id', 'many2one', rco.id, ro.company_id, + CONCAT('product.template,', t.id), CONCAT('rma.operation,', ro.id) + FROM product_template t JOIN rma_operation ro + ON t.rma_supplier_operation_id = ro.id + , rma_supplier_operation_id_field rco + WHERE ro.company_id IS NOT NULL + AND NOT EXISTS(SELECT 1 + FROM ir_property + WHERE fields_id=rco.id + AND company_id=ro.company_id + AND res_id=CONCAT('product.template,', t.id)) + """ + ) + _logger.info( + "Added %s rma_supplier_operation_id_field product properties", cr.rowcount + ) + + +def set_rma_customer_operation_category_property(cr): + """ """ + cr.execute( + """ + WITH rma_customer_operation_id_field AS ( + SELECT id FROM ir_model_fields WHERE model='product.category' + AND name='rma_customer_operation_id' + ) + INSERT INTO ir_property(name, type, fields_id, company_id, res_id, + value_reference) + SELECT 'rma_customer_operation_id', 'many2one', rco.id, ro.company_id, + CONCAT('product.category,', pc.id), CONCAT('rma.operation,', ro.id) + FROM product_category pc JOIN rma_operation ro + ON pc.rma_customer_operation_id = ro.id + , rma_customer_operation_id_field rco + WHERE ro.company_id IS NOT NULL + AND NOT EXISTS(SELECT 1 + FROM ir_property + WHERE fields_id=rco.id + AND company_id=ro.company_id + AND res_id=CONCAT('product.category,', pc.id)) + """ + ) + _logger.info( + "Added %s rma_customer_operation_id_field product category properties", + cr.rowcount, + ) + + +def set_rma_supplier_operation_category_property(cr): + """ """ + cr.execute( + """ + WITH rma_supplier_operation_id_field AS ( + SELECT id FROM ir_model_fields WHERE model='product.category' + AND name='rma_supplier_operation_id' + ) + INSERT INTO ir_property(name, type, fields_id, company_id, res_id, + value_reference) + SELECT 'rma_supplier_operation_id', 'many2one', rco.id, ro.company_id, + CONCAT('product.category,', pc.id), CONCAT('rma.operation,', ro.id) + FROM product_category pc JOIN rma_operation ro + ON pc.rma_supplier_operation_id = ro.id + , rma_supplier_operation_id_field rco + WHERE ro.company_id IS NOT NULL + AND NOT EXISTS(SELECT 1 + FROM ir_property + WHERE fields_id=rco.id + AND company_id=ro.company_id + AND res_id=CONCAT('product.category,', pc.id)) + """ + ) + _logger.info( + "Added %s rma_supplier_operation_id_field product category properties", + cr.rowcount, + ) + + +def migrate(cr, version=None): + if not version: + return + set_rma_customer_operation_property(cr) + set_rma_supplier_operation_property(cr) + set_rma_customer_operation_category_property(cr) + set_rma_supplier_operation_category_property(cr)