[IMP] stock_orderpoint_move_link: black, isort

This commit is contained in:
Guewen Baconnier
2020-01-06 16:28:59 +01:00
committed by davidborromeo
parent 86551a7058
commit db7c81c167
5 changed files with 129 additions and 94 deletions

View File

@@ -9,12 +9,8 @@
"website": "https://github.com/stock-logistics-warehouse", "website": "https://github.com/stock-logistics-warehouse",
"author": "Eficent, Odoo Community Association (OCA)", "author": "Eficent, Odoo Community Association (OCA)",
"category": "Warehouse Management", "category": "Warehouse Management",
"depends": [ "depends": ["stock"],
"stock", "data": ["views/stock_move_views.xml"],
],
"data": [
"views/stock_move_views.xml",
],
"installable": True, "installable": True,
"auto_install": False, "auto_install": False,
} }

View File

@@ -4,16 +4,31 @@ from odoo import models
class StockRule(models.Model): class StockRule(models.Model):
_inherit = 'stock.rule' _inherit = "stock.rule"
def _get_stock_move_values(self, product_id, product_qty, product_uom, def _get_stock_move_values(
location_id, name, origin, values, group_id): self,
product_id,
product_qty,
product_uom,
location_id,
name,
origin,
values,
group_id,
):
vals = super()._get_stock_move_values( vals = super()._get_stock_move_values(
product_id, product_qty, product_uom, product_id,
location_id, name, origin, values, group_id) product_qty,
if 'orderpoint_id' in values: product_uom,
vals['orderpoint_ids'] = [(4, values['orderpoint_id'].id)] location_id,
elif 'orderpoint_ids' in values: name,
vals['orderpoint_ids'] = [(4, o.id) origin,
for o in values['orderpoint_ids']] 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 return vals

View File

@@ -4,21 +4,19 @@ from odoo import fields, models
class StockMove(models.Model): class StockMove(models.Model):
_inherit = 'stock.move' _inherit = "stock.move"
orderpoint_ids = fields.Many2many( orderpoint_ids = fields.Many2many(
comodel_name='stock.warehouse.orderpoint', comodel_name="stock.warehouse.orderpoint", string="Linked Reordering Rules"
string='Linked Reordering Rules',
) )
def _prepare_procurement_values(self): def _prepare_procurement_values(self):
res = super(StockMove, self)._prepare_procurement_values() res = super(StockMove, self)._prepare_procurement_values()
if self.orderpoint_ids: if self.orderpoint_ids:
res['orderpoint_ids'] = self.orderpoint_ids res["orderpoint_ids"] = self.orderpoint_ids
return res return res
def _merge_moves_fields(self): def _merge_moves_fields(self):
res = super(StockMove, self)._merge_moves_fields() res = super(StockMove, self)._merge_moves_fields()
res['orderpoint_ids'] = [(4, m.id) res["orderpoint_ids"] = [(4, m.id) for m in self.mapped("orderpoint_ids")]
for m in self.mapped('orderpoint_ids')]
return res return res

View File

@@ -6,14 +6,17 @@ from odoo import api, models
class StockWarehouseOrderpoint(models.Model): class StockWarehouseOrderpoint(models.Model):
_inherit = 'stock.warehouse.orderpoint' _inherit = "stock.warehouse.orderpoint"
@api.multi @api.multi
def action_view_stock_picking(self): 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 = action.read()[0]
result['context'] = {} result["context"] = {}
picking_ids = self.env['stock.move'].search( picking_ids = (
[('orderpoint_ids', 'in', self.id)]).mapped('picking_id') self.env["stock.move"]
result['domain'] = "[('id','in',%s)]" % picking_ids.ids .search([("orderpoint_ids", "in", self.id)])
.mapped("picking_id")
)
result["domain"] = "[('id','in',%s)]" % picking_ids.ids
return result return result

View File

@@ -1,95 +1,118 @@
# Copyright 2019 Eficent Business and IT Consulting Services S.L. # Copyright 2019 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import ast import ast
from odoo.tests.common import SavepointCase from odoo.tests.common import SavepointCase
class TestStockOrderpointMoveLink(SavepointCase): class TestStockOrderpointMoveLink(SavepointCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super().setUpClass() super().setUpClass()
cls.product_obj = cls.env['product.product'] cls.product_obj = cls.env["product.product"]
cls.orderpoint_obj = cls.env['stock.warehouse.orderpoint'] cls.orderpoint_obj = cls.env["stock.warehouse.orderpoint"]
cls.loc_obj = cls.env['stock.location'] cls.loc_obj = cls.env["stock.location"]
cls.route_obj = cls.env['stock.location.route'] cls.route_obj = cls.env["stock.location.route"]
cls.group_obj = cls.env['procurement.group'] cls.group_obj = cls.env["procurement.group"]
cls.move_obj = cls.env['stock.move'] cls.move_obj = cls.env["stock.move"]
cls.picking_obj = cls.env['stock.picking'] cls.picking_obj = cls.env["stock.picking"]
cls.warehouse = cls.env.ref('stock.warehouse0') cls.warehouse = cls.env.ref("stock.warehouse0")
cls.stock_loc = cls.env.ref('stock.stock_location_stock') cls.stock_loc = cls.env.ref("stock.stock_location_stock")
# Create a new locations and routes: # Create a new locations and routes:
cls.intermediate_loc = cls.loc_obj.create({ cls.intermediate_loc = cls.loc_obj.create(
'name': 'Test location 1', {
'usage': 'internal', "name": "Test location 1",
'location_id': cls.warehouse.view_location_id.id, "usage": "internal",
}) "location_id": cls.warehouse.view_location_id.id,
cls.test_route = cls.route_obj.create({ }
'name': 'Stock -> Test 1', )
'product_selectable': True, cls.test_route = cls.route_obj.create(
'rule_ids': [(0, 0, { {
'name': 'stock to test', "name": "Stock -> Test 1",
'action': 'pull', "product_selectable": True,
'location_id': cls.intermediate_loc.id, "rule_ids": [
'location_src_id': cls.stock_loc.id, (
'procure_method': 'make_to_stock', 0,
'picking_type_id': cls.env.ref( 0,
'stock.picking_type_internal').id, {
'propagate': True "name": "stock to test",
})] "action": "pull",
}) "location_id": cls.intermediate_loc.id,
cls.need_loc = cls.loc_obj.create({ "location_src_id": cls.stock_loc.id,
'name': 'Test location 2', "procure_method": "make_to_stock",
'usage': 'internal', "picking_type_id": cls.env.ref(
'location_id': cls.warehouse.view_location_id.id, "stock.picking_type_internal"
}) ).id,
cls.test_route_2 = cls.route_obj.create({ "propagate": True,
'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, cls.need_loc = cls.loc_obj.create(
'location_src_id': cls.intermediate_loc.id, {
'procure_method': 'make_to_order', "name": "Test location 2",
'picking_type_id': cls.env.ref( "usage": "internal",
'stock.picking_type_internal').id, "location_id": cls.warehouse.view_location_id.id,
'propagate': True }
})] )
}) 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: # Prepare Products:
routes = cls.test_route_2 + cls.test_route routes = cls.test_route_2 + cls.test_route
cls.product = cls.product_obj.create({ cls.product = cls.product_obj.create(
'name': 'Test Product', {"name": "Test Product", "route_ids": [(6, 0, routes.ids)]}
'route_ids': [(6, 0, routes.ids)], )
})
# Create Orderpoint: # Create Orderpoint:
cls.orderpoint_need_loc = cls.orderpoint_obj.create({ cls.orderpoint_need_loc = cls.orderpoint_obj.create(
'warehouse_id': cls.warehouse.id, {
'location_id': cls.need_loc.id, "warehouse_id": cls.warehouse.id,
'product_id': cls.product.id, "location_id": cls.need_loc.id,
'product_min_qty': 10.0, "product_id": cls.product.id,
'product_max_qty': 50.0, "product_min_qty": 10.0,
'product_uom': cls.product.uom_id.id, "product_max_qty": 50.0,
}) "product_uom": cls.product.uom_id.id,
}
)
cls.group_obj.run_scheduler() cls.group_obj.run_scheduler()
def test_01_stock_orderpoint_move_link(self): def test_01_stock_orderpoint_move_link(self):
"""Tests if manual procurement fills orderpoint_ids field.""" """Tests if manual procurement fills orderpoint_ids field."""
move = self.move_obj.search([ move = self.move_obj.search(
('orderpoint_ids', '=', self.orderpoint_need_loc.id)]) [("orderpoint_ids", "=", self.orderpoint_need_loc.id)]
)
self.assertTrue(len(move), 2) self.assertTrue(len(move), 2)
def test_02_stock_orderpoint_move_link_action_view(self): def test_02_stock_orderpoint_move_link_action_view(self):
sp_orderpoint = self.move_obj.search( sp_orderpoint = self.move_obj.search(
[('orderpoint_ids', 'in', self.orderpoint_need_loc.id)]).mapped( [("orderpoint_ids", "in", self.orderpoint_need_loc.id)]
'picking_id') ).mapped("picking_id")
result = self.orderpoint_need_loc.action_view_stock_picking() result = self.orderpoint_need_loc.action_view_stock_picking()
sp_action = self.picking_obj.search( sp_action = self.picking_obj.search(ast.literal_eval(result["domain"]))
ast.literal_eval(result['domain']))
self.assertEquals(sp_orderpoint, sp_action) self.assertEquals(sp_orderpoint, sp_action)