OCA / rma

Odoo for Return Merchandise Authorization (RMA)
GNU Affero General Public License v3.0
78 stars 206 forks source link

[16.0][BUG] When migrating the rma module from v15 to v16 #395

Open pleirb opened 3 months ago

pleirb commented 3 months ago

After the update in the migrations folder of the rma module I receive this error when migrating from odoo 15 to 16

`2024-06-19 16:35:16,697 1 INFO mig odoo.modules.migration: module rma: Running migration [16.0.1.4.0>] post-migration 2024-06-19 16:35:16,716 1 INFO mig OpenUpgrade: rma: post-migration script called with version 15.0.1.3.0 2024-06-19 16:35:16,760 1 ERROR mig odoo.sql_db: bad query: INSERT INTO "stock_rule" ("action", "active", "auto", "company_id", "create_date", "create_uid", "delay", "group_propagation_option", "location_dest_id", "location_src_id", "name", "picking_type_id", "procure_method", "propagate_cancel", "propagate_carrier", "route_id", "sequence", "warehouse_id", "write_date", "write_uid") VALUES ('pull', true, 'manual', 1, '2024-06-19 16:35:15.665919', 1, 0, 'propagate', NULL, 9, '{"en_US": "Ofi: Cliente"}', NULL, 'make_to_stock', false, false, 30, 20, 1, '2024-06-19 16:35:15.665919', 1) RETURNING "id" ERROR: null value in column "picking_type_id" of relation "stock_rule" violates not-null constraint DETAIL: Failing row contains (90, 1, {"en_US": "Ofi: Cliente"}, 20, 1, 1, t, 2024-06-19 16:35:15.665919, pull, 2024-06-19 16:35:15.665919, null, propagate, null, null, 9, null, 0, 1, f, make_to_stock, null, 30, null, manual, f).

2024-06-19 16:35:16,760 1 ERROR mig OpenUpgrade: rma: error in migration script /odoo_env/src/OCA/rma/rma/migrations/16.0.1.4.0/post-migration.py: null value in column "picking_type_id" of relation "stock_rule" violates not-null constraint DETAIL: Failing row contains (90, 1, {"en_US": "Ofi: Cliente"}, 20, 1, 1, t, 2024-06-19 16:35:15.665919, pull, 2024-06-19 16:35:15.665919, null, propagate, null, null, 9, null, 0, 1, f, make_to_stock, null, 30, null, manual, f).

2024-06-19 16:35:16,760 1 ERROR mig OpenUpgrade: null value in column "picking_type_id" of relation "stock_rule" violates not-null constraint DETAIL: Failing row contains (90, 1, {"en_US": "Ofi: Cliente"}, 20, 1, 1, t, 2024-06-19 16:35:15.665919, pull, 2024-06-19 16:35:15.665919, null, propagate, null, null, 9, null, 0, 1, f, make_to_stock, null, 30, null, manual, f).

Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/openupgradelib/openupgrade.py", line 2296, in wrapped_function version, File "/odoo_env/src/OCA/rma/rma/migrations/16.0.1.4.0/post-migration.py", line 13, in migrate route_vals = wh._create_or_update_route() File "/odoo_env/src/odoo/addons/stock/models/stock_warehouse.py", line 480, in _create_or_update_route self._find_existing_rule_or_create(rules_list) File "/odoo_env/src/odoo/addons/stock/models/stock_warehouse.py", line 610, in _find_existing_rule_or_create self.env['stock.rule'].create(rule_vals) File "", line 2, in create File "/odoo_env/src/odoo/odoo/api.py", line 414, in _model_create_multi return create(self, [arg]) File "/odoo_env/src/odoo/odoo/addons/base/models/ir_fields.py", line 670, in create recs = super().create(vals_list) File "", line 2, in create File "/odoo_env/src/odoo/odoo/api.py", line 415, in _model_create_multi return create(self, arg) File "/odoo_env/src/odoo/odoo/models.py", line 3975, in create records = self._create(data_list) File "/odoo_env/src/odoo/odoo/models.py", line 4158, in _create [tuple(row) for row in rows], File "/odoo_env/src/odoo/odoo/sql_db.py", line 321, in execute res = self._obj.execute(query, params) psycopg2.IntegrityError: null value in column "picking_type_id" of relation "stock_rule" violates not-null constraint DETAIL: Failing row contains (90, 1, {"en_US": "Ofi: Cliente"}, 20, 1, 1, t, 2024-06-19 16:35:15.665919, pull, 2024-06-19 16:35:15.665919, null, propagate, null, null, 9, null, 0, 1, f, make_to_stock, null, 30, null, manual, f). `

pleirb commented 3 months ago

If I delete the migrations folder (which was added 2 weeks ago by @mt-software-de and @victoralmau) of the rma module, the migration from 15 to 16 is done correctly

mt-software-de commented 3 months ago

The commit what was used was cherry-picked from v14. And was not ready to merge yet.

But to help here, the fields rma_in_type_id and/or rma_out_type_id not set on the warehouse, the are used and mandatory to create the new rules for the rma proc run.

Within the migration we have to ensure, that those fields are set. Therefor _create_or_update_sequences_and_picking_types needs to be called at the migration. This would then create the missing stock.picking.type. But to ensure that no other stock.picking.type is changed, we have to overwrite _get_picking_type_update_values and checking the context value rma_post_init_hook. Like it is done in https://github.com/OCA/rma/blob/6713de309a44f280410d07303a0202e3cb2f1dbd/rma/models/stock_warehouse.py#L149

https://github.com/OCA/rma/blob/6713de309a44f280410d07303a0202e3cb2f1dbd/rma/models/stock_warehouse.py#L185

pedrobaeza commented 3 months ago

We will check it soon. Thanks for the extra info, Michael.

pleirb commented 3 months ago

Thanks @mt-software-de I have configured all the warehouses so that the rma_loc_id, rma_in_type_id and rma_out_type_id fields have a value and after running the migration again this error no longer occurs