diff --git a/stock_request/__manifest__.py b/stock_request/__manifest__.py index 983f42864..eb215dec9 100644 --- a/stock_request/__manifest__.py +++ b/stock_request/__manifest__.py @@ -1,13 +1,13 @@ -# Copyright 2017 Eficent Business and IT Consulting Services, S.L. +# Copyright 2017-2020 ForgeFlow, S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). { "name": "Stock Request", "summary": "Internal request for stock", - "version": "12.0.1.1.6", + "version": "13.0.1.0.0", "license": "LGPL-3", "website": "https://github.com/stock-logistics-warehouse", - "author": "Eficent, " "Odoo Community Association (OCA)", + "author": "ForgeFlow, Odoo Community Association (OCA)", "category": "Warehouse Management", "depends": ["stock"], "data": [ diff --git a/stock_request/models/procurement_group.py b/stock_request/models/procurement_group.py index c0730f15d..420b5c1f3 100644 --- a/stock_request/models/procurement_group.py +++ b/stock_request/models/procurement_group.py @@ -8,13 +8,22 @@ class ProcurementGroup(models.Model): _inherit = "procurement.group" @api.model - def run( - self, product_id, product_qty, product_uom, location_id, name, origin, values - ): - if "stock_request_id" in values and values.get("stock_request_id"): - req = self.env["stock.request"].browse(values.get("stock_request_id")) - if req.order_id: - origin = req.order_id.name - return super().run( - product_id, product_qty, product_uom, location_id, name, origin, values - ) + def run(self, procurements): + indexes_to_pop = [] + new_procs = [] + for i, procurement in enumerate(procurements): + if "stock_request_id" in procurement.values and procurement.values.get( + "stock_request_id" + ): + req = self.env["stock.request"].browse( + procurement.values.get("stock_request_id") + ) + if req.order_id: + new_procs.append(procurement._replace(origin=req.order_id.name)) + indexes_to_pop.append(i) + if new_procs: + indexes_to_pop.reverse() + for index in indexes_to_pop: + procurements.pop(index) + procurements.extend(new_procs) + return super().run(procurements) diff --git a/stock_request/models/stock_move.py b/stock_request/models/stock_move.py index a756e339e..077452f46 100644 --- a/stock_request/models/stock_move.py +++ b/stock_request/models/stock_move.py @@ -1,4 +1,4 @@ -# Copyright 2017 Eficent Business and IT Consulting Services, S.L. +# Copyright 2017-2020 ForgeFlow, S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from odoo import _, api, fields, models diff --git a/stock_request/models/stock_move_line.py b/stock_request/models/stock_move_line.py index 1b90ac07f..bed07ca1b 100644 --- a/stock_request/models/stock_move_line.py +++ b/stock_request/models/stock_move_line.py @@ -51,7 +51,7 @@ class StockMoveLine(models.Model): # We do sudo because potentially the user that completes the move # may not have permissions for stock.request. to_allocate_qty = ml.qty_done - for allocation in ml.move_id.allocation_ids.sudo(): + for allocation in ml.move_id.allocation_ids: allocated_qty = 0.0 if allocation.open_product_qty: allocated_qty = min(allocation.open_product_qty, qty_done) diff --git a/stock_request/models/stock_picking.py b/stock_request/models/stock_picking.py index 5e7aca501..cfe03de7c 100644 --- a/stock_request/models/stock_picking.py +++ b/stock_request/models/stock_picking.py @@ -1,4 +1,4 @@ -# Copyright 2017 Eficent Business and IT Consulting Services, S.L. +# Copyright 2017-2020 ForgeFlow, S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from odoo import api, fields, models diff --git a/stock_request/models/stock_request.py b/stock_request/models/stock_request.py index 3e5b4acec..f18cd3887 100644 --- a/stock_request/models/stock_request.py +++ b/stock_request/models/stock_request.py @@ -1,12 +1,10 @@ -# Copyright 2017 Eficent Business and IT Consulting Services, S.L. +# Copyright 2017-2020 ForgeFlow, S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from odoo import _, api, fields, models from odoo.exceptions import UserError, ValidationError from odoo.tools import float_compare -from odoo.addons import decimal_precision as dp - REQUEST_STATES = [ ("draft", "Draft"), ("open", "In progress"), @@ -92,7 +90,7 @@ class StockRequest(models.Model): ) qty_in_progress = fields.Float( "Qty In Progress", - digits=dp.get_precision("Product Unit of Measure"), + digits="Product Unit of Measure", readonly=True, compute="_compute_qty", store=True, @@ -100,7 +98,7 @@ class StockRequest(models.Model): ) qty_done = fields.Float( "Qty Done", - digits=dp.get_precision("Product Unit of Measure"), + digits="Product Unit of Measure", readonly=True, compute="_compute_qty", store=True, @@ -208,12 +206,10 @@ class StockRequest(models.Model): if self.order_id and self.order_id.picking_policy != self.picking_policy: raise ValidationError(_("The picking policy must be equal to the order")) - @api.multi def _action_confirm(self): self._action_launch_procurement_rule() self.state = "open" - @api.multi def action_confirm(self): self._action_confirm() return True @@ -223,7 +219,7 @@ class StockRequest(models.Model): return True def action_cancel(self): - self.sudo().mapped("move_ids")._action_cancel() + self.mapped("move_ids")._action_cancel() self.state = "cancel" return True @@ -271,7 +267,6 @@ class StockRequest(models.Model): def _skip_procurement(self): return self.state != "draft" or self.product_id.type not in ("consu", "product") - @api.multi def _action_launch_procurement_rule(self): """ Launch procurement group run method with required/custom @@ -298,25 +293,26 @@ class StockRequest(models.Model): group_id=request.procurement_group_id ) try: - # We launch with sudo because potentially we could create - # objects that the user is not authorized to create, such - # as PO. - self.env["procurement.group"].sudo().run( - request.product_id, - request.product_uom_qty, - request.product_uom_id, - request.location_id, - request.name, - request.name, - values, + procurements = [] + procurements.append( + self.env["procurement.group"].Procurement( + request.product_id, + request.product_uom_qty, + request.product_uom_id, + request.location_id, + request.name, + request.name, + self.env.company, + values, + ) ) + self.env["procurement.group"].run(procurements) except UserError as error: errors.append(error.name) if errors: raise UserError("\n".join(errors)) return True - @api.multi def action_view_transfer(self): action = self.env.ref("stock.action_picking_tree_all").read()[0] @@ -335,7 +331,6 @@ class StockRequest(models.Model): upd_vals["name"] = self.env["ir.sequence"].next_by_code("stock.request") return super().create(upd_vals) - @api.multi def unlink(self): if self.filtered(lambda r: r.state != "draft"): raise UserError(_("Only requests on draft state can be unlinked")) diff --git a/stock_request/models/stock_request_abstract.py b/stock_request/models/stock_request_abstract.py index 89883c57f..26075cd70 100644 --- a/stock_request/models/stock_request_abstract.py +++ b/stock_request/models/stock_request_abstract.py @@ -1,11 +1,9 @@ -# Copyright 2017 Eficent Business and IT Consulting Services, S.L. +# Copyright 2017-2020 ForgeFlow, S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from odoo import _, api, fields, models from odoo.exceptions import ValidationError -from odoo.addons import decimal_precision as dp - class StockRequest(models.AbstractModel): _name = "stock.request.abstract" @@ -66,16 +64,16 @@ class StockRequest(models.AbstractModel): ) product_uom_qty = fields.Float( "Quantity", - digits=dp.get_precision("Product Unit of Measure"), + digits="Product Unit of Measure", required=True, - help="Quantity, specified in the unit of measure indicated in the " "request.", + help="Quantity, specified in the unit of measure indicated in the request.", ) product_qty = fields.Float( "Real Quantity", compute="_compute_product_qty", store=True, copy=False, - digits=dp.get_precision("Product Unit of Measure"), + digits="Product Unit of Measure", help="Quantity in the default UoM of the product", ) procurement_group_id = fields.Many2one( @@ -86,12 +84,7 @@ class StockRequest(models.AbstractModel): "procurement rules will be grouped into one big picking.", ) company_id = fields.Many2one( - "res.company", - "Company", - required=True, - default=lambda self: self.env["res.company"]._company_default_get( - "stock.request" - ), + "res.company", "Company", required=True, default=lambda self: self.env.company ) route_id = fields.Many2one( "stock.location.route", @@ -202,8 +195,8 @@ class StockRequest(models.AbstractModel): def _check_qty(self): for rec in self: if rec.product_qty <= 0: - raise ValueError( - _("Stock Request product quantity has to be" " strictly positive.") + raise ValidationError( + _("Stock Request product quantity has to be strictly positive.") ) @api.onchange("warehouse_id") @@ -217,7 +210,7 @@ class StockRequest(models.AbstractModel): # the onchange, as it could lead to inconsistencies. return res if self.warehouse_id: - loc_wh = self.location_id.sudo().get_warehouse() + loc_wh = self.location_id.get_warehouse() if self.warehouse_id != loc_wh: self.location_id = self.warehouse_id.lot_stock_id.id if self.warehouse_id.company_id != self.company_id: @@ -227,7 +220,7 @@ class StockRequest(models.AbstractModel): @api.onchange("location_id") def onchange_location_id(self): if self.location_id: - loc_wh = self.location_id.sudo().get_warehouse() + loc_wh = self.location_id.get_warehouse() if loc_wh and self.warehouse_id != loc_wh: self.warehouse_id = loc_wh self.with_context(no_change_childs=True).onchange_warehouse_id() diff --git a/stock_request/models/stock_request_allocation.py b/stock_request/models/stock_request_allocation.py index 3d75e1657..4f2f962a9 100644 --- a/stock_request/models/stock_request_allocation.py +++ b/stock_request/models/stock_request_allocation.py @@ -1,4 +1,4 @@ -# Copyright 2017 Eficent Business and IT Consulting Services, S.L. +# Copyright 2017-2020 ForgeFlow, S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from odoo import api, fields, models diff --git a/stock_request/models/stock_request_order.py b/stock_request/models/stock_request_order.py index b38ba4119..dc5baf9b8 100644 --- a/stock_request/models/stock_request_order.py +++ b/stock_request/models/stock_request_order.py @@ -92,9 +92,7 @@ class StockRequestOrder(models.Model): required=True, readonly=True, states={"draft": [("readonly", False)]}, - default=lambda self: self.env["res.company"]._company_default_get( - "stock.request.order" - ), + default=lambda self: self.env.company, ) expected_date = fields.Datetime( "Expected Date", @@ -173,7 +171,7 @@ class StockRequestOrder(models.Model): @api.onchange("location_id") def onchange_location_id(self): if self.location_id: - loc_wh = self.location_id.sudo().get_warehouse() + loc_wh = self.location_id.get_warehouse() if loc_wh and self.warehouse_id != loc_wh: self.warehouse_id = loc_wh self.with_context(no_change_childs=True).onchange_warehouse_id() @@ -188,11 +186,11 @@ class StockRequestOrder(models.Model): def onchange_warehouse_id(self): if self.warehouse_id: # search with sudo because the user may not have permissions - loc_wh = self.location_id.sudo().get_warehouse() + loc_wh = self.location_id.get_warehouse() if self.warehouse_id != loc_wh: - self.location_id = self.warehouse_id.sudo().lot_stock_id + self.location_id = self.warehouse_id.lot_stock_id self.with_context(no_change_childs=True).onchange_location_id() - if self.warehouse_id.sudo().company_id != self.company_id: + if self.warehouse_id.company_id != self.company_id: self.company_id = self.warehouse_id.company_id self.with_context(no_change_childs=True).onchange_company_id() self.change_childs() @@ -204,8 +202,7 @@ class StockRequestOrder(models.Model): @api.onchange("company_id") def onchange_company_id(self): if self.company_id and ( - not self.warehouse_id - or self.warehouse_id.sudo().company_id != self.company_id + not self.warehouse_id or self.warehouse_id.company_id != self.company_id ): self.warehouse_id = self.env["stock.warehouse"].search( [("company_id", "=", self.company_id.id)], limit=1 @@ -225,7 +222,6 @@ class StockRequestOrder(models.Model): line.requested_by = self.requested_by line.procurement_group_id = self.procurement_group_id - @api.multi def action_confirm(self): for line in self.stock_request_ids: line.action_confirm() @@ -253,7 +249,6 @@ class StockRequestOrder(models.Model): self.action_done() return - @api.multi def action_view_transfer(self): action = self.env.ref("stock.action_picking_tree_all").read()[0] @@ -265,7 +260,6 @@ class StockRequestOrder(models.Model): action["res_id"] = pickings.id return action - @api.multi def action_view_stock_requests(self): action = self.env.ref("stock_request.action_stock_request_form").read()[0] if len(self.stock_request_ids) > 1: @@ -286,7 +280,6 @@ class StockRequestOrder(models.Model): ) return super().create(upd_vals) - @api.multi def unlink(self): if self.filtered(lambda r: r.state != "draft"): raise UserError(_("Only orders on draft state can be unlinked")) diff --git a/stock_request/models/stock_rule.py b/stock_request/models/stock_rule.py index 9368a4096..f304bd895 100644 --- a/stock_request/models/stock_rule.py +++ b/stock_request/models/stock_rule.py @@ -1,4 +1,4 @@ -# Copyright 2017 Eficent Business and IT Consulting Services, S.L. +# Copyright 2017-2020 ForgeFlow, S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from odoo import models @@ -15,8 +15,8 @@ class StockRule(models.Model): location_id, name, origin, + company_id, values, - group_id, ): result = super(StockRule, self)._get_stock_move_values( product_id, @@ -25,8 +25,8 @@ class StockRule(models.Model): location_id, name, origin, + company_id, values, - group_id, ) if values.get("stock_request_id", False): result["allocation_ids"] = [ diff --git a/stock_request/readme/CONTRIBUTORS.rst b/stock_request/readme/CONTRIBUTORS.rst index 67adc0edc..6ba1f8879 100644 --- a/stock_request/readme/CONTRIBUTORS.rst +++ b/stock_request/readme/CONTRIBUTORS.rst @@ -1,10 +1,12 @@ -* Jordi Ballester (EFICENT) . +* Jordi Ballester (EFICENT) . * Enric Tobella * Atte Isopuro -* Lois Rilo +* Lois Rilo * Raul Martin * Serpent Consulting Services Pvt. Ltd. * `Open Source Integrators `_ * Maxime Chambreuil * Steve Campbell + +* Héctor Villarreal diff --git a/stock_request/security/ir.model.access.csv b/stock_request/security/ir.model.access.csv index 7dc4569a2..6e397bc5c 100644 --- a/stock_request/security/ir.model.access.csv +++ b/stock_request/security/ir.model.access.csv @@ -4,7 +4,7 @@ access_stock_request_manager,stock request manager,model_stock_request,group_sto access_stock_request_stock_user,stock.request stock user,model_stock_request,stock.group_stock_user,1,0,0,0 access_stock_request_allocation_user,stock request allocation user,model_stock_request_allocation,group_stock_request_user,1,1,1,1 access_stock_request_allocation_manager,stock request allocation manager,model_stock_request_allocation,group_stock_request_manager,1,1,1,1 -access_stock_request_allocation_stock_user,stock.request.allocation stock user,model_stock_request_allocation,stock.group_stock_user,1,0,0,0 +access_stock_request_allocation_stock_user,stock.request.allocation stock user,model_stock_request_allocation,base.group_user,1,0,0,0 access_stock_location_user,stock.location.user,stock.model_stock_location,group_stock_request_user,1,0,0,0 access_stock_location_request_manager,stock.location request manager,stock.model_stock_location,group_stock_request_manager,1,0,0,0 access_stock_rule_request_manager,stock_rule_request_manager,stock.model_stock_rule,group_stock_request_manager,1,0,0,0 diff --git a/stock_request/security/stock_request_security.xml b/stock_request/security/stock_request_security.xml index b2c91d4da..ca8610e34 100644 --- a/stock_request/security/stock_request_security.xml +++ b/stock_request/security/stock_request_security.xml @@ -17,7 +17,7 @@ Stock Request Manager + eval="[(4, ref('stock_request.group_stock_request_user')),(4, ref('stock.group_stock_user'))]"/> diff --git a/stock_request/tests/test_stock_request.py b/stock_request/tests/test_stock_request.py index bdcd462e8..a5ac95b7d 100644 --- a/stock_request/tests/test_stock_request.py +++ b/stock_request/tests/test_stock_request.py @@ -32,6 +32,11 @@ class TestStockRequest(common.TransactionCase): self.company_2 = self.env["res.company"].create( {"name": "Comp2", "parent_id": self.main_company.id} ) + self.company_2_address = ( + self.env["res.partner"] + .with_context(company_id=self.company_2.id) + .create({"name": "Peñiscola"}) + ) self.wh2 = self.env["stock.warehouse"].search( [("company_id", "=", self.company_2.id)], limit=1 ) @@ -51,11 +56,21 @@ class TestStockRequest(common.TransactionCase): ) self.ressuply_loc = self.env["stock.location"].create( - {"name": "Ressuply", "location_id": self.warehouse.view_location_id.id} + { + "name": "Ressuply", + "location_id": self.warehouse.view_location_id.id, + "usage": "internal", + "company_id": self.main_company.id, + } ) self.ressuply_loc_2 = self.env["stock.location"].create( - {"name": "Ressuply", "location_id": self.wh2.view_location_id.id} + { + "name": "Ressuply", + "location_id": self.wh2.view_location_id.id, + "usage": "internal", + "company_id": self.company_2.id, + } ) self.route = self.env["stock.location.route"].create( @@ -99,7 +114,6 @@ class TestStockRequest(common.TransactionCase): "procure_method": "make_to_stock", "warehouse_id": self.warehouse.id, "company_id": self.main_company.id, - "propagate": "False", } ) @@ -114,7 +128,6 @@ class TestStockRequest(common.TransactionCase): "procure_method": "make_to_stock", "warehouse_id": self.wh2.id, "company_id": self.company_2.id, - "propagate": "False", } ) @@ -127,7 +140,7 @@ class TestStockRequest(common.TransactionCase): "name": name, "password": "demo", "login": name, - "email": "@".join([name, "@test.com"]), + "email": "@".join([name, "test.com"]), "groups_id": [(6, 0, group_ids)], "company_ids": [(6, 0, company_ids)], } @@ -158,7 +171,7 @@ class TestStockRequestBase(TestStockRequest): "product_uom_qty": 5.0, } stock_request = ( - self.stock_request.sudo(self.stock_request_user.id) + self.stock_request.with_user(self.stock_request_user) .with_context(company_id=self.main_company.id) .create(vals) ) @@ -172,7 +185,7 @@ class TestStockRequestBase(TestStockRequest): def test_defaults_order(self): vals = {} order = ( - self.request_order.sudo(self.stock_request_user.id) + self.request_order.with_user(self.stock_request_user) .with_context(company_id=self.main_company.id) .create(vals) ) @@ -206,7 +219,7 @@ class TestStockRequestBase(TestStockRequest): ) ], } - order = self.request_order.sudo(self.stock_request_user).new(vals) + order = self.request_order.with_user(self.stock_request_user).new(vals) self.stock_request_user.company_id = self.company_2 order.company_id = self.company_2 @@ -249,7 +262,7 @@ class TestStockRequestBase(TestStockRequest): "product_uom_qty": 5.0, "company_id": self.main_company.id, } - stock_request = self.stock_request.sudo(self.stock_request_user).new(vals) + stock_request = self.stock_request.with_user(self.stock_request_user).new(vals) stock_request.product_id = self.product vals = stock_request.default_get(["warehouse_id", "company_id"]) stock_request.update(vals) @@ -292,7 +305,14 @@ class TestStockRequestBase(TestStockRequest): wh2_2 = ( self.env["stock.warehouse"] .with_context(company_id=self.company_2.id) - .create({"name": "C2_2", "code": "C2_2", "company_id": self.company_2.id}) + .create( + { + "name": "C2_2", + "code": "C2_2", + "company_id": self.company_2.id, + "partner_id": self.company_2_address.id, + } + ) ) stock_request.warehouse_id = wh2_2 stock_request.onchange_warehouse_id() @@ -332,7 +352,7 @@ class TestStockRequestBase(TestStockRequest): ], } with self.assertRaises(exceptions.ValidationError): - self.request_order.sudo(self.stock_request_user).create(vals) + self.request_order.with_user(self.stock_request_user).create(vals) def test_stock_request_order_validations_02(self): """ Testing the discrepancy in location_id between @@ -360,7 +380,7 @@ class TestStockRequestBase(TestStockRequest): ], } with self.assertRaises(exceptions.ValidationError): - self.request_order.sudo(self.stock_request_user).create(vals) + self.request_order.with_user(self.stock_request_user).create(vals) def test_stock_request_order_validations_03(self): """ Testing the discrepancy in requested_by between @@ -390,7 +410,7 @@ class TestStockRequestBase(TestStockRequest): ], } with self.assertRaises(exceptions.ValidationError): - self.request_order.sudo(self.stock_request_user).create(vals) + self.request_order.with_user(self.stock_request_user).create(vals) def test_stock_request_order_validations_04(self): """ Testing the discrepancy in procurement_group_id between @@ -422,7 +442,7 @@ class TestStockRequestBase(TestStockRequest): ], } with self.assertRaises(exceptions.ValidationError): - self.request_order.sudo(self.stock_request_user).create(vals) + self.request_order.with_user(self.stock_request_user).create(vals) def test_stock_request_order_validations_05(self): """ Testing the discrepancy in company between @@ -450,7 +470,7 @@ class TestStockRequestBase(TestStockRequest): ], } with self.assertRaises(exceptions.ValidationError): - self.request_order.sudo(self.stock_request_user).create(vals) + self.request_order.with_user(self.stock_request_user).create(vals) def test_stock_request_order_validations_06(self): """ Testing the discrepancy in expected dates between @@ -479,7 +499,7 @@ class TestStockRequestBase(TestStockRequest): ], } with self.assertRaises(exceptions.ValidationError): - self.request_order.sudo().create(vals) + self.request_order.create(vals) def test_stock_request_order_validations_07(self): """ Testing the discrepancy in picking policy between @@ -508,7 +528,7 @@ class TestStockRequestBase(TestStockRequest): ], } with self.assertRaises(exceptions.ValidationError): - self.request_order.sudo(self.stock_request_user).create(vals) + self.request_order.with_user(self.stock_request_user).create(vals) def test_stock_request_validations_01(self): vals = { @@ -521,7 +541,7 @@ class TestStockRequestBase(TestStockRequest): } # Select a UoM that is incompatible with the product's UoM with self.assertRaises(exceptions.ValidationError): - self.stock_request.sudo(self.stock_request_user).create(vals) + self.stock_request.with_user(self.stock_request_user).create(vals) def test_stock_request_validations_02(self): vals = { @@ -533,7 +553,9 @@ class TestStockRequestBase(TestStockRequest): "location_id": self.warehouse.lot_stock_id.id, } - stock_request = self.stock_request.sudo(self.stock_request_user).create(vals) + stock_request = self.stock_request.with_user(self.stock_request_user).create( + vals + ) # With no route found, should raise an error with self.assertRaises(exceptions.UserError): @@ -563,21 +585,21 @@ class TestStockRequestBase(TestStockRequest): ], } - order = self.request_order.sudo(self.stock_request_user).create(vals) + order = self.request_order.with_user(self.stock_request_user).create(vals) stock_request = order.stock_request_ids self.product.route_ids = [(6, 0, self.route.ids)] - order.action_confirm() + order.with_user(self.stock_request_user).action_confirm() self.assertEqual(order.state, "open") self.assertEqual(stock_request.state, "open") - self.assertEqual(len(order.sudo().picking_ids), 1) - self.assertEqual(len(order.sudo().move_ids), 1) - self.assertEqual(len(stock_request.sudo().picking_ids), 1) - self.assertEqual(len(stock_request.sudo().move_ids), 1) + self.assertEqual(len(order.picking_ids), 1) + self.assertEqual(len(order.move_ids), 1) + self.assertEqual(len(stock_request.picking_ids), 1) + self.assertEqual(len(stock_request.move_ids), 1) self.assertEqual( - stock_request.sudo().move_ids[0].location_dest_id, stock_request.location_id + stock_request.move_ids[0].location_dest_id, stock_request.location_id ) self.assertEqual(stock_request.qty_in_progress, stock_request.product_uom_qty) self.env["stock.quant"].create( @@ -587,15 +609,15 @@ class TestStockRequestBase(TestStockRequest): "quantity": 5.0, } ) - picking = stock_request.sudo().picking_ids[0] - picking.action_confirm() + picking = stock_request.picking_ids[0] + picking.with_user(self.stock_request_manager).action_confirm() self.assertEqual(stock_request.qty_in_progress, 5.0) self.assertEqual(stock_request.qty_done, 0.0) - picking.action_assign() + picking.with_user(self.stock_request_manager).action_assign() self.assertEqual(picking.origin, order.name) packout1 = picking.move_line_ids[0] packout1.qty_done = 5 - picking.action_done() + picking.with_user(self.stock_request_manager).action_done() self.assertEqual(stock_request.qty_in_progress, 0.0) self.assertEqual(stock_request.qty_done, stock_request.product_uom_qty) self.assertEqual(order.state, "done") @@ -613,15 +635,17 @@ class TestStockRequestBase(TestStockRequest): "location_id": self.warehouse.lot_stock_id.id, } - stock_request = self.stock_request.sudo(self.stock_request_user).create(vals) + stock_request = self.stock_request.with_user(self.stock_request_user).create( + vals + ) self.product.route_ids = [(6, 0, self.route.ids)] - stock_request.action_confirm() + stock_request.with_user(self.stock_request_manager).action_confirm() self.assertEqual(stock_request.state, "open") - self.assertEqual(len(stock_request.sudo().picking_ids), 1) - self.assertEqual(len(stock_request.sudo().move_ids), 1) + self.assertEqual(len(stock_request.picking_ids), 1) + self.assertEqual(len(stock_request.move_ids), 1) self.assertEqual( - stock_request.sudo().move_ids[0].location_dest_id, stock_request.location_id + stock_request.move_ids[0].location_dest_id, stock_request.location_id ) self.assertEqual(stock_request.qty_in_progress, stock_request.product_uom_qty) self.env["stock.quant"].create( @@ -631,14 +655,14 @@ class TestStockRequestBase(TestStockRequest): "quantity": 12.0, } ) - picking = stock_request.sudo().picking_ids[0] - picking.action_confirm() + picking = stock_request.picking_ids[0] + picking.with_user(self.stock_request_manager).action_confirm() self.assertEqual(stock_request.qty_in_progress, 1.0) self.assertEqual(stock_request.qty_done, 0.0) - picking.action_assign() + picking.with_user(self.stock_request_manager).action_assign() packout1 = picking.move_line_ids[0] packout1.qty_done = 1 - picking.action_done() + picking.with_user(self.stock_request_manager).action_done() self.assertEqual(stock_request.qty_in_progress, 0.0) self.assertEqual(stock_request.qty_done, stock_request.product_uom_qty) self.assertEqual(stock_request.state, "done") @@ -655,22 +679,20 @@ class TestStockRequestBase(TestStockRequest): } stock_request_1 = ( - self.env["stock.request"].sudo(self.stock_request_user).create(vals) + self.env["stock.request"].with_user(self.stock_request_user).create(vals) ) stock_request_2 = ( - self.env["stock.request"].sudo(self.stock_request_manager).create(vals) + self.env["stock.request"] + .with_user(self.stock_request_manager.id) + .create(vals) ) stock_request_2.product_uom_qty = 6.0 self.product.route_ids = [(6, 0, self.route.ids)] - stock_request_1.action_confirm() - stock_request_2.action_confirm() - self.assertEqual(len(stock_request_1.sudo().picking_ids), 1) - self.assertEqual( - stock_request_1.sudo().picking_ids, stock_request_2.sudo().picking_ids - ) - self.assertEqual( - stock_request_1.sudo().move_ids, stock_request_2.sudo().move_ids - ) + stock_request_1.with_user(self.stock_request_manager).action_confirm() + stock_request_2.with_user(self.stock_request_manager).action_confirm() + self.assertEqual(len(stock_request_1.picking_ids), 1) + self.assertEqual(stock_request_1.picking_ids, stock_request_2.picking_ids) + self.assertEqual(stock_request_1.move_ids, stock_request_2.move_ids) self.env["stock.quant"].create( { "product_id": self.product.id, @@ -678,12 +700,12 @@ class TestStockRequestBase(TestStockRequest): "quantity": 10.0, } ) - picking = stock_request_1.sudo().picking_ids[0] - picking.action_confirm() - picking.action_assign() + picking = stock_request_1.picking_ids[0] + picking.with_user(self.stock_request_manager).action_confirm() + picking.with_user(self.stock_request_manager).action_assign() packout1 = picking.move_line_ids[0] packout1.qty_done = 10 - picking.action_done() + picking.with_user(self.stock_request_manager).action_done() def test_cancel_request(self): expected_date = fields.Datetime.now() @@ -709,17 +731,17 @@ class TestStockRequestBase(TestStockRequest): ], } - order = self.request_order.sudo(self.stock_request_user).create(vals) + order = self.request_order.with_user(self.stock_request_user).create(vals) self.product.route_ids = [(6, 0, self.route.ids)] - order.action_confirm() + order.with_user(self.stock_request_user).action_confirm() stock_request = order.stock_request_ids - self.assertEqual(len(order.sudo().picking_ids), 1) - self.assertEqual(len(order.sudo().move_ids), 1) - self.assertEqual(len(stock_request.sudo().picking_ids), 1) - self.assertEqual(len(stock_request.sudo().move_ids), 1) + self.assertEqual(len(order.picking_ids), 1) + self.assertEqual(len(order.move_ids), 1) + self.assertEqual(len(stock_request.picking_ids), 1) + self.assertEqual(len(stock_request.move_ids), 1) self.assertEqual( - stock_request.sudo().move_ids[0].location_dest_id, stock_request.location_id + stock_request.move_ids[0].location_dest_id, stock_request.location_id ) self.assertEqual(stock_request.qty_in_progress, stock_request.product_uom_qty) self.env["stock.quant"].create( @@ -729,26 +751,26 @@ class TestStockRequestBase(TestStockRequest): "quantity": 5.0, } ) - picking = stock_request.sudo().picking_ids[0] - picking.action_confirm() + picking = stock_request.picking_ids[0] + picking.with_user(self.stock_request_user).action_confirm() self.assertEqual(stock_request.qty_in_progress, 5.0) self.assertEqual(stock_request.qty_done, 0.0) - picking.action_assign() - order.action_cancel() + picking.with_user(self.stock_request_manager).action_assign() + order.with_user(self.stock_request_manager).action_cancel() self.assertEqual(stock_request.qty_in_progress, 0.0) self.assertEqual(stock_request.qty_done, 0.0) - self.assertEqual(len(stock_request.sudo().picking_ids), 0) + self.assertEqual(len(stock_request.picking_ids), 0) # Set the request back to draft - order.action_draft() + order.with_user(self.stock_request_user).action_draft() self.assertEqual(order.state, "draft") self.assertEqual(stock_request.state, "draft") # Re-confirm. We expect new pickings to be created - order.action_confirm() - self.assertEqual(len(stock_request.sudo().picking_ids), 1) - self.assertEqual(len(stock_request.sudo().move_ids), 2) + order.with_user(self.stock_request_user).action_confirm() + self.assertEqual(len(stock_request.picking_ids), 1) + self.assertEqual(len(stock_request.move_ids), 2) def test_view_actions(self): expected_date = fields.Datetime.now() @@ -774,10 +796,10 @@ class TestStockRequestBase(TestStockRequest): ], } - order = self.request_order.sudo().create(vals) + order = self.request_order.create(vals) self.product.route_ids = [(6, 0, self.route.ids)] - order.action_confirm() + order.with_user(self.stock_request_manager).action_confirm() stock_request = order.stock_request_ids self.assertTrue(stock_request.picking_ids) self.assertTrue(order.picking_ids) @@ -811,7 +833,9 @@ class TestStockRequestBase(TestStockRequest): "location_id": self.warehouse.lot_stock_id.id, } - stock_request = self.stock_request.sudo(self.stock_request_user).create(vals) + stock_request = self.stock_request.with_user(self.stock_request_user).create( + vals + ) # Cannot assign a warehouse that belongs to another company with self.assertRaises(exceptions.ValidationError): @@ -906,7 +930,7 @@ class TestStockRequestBase(TestStockRequest): "for creating stock requests. Please contact your " "administrator.", ): - order.sudo(self.stock_request_user)._create_from_product_multiselect( + order.with_user(self.stock_request_user)._create_from_product_multiselect( template_a + template_b ) @@ -929,7 +953,9 @@ class TestStockRequestBase(TestStockRequest): "warehouse_id": self.warehouse.id, "location_id": self.virtual_loc.id, } - stock_request = self.stock_request.sudo(self.stock_request_user).create(vals) + stock_request = self.stock_request.with_user(self.stock_request_user).create( + vals + ) stock_request.onchange_allow_virtual_location() self.assertTrue(stock_request.allow_virtual_location) vals = { @@ -937,7 +963,7 @@ class TestStockRequestBase(TestStockRequest): "warehouse_id": self.warehouse.id, "location_id": self.virtual_loc.id, } - order = self.request_order.sudo(self.stock_request_user).create(vals) + order = self.request_order.with_user(self.stock_request_user).create(vals) order.onchange_allow_virtual_location() self.assertTrue(order.allow_virtual_location) @@ -964,6 +990,6 @@ class TestStockRequestBase(TestStockRequest): ) ], } - order = self.request_order.sudo(self.stock_request_user).create(vals) + order = self.request_order.with_user(self.stock_request_user).create(vals) order.stock_request_ids.onchange_warehouse_id() self.assertEqual(order.stock_request_ids[0].location_id, self.virtual_loc) diff --git a/stock_request/views/stock_move_views.xml b/stock_request/views/stock_move_views.xml index 9a1d1baf9..c7b4cc4e5 100644 --- a/stock_request/views/stock_move_views.xml +++ b/stock_request/views/stock_move_views.xml @@ -28,19 +28,4 @@ - - stock.move.form - stock.move - - - - - - - - - - - diff --git a/stock_request/views/stock_request_order_views.xml b/stock_request/views/stock_request_order_views.xml index 84bb89551..24f0e030a 100644 --- a/stock_request/views/stock_request_order_views.xml +++ b/stock_request/views/stock_request_order_views.xml @@ -131,7 +131,6 @@ Stock Request Orders ir.actions.act_window stock.request.order - form tree,form diff --git a/stock_request/views/stock_request_views.xml b/stock_request/views/stock_request_views.xml index 80eec6f76..1c3812a35 100644 --- a/stock_request/views/stock_request_views.xml +++ b/stock_request/views/stock_request_views.xml @@ -130,7 +130,6 @@ Stock Requests stock.request ir.actions.act_window - form tree,form