mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[MIG] stock_move_location: Migration to 13.0
This commit is contained in:
@@ -4,3 +4,4 @@
|
||||
|
||||
from . import wizard
|
||||
from . import models
|
||||
from .init_hook import enable_multi_locations
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
{
|
||||
"name": "Move Stock Location",
|
||||
"version": "12.0.1.2.0",
|
||||
"author": "Julius Network Solutions, " "Odoo Community Association (OCA)",
|
||||
"version": "13.0.1.0.0",
|
||||
"author": "Julius Network Solutions, Odoo Community Association (OCA)",
|
||||
"summary": "This module allows to move all stock "
|
||||
"in a stock location to an other one.",
|
||||
"website": "https://github.com/OCA/stock-logistics-warehouse",
|
||||
@@ -17,4 +17,5 @@
|
||||
"views/stock_picking_type_views.xml",
|
||||
"wizard/stock_move_location.xml",
|
||||
],
|
||||
"post_init_hook": "enable_multi_locations",
|
||||
}
|
||||
|
||||
3
stock_move_location/data/stock_quant_view.xml
Executable file → Normal file
3
stock_move_location/data/stock_quant_view.xml
Executable file → Normal file
@@ -5,11 +5,10 @@
|
||||
<act_window id="wiz_stock_quant_location_action"
|
||||
name="Move to location..."
|
||||
res_model="wiz.stock.move.location"
|
||||
src_model="stock.quant"
|
||||
binding_model="stock.quant"
|
||||
view_mode="form"
|
||||
context="{'origin_location_disable': True}"
|
||||
target="new"
|
||||
key2="client_action_multi"
|
||||
groups="stock.group_stock_user"
|
||||
/>
|
||||
|
||||
|
||||
10
stock_move_location/init_hook.py
Normal file
10
stock_move_location/init_hook.py
Normal file
@@ -0,0 +1,10 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from odoo import SUPERUSER_ID, api
|
||||
|
||||
|
||||
def enable_multi_locations(cr, registry):
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
ResConfig = env["res.config.settings"]
|
||||
default_values = ResConfig.default_get(list(ResConfig.fields_get()))
|
||||
default_values.update({"group_stock_multi_locations": True})
|
||||
ResConfig.create(default_values).execute()
|
||||
@@ -1,6 +1,6 @@
|
||||
* Mathieu Vatel <mathieu@julius.fr>
|
||||
* Mykhailo Panarin <m.panarin@mobilunity.com>
|
||||
* Sergio Teruel <sergio.teruel@tecnativa.com>
|
||||
* Joan Sisquella <joan.sisquella@eficent.com>
|
||||
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
|
||||
* Lois Rilo <lois.rilo@eficent.com>
|
||||
* Joan Sisquella <joan.sisquella@forgeflow.com>
|
||||
* Jordi Ballester Alomar <jordi.ballester@forgeflow.com>
|
||||
* Lois Rilo <lois.rilo@forgeflow.com>
|
||||
|
||||
@@ -14,56 +14,63 @@ class TestsCommon(common.SavepointCase):
|
||||
product_obj = cls.env["product.product"]
|
||||
cls.wizard_obj = cls.env["wiz.stock.move.location"]
|
||||
cls.quant_obj = cls.env["stock.quant"]
|
||||
|
||||
# Enable multi-locations:
|
||||
wizard = cls.env["res.config.settings"].create(
|
||||
{"group_stock_multi_locations": True}
|
||||
)
|
||||
wizard.execute()
|
||||
cls.company = cls.env.ref("base.main_company")
|
||||
|
||||
cls.internal_loc_1 = cls.location_obj.create(
|
||||
{"name": "INT_1", "usage": "internal", "active": True}
|
||||
{
|
||||
"name": "INT_1",
|
||||
"usage": "internal",
|
||||
"active": True,
|
||||
"company_id": cls.company.id,
|
||||
}
|
||||
)
|
||||
cls.internal_loc_2 = cls.location_obj.create(
|
||||
{"name": "INT_2", "usage": "internal", "active": True}
|
||||
{
|
||||
"name": "INT_2",
|
||||
"usage": "internal",
|
||||
"active": True,
|
||||
"company_id": cls.company.id,
|
||||
}
|
||||
)
|
||||
cls.uom_unit = cls.env.ref("uom.product_uom_unit")
|
||||
cls.product_no_lots = product_obj.create(
|
||||
{
|
||||
"name": "Pineapple",
|
||||
"type": "product",
|
||||
"tracking": "none",
|
||||
"category_id": cls.env.ref("product.product_category_all").id,
|
||||
}
|
||||
{"name": "Pineapple", "type": "product", "tracking": "none"}
|
||||
)
|
||||
cls.product_lots = product_obj.create(
|
||||
{
|
||||
"name": "Pineapple",
|
||||
"type": "product",
|
||||
"tracking": "lot",
|
||||
"category_id": cls.env.ref("product.product_category_all").id,
|
||||
}
|
||||
{"name": "Apple", "type": "product", "tracking": "lot"}
|
||||
)
|
||||
cls.lot1 = cls.env["stock.production.lot"].create(
|
||||
{"product_id": cls.product_lots.id}
|
||||
{
|
||||
"name": "lot1",
|
||||
"product_id": cls.product_lots.id,
|
||||
"company_id": cls.company.id,
|
||||
}
|
||||
)
|
||||
cls.lot2 = cls.env["stock.production.lot"].create(
|
||||
{"product_id": cls.product_lots.id}
|
||||
{
|
||||
"name": "lot2",
|
||||
"product_id": cls.product_lots.id,
|
||||
"company_id": cls.company.id,
|
||||
}
|
||||
)
|
||||
cls.lot3 = cls.env["stock.production.lot"].create(
|
||||
{"product_id": cls.product_lots.id}
|
||||
{
|
||||
"name": "lot3",
|
||||
"product_id": cls.product_lots.id,
|
||||
"company_id": cls.company.id,
|
||||
}
|
||||
)
|
||||
|
||||
def setup_product_amounts(self):
|
||||
self.set_product_amount(self.product_no_lots, self.internal_loc_1, 123)
|
||||
self.set_product_amount(
|
||||
self.product_lots, self.internal_loc_1, 1, lot_id=self.lot1
|
||||
self.product_lots, self.internal_loc_1, 1.0, lot_id=self.lot1
|
||||
)
|
||||
self.set_product_amount(
|
||||
self.product_lots, self.internal_loc_1, 1, lot_id=self.lot2
|
||||
self.product_lots, self.internal_loc_1, 1.0, lot_id=self.lot2
|
||||
)
|
||||
self.set_product_amount(
|
||||
self.product_lots, self.internal_loc_1, 1, lot_id=self.lot3
|
||||
self.product_lots, self.internal_loc_1, 1.0, lot_id=self.lot3
|
||||
)
|
||||
|
||||
def set_product_amount(self, product, location, amount, lot_id=None):
|
||||
@@ -78,3 +85,12 @@ class TestsCommon(common.SavepointCase):
|
||||
),
|
||||
amount,
|
||||
)
|
||||
|
||||
def _create_wizard(self, origin_location, destination_location):
|
||||
move_location_wizard = self.env["wiz.stock.move.location"]
|
||||
return move_location_wizard.create(
|
||||
{
|
||||
"origin_location_id": origin_location.id,
|
||||
"destination_location_id": destination_location.id,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -12,14 +12,6 @@ class TestMoveLocation(TestsCommon):
|
||||
super().setUp()
|
||||
self.setup_product_amounts()
|
||||
|
||||
def _create_wizard(self, origin_location, destination_location):
|
||||
return self.wizard_obj.create(
|
||||
{
|
||||
"origin_location_id": origin_location.id,
|
||||
"destination_location_id": destination_location.id,
|
||||
}
|
||||
)
|
||||
|
||||
def test_move_location_wizard(self):
|
||||
"""Test a simple move."""
|
||||
wizard = self._create_wizard(self.internal_loc_1, self.internal_loc_2)
|
||||
|
||||
@@ -11,7 +11,6 @@ class StockMoveLocationWizard(models.TransientModel):
|
||||
_name = "wiz.stock.move.location"
|
||||
_description = "Wizard move location"
|
||||
|
||||
@api.multi
|
||||
def _get_default_picking_type_id(self):
|
||||
company_id = self.env.context.get("company_id") or self.env.user.company_id.id
|
||||
return (
|
||||
@@ -63,6 +62,9 @@ class StockMoveLocationWizard(models.TransientModel):
|
||||
rec.origin_location_disable = self.env.context.get(
|
||||
"origin_location_disable", False
|
||||
)
|
||||
rec.destination_location_disable = self.env.context.get(
|
||||
"destination_location_disable", False
|
||||
)
|
||||
if not rec.edit_locations:
|
||||
rec.origin_location_disable = True
|
||||
rec.destination_location_disable = True
|
||||
@@ -120,7 +122,6 @@ class StockMoveLocationWizard(models.TransientModel):
|
||||
}
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def group_lines(self):
|
||||
lines_grouped = {}
|
||||
for line in self.stock_move_location_line_ids:
|
||||
@@ -130,7 +131,6 @@ class StockMoveLocationWizard(models.TransientModel):
|
||||
lines_grouped[line.product_id.id] |= line
|
||||
return lines_grouped
|
||||
|
||||
@api.multi
|
||||
def _create_moves(self, picking):
|
||||
self.ensure_one()
|
||||
groups = self.group_lines()
|
||||
@@ -158,7 +158,6 @@ class StockMoveLocationWizard(models.TransientModel):
|
||||
"location_move": True,
|
||||
}
|
||||
|
||||
@api.multi
|
||||
def _create_move(self, picking, lines):
|
||||
self.ensure_one()
|
||||
move = self.env["stock.move"].create(self._get_move_values(picking, lines))
|
||||
@@ -167,7 +166,6 @@ class StockMoveLocationWizard(models.TransientModel):
|
||||
line.create_move_lines(picking, move)
|
||||
return move
|
||||
|
||||
@api.multi
|
||||
def action_move_location(self):
|
||||
self.ensure_one()
|
||||
picking = self._create_picking()
|
||||
@@ -189,18 +187,16 @@ class StockMoveLocationWizard(models.TransientModel):
|
||||
return action
|
||||
|
||||
def _get_group_quants(self):
|
||||
location_id = self.origin_location_id.id
|
||||
company = self.env["res.company"]._company_default_get("stock.inventory")
|
||||
location_id = self.origin_location_id
|
||||
# Using sql as search_group doesn't support aggregation functions
|
||||
# leading to overhead in queries to DB
|
||||
query = """
|
||||
SELECT product_id, lot_id, SUM(quantity)
|
||||
FROM stock_quant
|
||||
WHERE location_id = %s
|
||||
AND company_id = %s
|
||||
GROUP BY product_id, lot_id
|
||||
"""
|
||||
self.env.cr.execute(query, (location_id, company.id))
|
||||
self.env.cr.execute(query, (location_id.id,))
|
||||
return self.env.cr.dictfetchall()
|
||||
|
||||
def _get_stock_move_location_lines_values(self):
|
||||
@@ -210,7 +206,7 @@ class StockMoveLocationWizard(models.TransientModel):
|
||||
product = product_obj.browse(group.get("product_id")).exists()
|
||||
# Apply the putaway strategy
|
||||
location_dest_id = (
|
||||
self.destination_location_id.get_putaway_strategy(product).id
|
||||
self.destination_location_id._get_putaway_strategy(product).id
|
||||
or self.destination_location_id.id
|
||||
)
|
||||
product_data.append(
|
||||
|
||||
0
stock_move_location/wizard/stock_move_location.xml
Executable file → Normal file
0
stock_move_location/wizard/stock_move_location.xml
Executable file → Normal file
@@ -6,8 +6,6 @@ from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tools import float_compare
|
||||
|
||||
from odoo.addons import decimal_precision as dp
|
||||
|
||||
|
||||
class StockMoveLocationWizardLine(models.TransientModel):
|
||||
_name = "wiz.stock.move.location.line"
|
||||
@@ -31,11 +29,10 @@ class StockMoveLocationWizardLine(models.TransientModel):
|
||||
domain="[('product_id','=',product_id)]",
|
||||
)
|
||||
move_quantity = fields.Float(
|
||||
string="Quantity to move", digits=dp.get_precision("Product Unit of Measure")
|
||||
string="Quantity to move", digits="Product Unit of Measure"
|
||||
)
|
||||
max_quantity = fields.Float(
|
||||
string="Maximum available quantity",
|
||||
digits=dp.get_precision("Product Unit of Measure"),
|
||||
string="Maximum available quantity", digits="Product Unit of Measure"
|
||||
)
|
||||
custom = fields.Boolean(string="Custom line", default=True)
|
||||
|
||||
@@ -78,11 +75,10 @@ class StockMoveLocationWizardLine(models.TransientModel):
|
||||
self.env["stock.move.line"].create(values)
|
||||
return True
|
||||
|
||||
@api.multi
|
||||
def _get_move_line_values(self, picking, move):
|
||||
self.ensure_one()
|
||||
location_dest_id = (
|
||||
self.destination_location_id.get_putaway_strategy(self.product_id).id
|
||||
self.destination_location_id._get_putaway_strategy(self.product_id).id
|
||||
or self.destination_location_id.id
|
||||
)
|
||||
qty_todo, qty_done = self._get_available_quantity()
|
||||
|
||||
Reference in New Issue
Block a user