mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] stock_orderpoint_move_link: black, isort
This commit is contained in:
committed by
davidborromeo
parent
86551a7058
commit
db7c81c167
@@ -9,12 +9,8 @@
|
||||
"website": "https://github.com/stock-logistics-warehouse",
|
||||
"author": "Eficent, Odoo Community Association (OCA)",
|
||||
"category": "Warehouse Management",
|
||||
"depends": [
|
||||
"stock",
|
||||
],
|
||||
"data": [
|
||||
"views/stock_move_views.xml",
|
||||
],
|
||||
"depends": ["stock"],
|
||||
"data": ["views/stock_move_views.xml"],
|
||||
"installable": True,
|
||||
"auto_install": False,
|
||||
}
|
||||
|
||||
@@ -4,16 +4,31 @@ from odoo import models
|
||||
|
||||
|
||||
class StockRule(models.Model):
|
||||
_inherit = 'stock.rule'
|
||||
_inherit = "stock.rule"
|
||||
|
||||
def _get_stock_move_values(self, product_id, product_qty, product_uom,
|
||||
location_id, name, origin, values, group_id):
|
||||
def _get_stock_move_values(
|
||||
self,
|
||||
product_id,
|
||||
product_qty,
|
||||
product_uom,
|
||||
location_id,
|
||||
name,
|
||||
origin,
|
||||
values,
|
||||
group_id,
|
||||
):
|
||||
vals = super()._get_stock_move_values(
|
||||
product_id, product_qty, product_uom,
|
||||
location_id, name, origin, values, group_id)
|
||||
if 'orderpoint_id' in values:
|
||||
vals['orderpoint_ids'] = [(4, values['orderpoint_id'].id)]
|
||||
elif 'orderpoint_ids' in values:
|
||||
vals['orderpoint_ids'] = [(4, o.id)
|
||||
for o in values['orderpoint_ids']]
|
||||
product_id,
|
||||
product_qty,
|
||||
product_uom,
|
||||
location_id,
|
||||
name,
|
||||
origin,
|
||||
values,
|
||||
group_id,
|
||||
)
|
||||
if "orderpoint_id" in values:
|
||||
vals["orderpoint_ids"] = [(4, values["orderpoint_id"].id)]
|
||||
elif "orderpoint_ids" in values:
|
||||
vals["orderpoint_ids"] = [(4, o.id) for o in values["orderpoint_ids"]]
|
||||
return vals
|
||||
|
||||
@@ -4,21 +4,19 @@ from odoo import fields, models
|
||||
|
||||
|
||||
class StockMove(models.Model):
|
||||
_inherit = 'stock.move'
|
||||
_inherit = "stock.move"
|
||||
|
||||
orderpoint_ids = fields.Many2many(
|
||||
comodel_name='stock.warehouse.orderpoint',
|
||||
string='Linked Reordering Rules',
|
||||
comodel_name="stock.warehouse.orderpoint", string="Linked Reordering Rules"
|
||||
)
|
||||
|
||||
def _prepare_procurement_values(self):
|
||||
res = super(StockMove, self)._prepare_procurement_values()
|
||||
if self.orderpoint_ids:
|
||||
res['orderpoint_ids'] = self.orderpoint_ids
|
||||
res["orderpoint_ids"] = self.orderpoint_ids
|
||||
return res
|
||||
|
||||
def _merge_moves_fields(self):
|
||||
res = super(StockMove, self)._merge_moves_fields()
|
||||
res['orderpoint_ids'] = [(4, m.id)
|
||||
for m in self.mapped('orderpoint_ids')]
|
||||
res["orderpoint_ids"] = [(4, m.id) for m in self.mapped("orderpoint_ids")]
|
||||
return res
|
||||
|
||||
@@ -6,14 +6,17 @@ from odoo import api, models
|
||||
|
||||
|
||||
class StockWarehouseOrderpoint(models.Model):
|
||||
_inherit = 'stock.warehouse.orderpoint'
|
||||
_inherit = "stock.warehouse.orderpoint"
|
||||
|
||||
@api.multi
|
||||
def action_view_stock_picking(self):
|
||||
action = self.env.ref('stock.action_picking_tree_all')
|
||||
action = self.env.ref("stock.action_picking_tree_all")
|
||||
result = action.read()[0]
|
||||
result['context'] = {}
|
||||
picking_ids = self.env['stock.move'].search(
|
||||
[('orderpoint_ids', 'in', self.id)]).mapped('picking_id')
|
||||
result['domain'] = "[('id','in',%s)]" % picking_ids.ids
|
||||
result["context"] = {}
|
||||
picking_ids = (
|
||||
self.env["stock.move"]
|
||||
.search([("orderpoint_ids", "in", self.id)])
|
||||
.mapped("picking_id")
|
||||
)
|
||||
result["domain"] = "[('id','in',%s)]" % picking_ids.ids
|
||||
return result
|
||||
|
||||
@@ -1,95 +1,118 @@
|
||||
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
import ast
|
||||
|
||||
from odoo.tests.common import SavepointCase
|
||||
|
||||
|
||||
class TestStockOrderpointMoveLink(SavepointCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
|
||||
cls.product_obj = cls.env['product.product']
|
||||
cls.orderpoint_obj = cls.env['stock.warehouse.orderpoint']
|
||||
cls.loc_obj = cls.env['stock.location']
|
||||
cls.route_obj = cls.env['stock.location.route']
|
||||
cls.group_obj = cls.env['procurement.group']
|
||||
cls.move_obj = cls.env['stock.move']
|
||||
cls.picking_obj = cls.env['stock.picking']
|
||||
cls.product_obj = cls.env["product.product"]
|
||||
cls.orderpoint_obj = cls.env["stock.warehouse.orderpoint"]
|
||||
cls.loc_obj = cls.env["stock.location"]
|
||||
cls.route_obj = cls.env["stock.location.route"]
|
||||
cls.group_obj = cls.env["procurement.group"]
|
||||
cls.move_obj = cls.env["stock.move"]
|
||||
cls.picking_obj = cls.env["stock.picking"]
|
||||
|
||||
cls.warehouse = cls.env.ref('stock.warehouse0')
|
||||
cls.stock_loc = cls.env.ref('stock.stock_location_stock')
|
||||
cls.warehouse = cls.env.ref("stock.warehouse0")
|
||||
cls.stock_loc = cls.env.ref("stock.stock_location_stock")
|
||||
|
||||
# Create a new locations and routes:
|
||||
cls.intermediate_loc = cls.loc_obj.create({
|
||||
'name': 'Test location 1',
|
||||
'usage': 'internal',
|
||||
'location_id': cls.warehouse.view_location_id.id,
|
||||
})
|
||||
cls.test_route = cls.route_obj.create({
|
||||
'name': 'Stock -> Test 1',
|
||||
'product_selectable': True,
|
||||
'rule_ids': [(0, 0, {
|
||||
'name': 'stock to test',
|
||||
'action': 'pull',
|
||||
'location_id': cls.intermediate_loc.id,
|
||||
'location_src_id': cls.stock_loc.id,
|
||||
'procure_method': 'make_to_stock',
|
||||
'picking_type_id': cls.env.ref(
|
||||
'stock.picking_type_internal').id,
|
||||
'propagate': True
|
||||
})]
|
||||
})
|
||||
cls.need_loc = cls.loc_obj.create({
|
||||
'name': 'Test location 2',
|
||||
'usage': 'internal',
|
||||
'location_id': cls.warehouse.view_location_id.id,
|
||||
})
|
||||
cls.test_route_2 = cls.route_obj.create({
|
||||
'name': 'Test 1 -> Test 2',
|
||||
'product_selectable': True,
|
||||
'rule_ids': [(0, 0, {
|
||||
'name': 'Test 1 to Test 2',
|
||||
'action': 'pull',
|
||||
'location_id': cls.need_loc.id,
|
||||
'location_src_id': cls.intermediate_loc.id,
|
||||
'procure_method': 'make_to_order',
|
||||
'picking_type_id': cls.env.ref(
|
||||
'stock.picking_type_internal').id,
|
||||
'propagate': True
|
||||
})]
|
||||
})
|
||||
cls.intermediate_loc = cls.loc_obj.create(
|
||||
{
|
||||
"name": "Test location 1",
|
||||
"usage": "internal",
|
||||
"location_id": cls.warehouse.view_location_id.id,
|
||||
}
|
||||
)
|
||||
cls.test_route = cls.route_obj.create(
|
||||
{
|
||||
"name": "Stock -> Test 1",
|
||||
"product_selectable": True,
|
||||
"rule_ids": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "stock to test",
|
||||
"action": "pull",
|
||||
"location_id": cls.intermediate_loc.id,
|
||||
"location_src_id": cls.stock_loc.id,
|
||||
"procure_method": "make_to_stock",
|
||||
"picking_type_id": cls.env.ref(
|
||||
"stock.picking_type_internal"
|
||||
).id,
|
||||
"propagate": True,
|
||||
},
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
cls.need_loc = cls.loc_obj.create(
|
||||
{
|
||||
"name": "Test location 2",
|
||||
"usage": "internal",
|
||||
"location_id": cls.warehouse.view_location_id.id,
|
||||
}
|
||||
)
|
||||
cls.test_route_2 = cls.route_obj.create(
|
||||
{
|
||||
"name": "Test 1 -> Test 2",
|
||||
"product_selectable": True,
|
||||
"rule_ids": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Test 1 to Test 2",
|
||||
"action": "pull",
|
||||
"location_id": cls.need_loc.id,
|
||||
"location_src_id": cls.intermediate_loc.id,
|
||||
"procure_method": "make_to_order",
|
||||
"picking_type_id": cls.env.ref(
|
||||
"stock.picking_type_internal"
|
||||
).id,
|
||||
"propagate": True,
|
||||
},
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
# Prepare Products:
|
||||
routes = cls.test_route_2 + cls.test_route
|
||||
cls.product = cls.product_obj.create({
|
||||
'name': 'Test Product',
|
||||
'route_ids': [(6, 0, routes.ids)],
|
||||
})
|
||||
cls.product = cls.product_obj.create(
|
||||
{"name": "Test Product", "route_ids": [(6, 0, routes.ids)]}
|
||||
)
|
||||
|
||||
# Create Orderpoint:
|
||||
cls.orderpoint_need_loc = cls.orderpoint_obj.create({
|
||||
'warehouse_id': cls.warehouse.id,
|
||||
'location_id': cls.need_loc.id,
|
||||
'product_id': cls.product.id,
|
||||
'product_min_qty': 10.0,
|
||||
'product_max_qty': 50.0,
|
||||
'product_uom': cls.product.uom_id.id,
|
||||
})
|
||||
cls.orderpoint_need_loc = cls.orderpoint_obj.create(
|
||||
{
|
||||
"warehouse_id": cls.warehouse.id,
|
||||
"location_id": cls.need_loc.id,
|
||||
"product_id": cls.product.id,
|
||||
"product_min_qty": 10.0,
|
||||
"product_max_qty": 50.0,
|
||||
"product_uom": cls.product.uom_id.id,
|
||||
}
|
||||
)
|
||||
cls.group_obj.run_scheduler()
|
||||
|
||||
def test_01_stock_orderpoint_move_link(self):
|
||||
"""Tests if manual procurement fills orderpoint_ids field."""
|
||||
move = self.move_obj.search([
|
||||
('orderpoint_ids', '=', self.orderpoint_need_loc.id)])
|
||||
move = self.move_obj.search(
|
||||
[("orderpoint_ids", "=", self.orderpoint_need_loc.id)]
|
||||
)
|
||||
self.assertTrue(len(move), 2)
|
||||
|
||||
def test_02_stock_orderpoint_move_link_action_view(self):
|
||||
sp_orderpoint = self.move_obj.search(
|
||||
[('orderpoint_ids', 'in', self.orderpoint_need_loc.id)]).mapped(
|
||||
'picking_id')
|
||||
[("orderpoint_ids", "in", self.orderpoint_need_loc.id)]
|
||||
).mapped("picking_id")
|
||||
result = self.orderpoint_need_loc.action_view_stock_picking()
|
||||
sp_action = self.picking_obj.search(
|
||||
ast.literal_eval(result['domain']))
|
||||
sp_action = self.picking_obj.search(ast.literal_eval(result["domain"]))
|
||||
self.assertEquals(sp_orderpoint, sp_action)
|
||||
|
||||
Reference in New Issue
Block a user