[10.0][Stock] Added migration scripts for stock module - #837
Conversation
|
@jbeficent can you have a look at this? |
pedrobaeza
left a comment
There was a problem hiding this comment.
Good work being your first submission to OpenUpgrade. Please follow my remarks.
| # TODO: pre-migration. Default to some value, guessing by looking at source | ||
| # TODO: post-migration. Default to some value, guessing by looking at source | ||
| # and destination locations, and warehouse. | ||
| # Done! |
There was a problem hiding this comment.
Remove the TODO and put Done: explanation of what you have done
| @@ -0,0 +1,32 @@ | |||
| # -*- coding: utf-8 -*- | |||
| # © 2017 Trescloud <http://trescloud.com> | |||
| @@ -0,0 +1,104 @@ | |||
| # -*- coding: utf-8 -*- | |||
| # © 2017 Trescloud <http://trescloud.com> | |||
| from openupgradelib import openupgrade | ||
|
|
||
| @openupgrade.migrate(use_env=True) | ||
| def migrate(env, version): |
There was a problem hiding this comment.
Put this at the end of the file by general convention
| populate_stock_scrap(env) | ||
|
|
||
| def update_picking_type_id(env): | ||
| ''' |
There was a problem hiding this comment.
According PEP257, method documentation goes with triple double quota, not simple, and first line start in the same one as the initial quotas.
| Set as default the value of field ordered_qty from the value of field product_uom_qty | ||
| :param env: enviroment variable (self) | ||
| ''' | ||
| #stock / stock.move / ordered_qty (float) : NEW |
There was a problem hiding this comment.
Don't be too verbose. This line can be removed.
| #stock / stock.move / ordered_qty (float) : NEW | ||
| # TODO: post-migration. Default to product_uom_qty | ||
| env.cr.execute( | ||
| """ |
There was a problem hiding this comment.
Use one quote when the query is very simple.
| """) | ||
|
|
||
| def populate_stock_scrap(env): | ||
| ''' |
There was a problem hiding this comment.
You have forgotten to put Done on the work analysis for this.
|
|
||
| #do not call stock_scrap.create as it will create a duplicated stock move, use SQL instead | ||
| #field package_id not set as no value is defined | ||
| env.cr.execute( |
There was a problem hiding this comment.
Again, using ORM can be simple and the same in speed (more or less).
|
|
||
| #field route_sequence | ||
| openupgrade.copy_columns( | ||
| env.cr, { |
There was a problem hiding this comment.
Use variables to store the list of column renames, copies, and so on, the same as in https://github.com/OCA/OpenUpgrade/pull/839/files#diff-3cdc4348ce357d41a6908e42cadbca5aR8
Group also all the copies in one.
|
Thanks for your remarks @pedrobaeza!, we will work on this by next monday |
MiquelRForgeFlow
left a comment
There was a problem hiding this comment.
I just sent you a PR (TRESCLOUD#2) that includes all adjustments I requested here
| stock / stock.scrap / state (selection) : NEW selection_keys: ['done', 'draft'] | ||
| # TODO: Create one record for each move that had as destionation a scrap | ||
| # location | ||
| # Done: pre-migration: Create one record for each move that had as destionation a scrap location |
There was a problem hiding this comment.
is post-migration
| stock / stock.location.path / auto (selection) : selection_keys is now '['manual', 'transparent']' ('['auto', 'manual', 'transparent']') | ||
| # TODO: pre-migration. copy column | ||
| # TODO: post-migration. Move 'auto' to some other value | ||
| # Done: pre-migration. copy column and then replace value "auto" with value "manual" |
There was a problem hiding this comment.
the replacement should be done in post-migration
| xml_stock_picking_type_internal = env.ref("stock.picking_type_internal") | ||
| xml_stock_picking_type_out = env.ref("stock.picking_type_out") | ||
| xml_stock_picking_type_in = env.ref("stock.picking_type_in") | ||
| xml_stock_picking_type_manufacturing = env.ref("mrp.picking_type_manufacturing") |
There was a problem hiding this comment.
this should be removed. the 'manufacture' case should be into the migration of mrp module
| if not procurement_rule.picking_type_id: | ||
| picking_type_id = False | ||
| env.cr.execute( | ||
| ''' |
| procurement_rule.location_src_id, | ||
| ) | ||
| ) | ||
| picking_type_ids = cr.fetchone() |
There was a problem hiding this comment.
→ env.cr.fetchone()
| """ | ||
| env.cr.execute( | ||
| ''' | ||
| UPDATE stock_move SET ordered_qty = product_uom_qty |
There was a problem hiding this comment.
the query should be compacted in one line
| ) | ||
| scrap_location_ids = env.cr.fetchone() | ||
| #do not call stock_scrap.create as it will create a duplicated stock move, use SQL instead | ||
| #field package_id not set as no value is defined |
There was a problem hiding this comment.
field package_id can be set, with a witty query, if you relate the move with the stock_quant
| openupgrade.copy_columns(env.cr, column_copies) | ||
| openupgrade.float_to_integer(env.cr, 'stock_location_path', 'route_sequence') | ||
| openupgrade.float_to_integer(env.cr, 'procurement_rule', 'route_sequence') | ||
| env.cr.execute( |
There was a problem hiding this comment.
this replacement should be done in the post-migration
| if xml_stock_picking_type_manufacturing: | ||
| picking_type_id = xml_stock_picking_type_manufacturing.id | ||
| procurement_rule.write({'picking_type_id': picking_type_id}) | ||
|
|
There was a problem hiding this comment.
between the defs should be two empty lines
| @openupgrade.migrate(use_env=True) | ||
| def migrate(env, version): | ||
| update_picking_type_id(env) | ||
| update_ordered_qty(env) |
There was a problem hiding this comment.
pass the cr instead of the env if the def only use the cr
|
Thanks @pedrobaeza and @mreficent for your remarks, I am still doing some tests today and I will likely push a few more commits. |
|
@mreficent I have included some minor changes for the migration of stock module, and I think we can merge it now. I have included again the case for mrp.picking_type_manufacturing with a None option if it is missing (line 24 of post-migration.py), I believe it might be much easier to migrate that field in stock module rather than in mrp module (this change is not even detected in the analysis file of mrp). If you insist I can remove it again, what do you think?. Thanks in advance for your advise. |
There was a problem hiding this comment.
put a space between the comma and the False, and also remember to not overpass 80 chars limit by line in all the code
There was a problem hiding this comment.
flake8 wants the whitespaces at the end of the line to be removed. there are 9 lines affected.
1a93cc0 to
d3deaa4
Compare
|
@pedrobaeza thanks for your fixes, this error appears again in travis: I think that to avoid this missing ID we should keep the the False option in the method env.ref method, or alternatively move this part to the migration script of mrp (which is not advisable from my point of view as detailed above). So I have included a solution in this PR, please comment if you agree with the resolution as I don't want to overwrite one line of your last commit without your agreement. |
|
Oh, I was working on that and other missing things right now. Well, I remove that part and continue. |
|
Hello @pedrobaeza, just to make sure I understood correctly. I understood that you will make the fix altogether with other fixes, so I have not merged my fix into this branch. If you like me to merge my fix please let me know. |
|
Yeah, I'm making them, but today and tomorrow there is the Odoo days in Spain (https://odoospain.odoo.com/event/jornadas-odoo-2017-2017-06-01-2017-06-02-5), so I'm quite busy. I will try to work tomorrow or on Monday. |
dd50e48 to
3ad8291
Compare
|
@StefanRijnhart the same behavior is happening again with Travis (infinite loop), so the reason should be another one. I'll check it later. |
|
@pedrobaeza I see, thanks for the heads up. Why is the generic coa set to uninstallable? |
|
That was another try before throwing this error because it tries to create some invoices without account_id. I see that this is not the ideal solution anyway. I'll make other tries later. |
a3ef31c to
def2b6d
Compare
def2b6d to
71e67e0
Compare
|
@pepetreshere please rebase your branch on current 10.0, then we should get a better picture from travis |
|
@StefanRijnhart I feel uncomfortable patching upstream code where it's not absolutely necessary, so I'd prefer not to have 9314ff87188da31d1263b6c3bf7bb4f3d2485ac0 in OpenUpgrade. You know from painful experience in #895 that every change we apply is a possible source of conflicts. My proposal is: Revert 9314ff87188da31d1263b6c3bf7bb4f3d2485ac0, merge #897, then this should be green too, and we're happy |
|
@hbrunn I can agree with that, yes. |
|
Wait, you want to keep setting modules to uninstallable? |
|
@hbrunn I don't think the change in base_action_rule will conflict in the future, but anyway, have you checked if there's any other non migrated module that declares action rules? |
|
@StefanRijnhart setting modules to uninstallable: Now that I looked at the code for the first time, no, I don't want that either |
9314ff8 to
02fa3f1
Compare
02fa3f1 to
f49ebb2
Compare
- Added reate_date to stock_scrap, - Removed positive qtys filter as positive and negative are supported - Removed scrapped source location as domains avoids this in v10 - Added explanation about using SQL instead of ORM - Included case for MRP for ease of coding
* PEP8 * Fixes * Some things not attended
f49ebb2 to
4d9fd56
Compare
|
We still have problems with website module that don't anticipate before. Should I fix it here or do you prefer to merge this and create another PR fixing website? |
|
We can merge, if you remove the change of setting the coa modules uninstallable. |
|
Removing that commit, I won't still be able to get a green branch although I fix website part. Can't we let the commit and revert later when dealing with account migration? |
4d9fd56 to
0ca64f2
Compare
|
OK, finally I'm going to translate my greenifying efforts to the account migration PR, so I have removed the commit that makes uninstallable the l10n_* modules and merging this one although in red. Then, I'll wait for website PR and rebase everything to work on the final solution at account level. |
|
👍 |
|
👍 :) |
Description of the issue/feature this PR addresses: Added migration scripts to v10 for stock module
Current behavior before PR: Module stock fail migration
Desired behavior after PR is merged: Module stock migrated successfully
--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr