mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[IMP] mrp_stock_orderpoint_manual_procurement: black, isort
This commit is contained in:
@@ -4,21 +4,15 @@
|
||||
{
|
||||
"name": "MRP Stock Orderpoint Manual Procurement",
|
||||
"summary": "Updates the value of MO Responsible and keeps track"
|
||||
"of changes regarding this field",
|
||||
"version": "12.0.1.0.0",
|
||||
"author": "Eficent, "
|
||||
"Odoo Community Association (OCA)",
|
||||
"of changes regarding this field",
|
||||
"version": "13.0.1.0.0",
|
||||
"author": "Eficent, " "Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/manufacture",
|
||||
"category": "Manufacturing",
|
||||
"depends": [
|
||||
"mrp",
|
||||
"stock_orderpoint_manual_procurement",
|
||||
],
|
||||
"data": [
|
||||
"views/mrp_production_view.xml",
|
||||
],
|
||||
"depends": ["mrp", "stock_orderpoint_manual_procurement"],
|
||||
"data": ["views/mrp_production_view.xml"],
|
||||
"license": "AGPL-3",
|
||||
'installable': True,
|
||||
'application': False,
|
||||
'auto_install': True
|
||||
"installable": True,
|
||||
"application": False,
|
||||
"auto_install": True,
|
||||
}
|
||||
|
||||
@@ -5,9 +5,6 @@ from odoo import fields, models
|
||||
|
||||
|
||||
class MrpProduction(models.Model):
|
||||
_inherit = 'mrp.production'
|
||||
_inherit = "mrp.production"
|
||||
|
||||
requested_by = fields.Many2one(
|
||||
comodel_name='res.users',
|
||||
track_visibility='always',
|
||||
)
|
||||
requested_by = fields.Many2one(comodel_name="res.users", track_visibility="always")
|
||||
|
||||
@@ -5,14 +5,23 @@ from odoo import models
|
||||
|
||||
|
||||
class StockRule(models.Model):
|
||||
_inherit = 'stock.rule'
|
||||
_inherit = "stock.rule"
|
||||
|
||||
def _prepare_mo_vals(self, product_id, product_qty, product_uom,
|
||||
location_id, name, origin, values, bom):
|
||||
def _prepare_mo_vals(
|
||||
self,
|
||||
product_id,
|
||||
product_qty,
|
||||
product_uom,
|
||||
location_id,
|
||||
name,
|
||||
origin,
|
||||
values,
|
||||
bom,
|
||||
):
|
||||
res = super(StockRule, self)._prepare_mo_vals(
|
||||
product_id, product_qty, product_uom, location_id, name,
|
||||
origin, values, bom)
|
||||
requested_uid = self.env.context.get('requested_uid')
|
||||
product_id, product_qty, product_uom, location_id, name, origin, values, bom
|
||||
)
|
||||
requested_uid = self.env.context.get("requested_uid")
|
||||
if requested_uid:
|
||||
res.update({'requested_by': requested_uid.id})
|
||||
res.update({"requested_by": requested_uid.id})
|
||||
return res
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
This module updates a new field *Requested by* in Manufacturing Orders
|
||||
in the case the MO has been created as a result of a manual procurement from
|
||||
an orderpoint.
|
||||
an orderpoint.
|
||||
|
||||
@@ -5,100 +5,107 @@ from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestMrpManualProcurement(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestMrpManualProcurement, self).setUp()
|
||||
|
||||
self.production_model = self.env['mrp.production']
|
||||
self.product_model = self.env['product.product']
|
||||
self.orderpoint_model = self.env['stock.warehouse.orderpoint']
|
||||
self.loc_model = self.env['stock.location']
|
||||
self.route_model = self.env['stock.location.route']
|
||||
self.manual_procurement_wiz = self.env['make.procurement.orderpoint']
|
||||
self.bom_model = self.env['mrp.bom']
|
||||
self.boml_model = self.env['mrp.bom.line']
|
||||
self.production_model = self.env["mrp.production"]
|
||||
self.product_model = self.env["product.product"]
|
||||
self.orderpoint_model = self.env["stock.warehouse.orderpoint"]
|
||||
self.loc_model = self.env["stock.location"]
|
||||
self.route_model = self.env["stock.location.route"]
|
||||
self.manual_procurement_wiz = self.env["make.procurement.orderpoint"]
|
||||
self.bom_model = self.env["mrp.bom"]
|
||||
self.boml_model = self.env["mrp.bom.line"]
|
||||
|
||||
self.warehouse = self.env.ref('stock.warehouse0')
|
||||
self.stock_loc = self.env.ref('stock.stock_location_stock')
|
||||
route_manuf = self.env.ref('mrp.route_warehouse0_manufacture')
|
||||
self.warehouse = self.env.ref("stock.warehouse0")
|
||||
self.stock_loc = self.env.ref("stock.stock_location_stock")
|
||||
route_manuf = self.env.ref("mrp.route_warehouse0_manufacture")
|
||||
|
||||
# Create a new location and route:
|
||||
self.secondary_loc = self.loc_model.create({
|
||||
'name': 'Test location',
|
||||
'usage': 'internal',
|
||||
'location_id': self.warehouse.view_location_id.id,
|
||||
})
|
||||
test_route = self.route_model.create({
|
||||
'name': 'Stock -> Test',
|
||||
'product_selectable': True,
|
||||
'rule_ids': [(0, 0, {
|
||||
'name': 'stock to test',
|
||||
'action': 'pull',
|
||||
'location_id': self.secondary_loc.id,
|
||||
'location_src_id': self.stock_loc.id,
|
||||
'procure_method': 'make_to_order',
|
||||
'picking_type_id': self.env.ref(
|
||||
'stock.picking_type_internal').id,
|
||||
'propagate': True
|
||||
})]
|
||||
})
|
||||
self.secondary_loc = self.loc_model.create(
|
||||
{
|
||||
"name": "Test location",
|
||||
"usage": "internal",
|
||||
"location_id": self.warehouse.view_location_id.id,
|
||||
}
|
||||
)
|
||||
test_route = self.route_model.create(
|
||||
{
|
||||
"name": "Stock -> Test",
|
||||
"product_selectable": True,
|
||||
"rule_ids": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "stock to test",
|
||||
"action": "pull",
|
||||
"location_id": self.secondary_loc.id,
|
||||
"location_src_id": self.stock_loc.id,
|
||||
"procure_method": "make_to_order",
|
||||
"picking_type_id": self.env.ref(
|
||||
"stock.picking_type_internal"
|
||||
).id,
|
||||
"propagate": True,
|
||||
},
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
# Prepare Products:
|
||||
routes = route_manuf + test_route
|
||||
self.product = self.product_model.create({
|
||||
'name': 'Test Product',
|
||||
'route_ids': [(6, 0, routes.ids)],
|
||||
})
|
||||
component = self.product_model.create({
|
||||
'name': 'Test component',
|
||||
})
|
||||
self.product = self.product_model.create(
|
||||
{"name": "Test Product", "route_ids": [(6, 0, routes.ids)]}
|
||||
)
|
||||
component = self.product_model.create({"name": "Test component"})
|
||||
|
||||
# Create Bill of Materials:
|
||||
self.bom_1 = self.bom_model.create({
|
||||
'product_id': self.product.id,
|
||||
'product_tmpl_id': self.product.product_tmpl_id.id,
|
||||
'product_uom_id': self.product.uom_id.id,
|
||||
'product_qty': 1.0,
|
||||
})
|
||||
self.boml_model.create({
|
||||
'bom_id': self.bom_1.id,
|
||||
'product_id': component.id,
|
||||
'product_qty': 1.0,
|
||||
})
|
||||
self.bom_1 = self.bom_model.create(
|
||||
{
|
||||
"product_id": self.product.id,
|
||||
"product_tmpl_id": self.product.product_tmpl_id.id,
|
||||
"product_uom_id": self.product.uom_id.id,
|
||||
"product_qty": 1.0,
|
||||
}
|
||||
)
|
||||
self.boml_model.create(
|
||||
{"bom_id": self.bom_1.id, "product_id": component.id, "product_qty": 1.0}
|
||||
)
|
||||
|
||||
# Create Orderpoint:
|
||||
self.orderpoint_stock = self.orderpoint_model.create({
|
||||
'warehouse_id': self.warehouse.id,
|
||||
'location_id': self.warehouse.lot_stock_id.id,
|
||||
'product_id': self.product.id,
|
||||
'product_min_qty': 10.0,
|
||||
'product_max_qty': 50.0,
|
||||
'product_uom': self.product.uom_id.id,
|
||||
})
|
||||
self.orderpoint_secondary_loc = self.orderpoint_model.create({
|
||||
'warehouse_id': self.warehouse.id,
|
||||
'location_id': self.secondary_loc.id,
|
||||
'product_id': self.product.id,
|
||||
'product_min_qty': 10.0,
|
||||
'product_max_qty': 20.0,
|
||||
'product_uom': self.product.uom_id.id,
|
||||
})
|
||||
self.orderpoint_stock = self.orderpoint_model.create(
|
||||
{
|
||||
"warehouse_id": self.warehouse.id,
|
||||
"location_id": self.warehouse.lot_stock_id.id,
|
||||
"product_id": self.product.id,
|
||||
"product_min_qty": 10.0,
|
||||
"product_max_qty": 50.0,
|
||||
"product_uom": self.product.uom_id.id,
|
||||
}
|
||||
)
|
||||
self.orderpoint_secondary_loc = self.orderpoint_model.create(
|
||||
{
|
||||
"warehouse_id": self.warehouse.id,
|
||||
"location_id": self.secondary_loc.id,
|
||||
"product_id": self.product.id,
|
||||
"product_min_qty": 10.0,
|
||||
"product_max_qty": 20.0,
|
||||
"product_uom": self.product.uom_id.id,
|
||||
}
|
||||
)
|
||||
|
||||
# Create User:
|
||||
self.test_user = self.env['res.users'].create({
|
||||
'name': 'John',
|
||||
'login': 'test',
|
||||
})
|
||||
self.test_user = self.env["res.users"].create({"name": "John", "login": "test"})
|
||||
|
||||
def manual_procurement(self, orderpoint, user):
|
||||
"""Make Procurement from Reordering Rule"""
|
||||
context = {
|
||||
'active_model': 'stock.warehouse.orderpoint',
|
||||
'active_ids': orderpoint.ids,
|
||||
'active_id': orderpoint.id
|
||||
"active_model": "stock.warehouse.orderpoint",
|
||||
"active_ids": orderpoint.ids,
|
||||
"active_id": orderpoint.id,
|
||||
}
|
||||
wizard = self.manual_procurement_wiz.sudo(user).\
|
||||
with_context(context).create({})
|
||||
wizard = self.manual_procurement_wiz.sudo(user).with_context(context).create({})
|
||||
wizard.make_procurement()
|
||||
return wizard
|
||||
|
||||
@@ -106,8 +113,7 @@ class TestMrpManualProcurement(TransactionCase):
|
||||
"""Tests manual procurement fills requested_by field.
|
||||
Direct MO creation."""
|
||||
self.manual_procurement(self.orderpoint_stock, self.test_user)
|
||||
mo = self.production_model.search([
|
||||
('requested_by', '=', self.test_user.id)])
|
||||
mo = self.production_model.search([("requested_by", "=", self.test_user.id)])
|
||||
self.assertTrue(mo)
|
||||
self.assertEqual(mo.product_id, self.product)
|
||||
self.assertEqual(mo.product_qty, 50.0)
|
||||
@@ -116,8 +122,7 @@ class TestMrpManualProcurement(TransactionCase):
|
||||
"""Tests manual procurement fills requested_by field.
|
||||
Indirect MO creation (transfer -> MO)."""
|
||||
self.manual_procurement(self.orderpoint_secondary_loc, self.test_user)
|
||||
mo = self.production_model.search([
|
||||
('requested_by', '=', self.test_user.id)])
|
||||
mo = self.production_model.search([("requested_by", "=", self.test_user.id)])
|
||||
self.assertTrue(mo)
|
||||
self.assertEqual(mo.product_id, self.product)
|
||||
self.assertEqual(mo.product_qty, 20.0)
|
||||
|
||||
Reference in New Issue
Block a user