-
-
Notifications
You must be signed in to change notification settings - Fork 729
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] stock_change_qty_reason: Migration to 15.0
- Loading branch information
1 parent
337489e
commit 41fc231
Showing
18 changed files
with
195 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
stock_change_qty_reason/migrations/15.0.1.0.0/post-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright 2023 ForgeFlow <http://www.forgeflow.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from openupgradelib import openupgrade | ||
|
||
|
||
def fill_stock_quant_reason(env): | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE stock_move_line sml | ||
SET reason = sil.reason | ||
FROM stock_inventory_line sil | ||
JOIN stock_inventory ON sil.inventory_id = si.id | ||
JOIN stock_location sl ON sil.location_id = sl.id | ||
JOIN stock_move sm ON sm.inventory_id = si.id | ||
WHERE sml.move_id = sm.id AND sml.location_id = sl.id | ||
AND sl.usage in ('internal', 'transit') | ||
AND si.state = 'done' AND sml.product_id = sil.product_id | ||
AND (sil.prod_lot_id IS NULL AND sml.lot_id IS NULL) OR ( | ||
sil.prod_lot_id = sml.lot_id) | ||
AND sml.date = sil.inventory_date""", | ||
) | ||
|
||
|
||
def fill_stock_move_line_preset_reason_id(env): | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE stock_move_line sml | ||
SET preset_reason_id = sm.preset_reason_id | ||
FROM stock_move sm | ||
WHERE sml.move_id = sm.id AND sm.preset_reason_id IS NOT NULL""", | ||
) | ||
|
||
|
||
def fill_stock_move_line_reason(env): | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE stock_move_line sml | ||
SET reason = COALESCE(reason, sqr.name) | ||
FROM stock_quant_reason sqr | ||
WHERE sml.preset_reason_id = sqr.id""", | ||
) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
fill_stock_quant_reason(env) | ||
fill_stock_move_line_preset_reason_id(env) | ||
fill_stock_move_line_reason(env) |
14 changes: 14 additions & 0 deletions
14
stock_change_qty_reason/migrations/15.0.1.0.0/pre-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2023 ForgeFlow <http://www.forgeflow.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from openupgradelib import openupgrade | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
openupgrade.rename_tables( | ||
env.cr, [("stock_inventory_line_reason", "stock_quant_reason")] | ||
) | ||
openupgrade.rename_models( | ||
env.cr, [("stock.inventory.line.reason", "stock.quant.reason")] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import res_config_settings | ||
from . import stock_inventory | ||
from . import stock_inventory_line | ||
from . import stock_inventory_line_reason | ||
from . import stock_move | ||
from . import stock_move_line | ||
from . import stock_quant | ||
from . import stock_quant_reason |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright 2019-2023 ForgeFlow S.L. | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
from odoo import fields, models | ||
|
||
|
||
class StockMoveLine(models.Model): | ||
_inherit = "stock.move.line" | ||
|
||
preset_reason_id = fields.Many2one("stock.quant.reason") | ||
reason = fields.Char(help="Type in a reason for the product quantity change") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright 2016-2017 ACSONE SA/NV (<http://acsone.eu>) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class StockQuant(models.Model): | ||
"""Class to inherit model stock.quant""" | ||
|
||
_inherit = "stock.quant" | ||
|
||
reason = fields.Char(help="Type in a reason for the product quantity change") | ||
preset_reason_id = fields.Many2one("stock.quant.reason") | ||
|
||
def _get_inventory_move_values(self, qty, location_id, location_dest_id, out=False): | ||
"""Function to super _get_inventory_move_values""" | ||
res = super()._get_inventory_move_values( | ||
qty, location_id, location_dest_id, out | ||
) | ||
context = ( | ||
self.reason if not self.preset_reason_id else self.preset_reason_id.name | ||
) | ||
line = res["move_line_ids"][0][2] | ||
line["reason"] = context | ||
if res.get("origin"): | ||
res["origin"] = " ,".join([res.get("origin"), context]) | ||
else: | ||
res["origin"] = context | ||
if self.preset_reason_id: | ||
line["preset_reason_id"] = self.preset_reason_id.id | ||
self.preset_reason_id = False | ||
if self.reason: | ||
self.reason = False | ||
return res |
9 changes: 4 additions & 5 deletions
9
...son/models/stock_inventory_line_reason.py → ...e_qty_reason/models/stock_quant_reason.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_stock_inventory_line_reason_user,stock.inventory.line.reason,model_stock_inventory_line_reason,stock.group_stock_user,1,0,0,0 | ||
access_stock_inventory_line_reason_manager,stock.inventory.line.reason,model_stock_inventory_line_reason,stock.group_stock_manager,1,1,1,1 | ||
access_stock_quant_reason_user,stock.quant.reason,model_stock_quant_reason,stock.group_stock_user,1,0,0,0 | ||
access_stock_quant_reason_manager,stock.quant.reason,model_stock_quant_reason,stock.group_stock_manager,1,1,1,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
stock_change_qty_reason/views/stock_inventory_line_view.xml
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.