[MIG] stock_request: Migration to 13.0

This commit is contained in:
hveficent
2020-01-29 11:48:58 +01:00
committed by Kitti U
parent 854bbe132d
commit 6b07937599
17 changed files with 170 additions and 169 deletions

View File

@@ -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). # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{ {
"name": "Stock Request", "name": "Stock Request",
"summary": "Internal request for stock", "summary": "Internal request for stock",
"version": "12.0.1.1.6", "version": "13.0.1.0.0",
"license": "LGPL-3", "license": "LGPL-3",
"website": "https://github.com/stock-logistics-warehouse", "website": "https://github.com/stock-logistics-warehouse",
"author": "Eficent, " "Odoo Community Association (OCA)", "author": "ForgeFlow, Odoo Community Association (OCA)",
"category": "Warehouse Management", "category": "Warehouse Management",
"depends": ["stock"], "depends": ["stock"],
"data": [ "data": [

View File

@@ -8,13 +8,22 @@ class ProcurementGroup(models.Model):
_inherit = "procurement.group" _inherit = "procurement.group"
@api.model @api.model
def run( def run(self, procurements):
self, product_id, product_qty, product_uom, location_id, name, origin, values indexes_to_pop = []
): new_procs = []
if "stock_request_id" in values and values.get("stock_request_id"): for i, procurement in enumerate(procurements):
req = self.env["stock.request"].browse(values.get("stock_request_id")) if "stock_request_id" in procurement.values and procurement.values.get(
if req.order_id: "stock_request_id"
origin = req.order_id.name ):
return super().run( req = self.env["stock.request"].browse(
product_id, product_qty, product_uom, location_id, name, origin, values 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)

View File

@@ -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). # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import _, api, fields, models from odoo import _, api, fields, models

View File

@@ -51,7 +51,7 @@ class StockMoveLine(models.Model):
# We do sudo because potentially the user that completes the move # We do sudo because potentially the user that completes the move
# may not have permissions for stock.request. # may not have permissions for stock.request.
to_allocate_qty = ml.qty_done 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 allocated_qty = 0.0
if allocation.open_product_qty: if allocation.open_product_qty:
allocated_qty = min(allocation.open_product_qty, qty_done) allocated_qty = min(allocation.open_product_qty, qty_done)

View File

@@ -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). # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models from odoo import api, fields, models

View File

@@ -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). # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import _, api, fields, models from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError from odoo.exceptions import UserError, ValidationError
from odoo.tools import float_compare from odoo.tools import float_compare
from odoo.addons import decimal_precision as dp
REQUEST_STATES = [ REQUEST_STATES = [
("draft", "Draft"), ("draft", "Draft"),
("open", "In progress"), ("open", "In progress"),
@@ -92,7 +90,7 @@ class StockRequest(models.Model):
) )
qty_in_progress = fields.Float( qty_in_progress = fields.Float(
"Qty In Progress", "Qty In Progress",
digits=dp.get_precision("Product Unit of Measure"), digits="Product Unit of Measure",
readonly=True, readonly=True,
compute="_compute_qty", compute="_compute_qty",
store=True, store=True,
@@ -100,7 +98,7 @@ class StockRequest(models.Model):
) )
qty_done = fields.Float( qty_done = fields.Float(
"Qty Done", "Qty Done",
digits=dp.get_precision("Product Unit of Measure"), digits="Product Unit of Measure",
readonly=True, readonly=True,
compute="_compute_qty", compute="_compute_qty",
store=True, store=True,
@@ -208,12 +206,10 @@ class StockRequest(models.Model):
if self.order_id and self.order_id.picking_policy != self.picking_policy: if self.order_id and self.order_id.picking_policy != self.picking_policy:
raise ValidationError(_("The picking policy must be equal to the order")) raise ValidationError(_("The picking policy must be equal to the order"))
@api.multi
def _action_confirm(self): def _action_confirm(self):
self._action_launch_procurement_rule() self._action_launch_procurement_rule()
self.state = "open" self.state = "open"
@api.multi
def action_confirm(self): def action_confirm(self):
self._action_confirm() self._action_confirm()
return True return True
@@ -223,7 +219,7 @@ class StockRequest(models.Model):
return True return True
def action_cancel(self): def action_cancel(self):
self.sudo().mapped("move_ids")._action_cancel() self.mapped("move_ids")._action_cancel()
self.state = "cancel" self.state = "cancel"
return True return True
@@ -271,7 +267,6 @@ class StockRequest(models.Model):
def _skip_procurement(self): def _skip_procurement(self):
return self.state != "draft" or self.product_id.type not in ("consu", "product") return self.state != "draft" or self.product_id.type not in ("consu", "product")
@api.multi
def _action_launch_procurement_rule(self): def _action_launch_procurement_rule(self):
""" """
Launch procurement group run method with required/custom Launch procurement group run method with required/custom
@@ -298,25 +293,26 @@ class StockRequest(models.Model):
group_id=request.procurement_group_id group_id=request.procurement_group_id
) )
try: try:
# We launch with sudo because potentially we could create procurements = []
# objects that the user is not authorized to create, such procurements.append(
# as PO. self.env["procurement.group"].Procurement(
self.env["procurement.group"].sudo().run( request.product_id,
request.product_id, request.product_uom_qty,
request.product_uom_qty, request.product_uom_id,
request.product_uom_id, request.location_id,
request.location_id, request.name,
request.name, request.name,
request.name, self.env.company,
values, values,
)
) )
self.env["procurement.group"].run(procurements)
except UserError as error: except UserError as error:
errors.append(error.name) errors.append(error.name)
if errors: if errors:
raise UserError("\n".join(errors)) raise UserError("\n".join(errors))
return True return True
@api.multi
def action_view_transfer(self): def action_view_transfer(self):
action = self.env.ref("stock.action_picking_tree_all").read()[0] 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") upd_vals["name"] = self.env["ir.sequence"].next_by_code("stock.request")
return super().create(upd_vals) return super().create(upd_vals)
@api.multi
def unlink(self): def unlink(self):
if self.filtered(lambda r: r.state != "draft"): if self.filtered(lambda r: r.state != "draft"):
raise UserError(_("Only requests on draft state can be unlinked")) raise UserError(_("Only requests on draft state can be unlinked"))

View File

@@ -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). # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import _, api, fields, models from odoo import _, api, fields, models
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
from odoo.addons import decimal_precision as dp
class StockRequest(models.AbstractModel): class StockRequest(models.AbstractModel):
_name = "stock.request.abstract" _name = "stock.request.abstract"
@@ -66,16 +64,16 @@ class StockRequest(models.AbstractModel):
) )
product_uom_qty = fields.Float( product_uom_qty = fields.Float(
"Quantity", "Quantity",
digits=dp.get_precision("Product Unit of Measure"), digits="Product Unit of Measure",
required=True, 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( product_qty = fields.Float(
"Real Quantity", "Real Quantity",
compute="_compute_product_qty", compute="_compute_product_qty",
store=True, store=True,
copy=False, copy=False,
digits=dp.get_precision("Product Unit of Measure"), digits="Product Unit of Measure",
help="Quantity in the default UoM of the product", help="Quantity in the default UoM of the product",
) )
procurement_group_id = fields.Many2one( procurement_group_id = fields.Many2one(
@@ -86,12 +84,7 @@ class StockRequest(models.AbstractModel):
"procurement rules will be grouped into one big picking.", "procurement rules will be grouped into one big picking.",
) )
company_id = fields.Many2one( company_id = fields.Many2one(
"res.company", "res.company", "Company", required=True, default=lambda self: self.env.company
"Company",
required=True,
default=lambda self: self.env["res.company"]._company_default_get(
"stock.request"
),
) )
route_id = fields.Many2one( route_id = fields.Many2one(
"stock.location.route", "stock.location.route",
@@ -202,8 +195,8 @@ class StockRequest(models.AbstractModel):
def _check_qty(self): def _check_qty(self):
for rec in self: for rec in self:
if rec.product_qty <= 0: if rec.product_qty <= 0:
raise ValueError( raise ValidationError(
_("Stock Request product quantity has to be" " strictly positive.") _("Stock Request product quantity has to be strictly positive.")
) )
@api.onchange("warehouse_id") @api.onchange("warehouse_id")
@@ -217,7 +210,7 @@ class StockRequest(models.AbstractModel):
# the onchange, as it could lead to inconsistencies. # the onchange, as it could lead to inconsistencies.
return res return res
if self.warehouse_id: 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: if self.warehouse_id != loc_wh:
self.location_id = self.warehouse_id.lot_stock_id.id self.location_id = self.warehouse_id.lot_stock_id.id
if self.warehouse_id.company_id != self.company_id: if self.warehouse_id.company_id != self.company_id:
@@ -227,7 +220,7 @@ class StockRequest(models.AbstractModel):
@api.onchange("location_id") @api.onchange("location_id")
def onchange_location_id(self): def onchange_location_id(self):
if self.location_id: 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: if loc_wh and self.warehouse_id != loc_wh:
self.warehouse_id = loc_wh self.warehouse_id = loc_wh
self.with_context(no_change_childs=True).onchange_warehouse_id() self.with_context(no_change_childs=True).onchange_warehouse_id()

View File

@@ -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). # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models from odoo import api, fields, models

View File

@@ -92,9 +92,7 @@ class StockRequestOrder(models.Model):
required=True, required=True,
readonly=True, readonly=True,
states={"draft": [("readonly", False)]}, states={"draft": [("readonly", False)]},
default=lambda self: self.env["res.company"]._company_default_get( default=lambda self: self.env.company,
"stock.request.order"
),
) )
expected_date = fields.Datetime( expected_date = fields.Datetime(
"Expected Date", "Expected Date",
@@ -173,7 +171,7 @@ class StockRequestOrder(models.Model):
@api.onchange("location_id") @api.onchange("location_id")
def onchange_location_id(self): def onchange_location_id(self):
if self.location_id: 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: if loc_wh and self.warehouse_id != loc_wh:
self.warehouse_id = loc_wh self.warehouse_id = loc_wh
self.with_context(no_change_childs=True).onchange_warehouse_id() self.with_context(no_change_childs=True).onchange_warehouse_id()
@@ -188,11 +186,11 @@ class StockRequestOrder(models.Model):
def onchange_warehouse_id(self): def onchange_warehouse_id(self):
if self.warehouse_id: if self.warehouse_id:
# search with sudo because the user may not have permissions # 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: 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() 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.company_id = self.warehouse_id.company_id
self.with_context(no_change_childs=True).onchange_company_id() self.with_context(no_change_childs=True).onchange_company_id()
self.change_childs() self.change_childs()
@@ -204,8 +202,7 @@ class StockRequestOrder(models.Model):
@api.onchange("company_id") @api.onchange("company_id")
def onchange_company_id(self): def onchange_company_id(self):
if self.company_id and ( if self.company_id and (
not self.warehouse_id not self.warehouse_id or self.warehouse_id.company_id != self.company_id
or self.warehouse_id.sudo().company_id != self.company_id
): ):
self.warehouse_id = self.env["stock.warehouse"].search( self.warehouse_id = self.env["stock.warehouse"].search(
[("company_id", "=", self.company_id.id)], limit=1 [("company_id", "=", self.company_id.id)], limit=1
@@ -225,7 +222,6 @@ class StockRequestOrder(models.Model):
line.requested_by = self.requested_by line.requested_by = self.requested_by
line.procurement_group_id = self.procurement_group_id line.procurement_group_id = self.procurement_group_id
@api.multi
def action_confirm(self): def action_confirm(self):
for line in self.stock_request_ids: for line in self.stock_request_ids:
line.action_confirm() line.action_confirm()
@@ -253,7 +249,6 @@ class StockRequestOrder(models.Model):
self.action_done() self.action_done()
return return
@api.multi
def action_view_transfer(self): def action_view_transfer(self):
action = self.env.ref("stock.action_picking_tree_all").read()[0] action = self.env.ref("stock.action_picking_tree_all").read()[0]
@@ -265,7 +260,6 @@ class StockRequestOrder(models.Model):
action["res_id"] = pickings.id action["res_id"] = pickings.id
return action return action
@api.multi
def action_view_stock_requests(self): def action_view_stock_requests(self):
action = self.env.ref("stock_request.action_stock_request_form").read()[0] action = self.env.ref("stock_request.action_stock_request_form").read()[0]
if len(self.stock_request_ids) > 1: if len(self.stock_request_ids) > 1:
@@ -286,7 +280,6 @@ class StockRequestOrder(models.Model):
) )
return super().create(upd_vals) return super().create(upd_vals)
@api.multi
def unlink(self): def unlink(self):
if self.filtered(lambda r: r.state != "draft"): if self.filtered(lambda r: r.state != "draft"):
raise UserError(_("Only orders on draft state can be unlinked")) raise UserError(_("Only orders on draft state can be unlinked"))

View File

@@ -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). # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import models from odoo import models
@@ -15,8 +15,8 @@ class StockRule(models.Model):
location_id, location_id,
name, name,
origin, origin,
company_id,
values, values,
group_id,
): ):
result = super(StockRule, self)._get_stock_move_values( result = super(StockRule, self)._get_stock_move_values(
product_id, product_id,
@@ -25,8 +25,8 @@ class StockRule(models.Model):
location_id, location_id,
name, name,
origin, origin,
company_id,
values, values,
group_id,
) )
if values.get("stock_request_id", False): if values.get("stock_request_id", False):
result["allocation_ids"] = [ result["allocation_ids"] = [

View File

@@ -1,10 +1,12 @@
* Jordi Ballester (EFICENT) <jordi.ballester@eficent.com>. * Jordi Ballester (EFICENT) <jordi.ballester@forgeflow.com>.
* Enric Tobella <etobella@creublanca.es> * Enric Tobella <etobella@creublanca.es>
* Atte Isopuro <atte.isopuro@avoin.systems> * Atte Isopuro <atte.isopuro@avoin.systems>
* Lois Rilo <lois.rilo@eficent.com> * Lois Rilo <lois.rilo@forgeflow.com>
* Raul Martin <raul.martin@braintec-group.com> * Raul Martin <raul.martin@braintec-group.com>
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com> * Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>
* `Open Source Integrators <https://www.opensourceintegrators.com>`_ * `Open Source Integrators <https://www.opensourceintegrators.com>`_
* Maxime Chambreuil <mchambreuil@opensourceintegrators.com> * Maxime Chambreuil <mchambreuil@opensourceintegrators.com>
* Steve Campbell <scampbell@opensourceintegrators.com> * Steve Campbell <scampbell@opensourceintegrators.com>
* Héctor Villarreal <hector.villarreal@forgeflow.com>

View File

@@ -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_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_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_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_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_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 access_stock_rule_request_manager,stock_rule_request_manager,stock.model_stock_rule,group_stock_request_manager,1,0,0,0
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
4 access_stock_request_stock_user stock.request stock user model_stock_request stock.group_stock_user 1 0 0 0
5 access_stock_request_allocation_user stock request allocation user model_stock_request_allocation group_stock_request_user 1 1 1 1
6 access_stock_request_allocation_manager stock request allocation manager model_stock_request_allocation group_stock_request_manager 1 1 1 1
7 access_stock_request_allocation_stock_user stock.request.allocation stock user model_stock_request_allocation stock.group_stock_user base.group_user 1 0 0 0
8 access_stock_location_user stock.location.user stock.model_stock_location group_stock_request_user 1 0 0 0
9 access_stock_location_request_manager stock.location request manager stock.model_stock_location group_stock_request_manager 1 0 0 0
10 access_stock_rule_request_manager stock_rule_request_manager stock.model_stock_rule group_stock_request_manager 1 0 0 0

View File

@@ -17,7 +17,7 @@
<field name="name">Stock Request Manager</field> <field name="name">Stock Request Manager</field>
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/> <field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
<field name="implied_ids" <field name="implied_ids"
eval="[(4, ref('stock_request.group_stock_request_user'))]"/> eval="[(4, ref('stock_request.group_stock_request_user')),(4, ref('stock.group_stock_user'))]"/>
<field name="category_id" ref="module_category_stock_request"/> <field name="category_id" ref="module_category_stock_request"/>
</record> </record>

View File

@@ -32,6 +32,11 @@ class TestStockRequest(common.TransactionCase):
self.company_2 = self.env["res.company"].create( self.company_2 = self.env["res.company"].create(
{"name": "Comp2", "parent_id": self.main_company.id} {"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( self.wh2 = self.env["stock.warehouse"].search(
[("company_id", "=", self.company_2.id)], limit=1 [("company_id", "=", self.company_2.id)], limit=1
) )
@@ -51,11 +56,21 @@ class TestStockRequest(common.TransactionCase):
) )
self.ressuply_loc = self.env["stock.location"].create( 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( 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( self.route = self.env["stock.location.route"].create(
@@ -99,7 +114,6 @@ class TestStockRequest(common.TransactionCase):
"procure_method": "make_to_stock", "procure_method": "make_to_stock",
"warehouse_id": self.warehouse.id, "warehouse_id": self.warehouse.id,
"company_id": self.main_company.id, "company_id": self.main_company.id,
"propagate": "False",
} }
) )
@@ -114,7 +128,6 @@ class TestStockRequest(common.TransactionCase):
"procure_method": "make_to_stock", "procure_method": "make_to_stock",
"warehouse_id": self.wh2.id, "warehouse_id": self.wh2.id,
"company_id": self.company_2.id, "company_id": self.company_2.id,
"propagate": "False",
} }
) )
@@ -127,7 +140,7 @@ class TestStockRequest(common.TransactionCase):
"name": name, "name": name,
"password": "demo", "password": "demo",
"login": name, "login": name,
"email": "@".join([name, "@test.com"]), "email": "@".join([name, "test.com"]),
"groups_id": [(6, 0, group_ids)], "groups_id": [(6, 0, group_ids)],
"company_ids": [(6, 0, company_ids)], "company_ids": [(6, 0, company_ids)],
} }
@@ -158,7 +171,7 @@ class TestStockRequestBase(TestStockRequest):
"product_uom_qty": 5.0, "product_uom_qty": 5.0,
} }
stock_request = ( 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) .with_context(company_id=self.main_company.id)
.create(vals) .create(vals)
) )
@@ -172,7 +185,7 @@ class TestStockRequestBase(TestStockRequest):
def test_defaults_order(self): def test_defaults_order(self):
vals = {} vals = {}
order = ( 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) .with_context(company_id=self.main_company.id)
.create(vals) .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 self.stock_request_user.company_id = self.company_2
order.company_id = self.company_2 order.company_id = self.company_2
@@ -249,7 +262,7 @@ class TestStockRequestBase(TestStockRequest):
"product_uom_qty": 5.0, "product_uom_qty": 5.0,
"company_id": self.main_company.id, "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 stock_request.product_id = self.product
vals = stock_request.default_get(["warehouse_id", "company_id"]) vals = stock_request.default_get(["warehouse_id", "company_id"])
stock_request.update(vals) stock_request.update(vals)
@@ -292,7 +305,14 @@ class TestStockRequestBase(TestStockRequest):
wh2_2 = ( wh2_2 = (
self.env["stock.warehouse"] self.env["stock.warehouse"]
.with_context(company_id=self.company_2.id) .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.warehouse_id = wh2_2
stock_request.onchange_warehouse_id() stock_request.onchange_warehouse_id()
@@ -332,7 +352,7 @@ class TestStockRequestBase(TestStockRequest):
], ],
} }
with self.assertRaises(exceptions.ValidationError): 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): def test_stock_request_order_validations_02(self):
""" Testing the discrepancy in location_id between """ Testing the discrepancy in location_id between
@@ -360,7 +380,7 @@ class TestStockRequestBase(TestStockRequest):
], ],
} }
with self.assertRaises(exceptions.ValidationError): 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): def test_stock_request_order_validations_03(self):
""" Testing the discrepancy in requested_by between """ Testing the discrepancy in requested_by between
@@ -390,7 +410,7 @@ class TestStockRequestBase(TestStockRequest):
], ],
} }
with self.assertRaises(exceptions.ValidationError): 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): def test_stock_request_order_validations_04(self):
""" Testing the discrepancy in procurement_group_id between """ Testing the discrepancy in procurement_group_id between
@@ -422,7 +442,7 @@ class TestStockRequestBase(TestStockRequest):
], ],
} }
with self.assertRaises(exceptions.ValidationError): 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): def test_stock_request_order_validations_05(self):
""" Testing the discrepancy in company between """ Testing the discrepancy in company between
@@ -450,7 +470,7 @@ class TestStockRequestBase(TestStockRequest):
], ],
} }
with self.assertRaises(exceptions.ValidationError): 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): def test_stock_request_order_validations_06(self):
""" Testing the discrepancy in expected dates between """ Testing the discrepancy in expected dates between
@@ -479,7 +499,7 @@ class TestStockRequestBase(TestStockRequest):
], ],
} }
with self.assertRaises(exceptions.ValidationError): with self.assertRaises(exceptions.ValidationError):
self.request_order.sudo().create(vals) self.request_order.create(vals)
def test_stock_request_order_validations_07(self): def test_stock_request_order_validations_07(self):
""" Testing the discrepancy in picking policy between """ Testing the discrepancy in picking policy between
@@ -508,7 +528,7 @@ class TestStockRequestBase(TestStockRequest):
], ],
} }
with self.assertRaises(exceptions.ValidationError): 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): def test_stock_request_validations_01(self):
vals = { vals = {
@@ -521,7 +541,7 @@ class TestStockRequestBase(TestStockRequest):
} }
# Select a UoM that is incompatible with the product's UoM # Select a UoM that is incompatible with the product's UoM
with self.assertRaises(exceptions.ValidationError): 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): def test_stock_request_validations_02(self):
vals = { vals = {
@@ -533,7 +553,9 @@ class TestStockRequestBase(TestStockRequest):
"location_id": self.warehouse.lot_stock_id.id, "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 no route found, should raise an error
with self.assertRaises(exceptions.UserError): 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 stock_request = order.stock_request_ids
self.product.route_ids = [(6, 0, self.route.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(order.state, "open")
self.assertEqual(stock_request.state, "open") self.assertEqual(stock_request.state, "open")
self.assertEqual(len(order.sudo().picking_ids), 1) self.assertEqual(len(order.picking_ids), 1)
self.assertEqual(len(order.sudo().move_ids), 1) self.assertEqual(len(order.move_ids), 1)
self.assertEqual(len(stock_request.sudo().picking_ids), 1) self.assertEqual(len(stock_request.picking_ids), 1)
self.assertEqual(len(stock_request.sudo().move_ids), 1) self.assertEqual(len(stock_request.move_ids), 1)
self.assertEqual( 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.assertEqual(stock_request.qty_in_progress, stock_request.product_uom_qty)
self.env["stock.quant"].create( self.env["stock.quant"].create(
@@ -587,15 +609,15 @@ class TestStockRequestBase(TestStockRequest):
"quantity": 5.0, "quantity": 5.0,
} }
) )
picking = stock_request.sudo().picking_ids[0] picking = stock_request.picking_ids[0]
picking.action_confirm() picking.with_user(self.stock_request_manager).action_confirm()
self.assertEqual(stock_request.qty_in_progress, 5.0) self.assertEqual(stock_request.qty_in_progress, 5.0)
self.assertEqual(stock_request.qty_done, 0.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) self.assertEqual(picking.origin, order.name)
packout1 = picking.move_line_ids[0] packout1 = picking.move_line_ids[0]
packout1.qty_done = 5 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_in_progress, 0.0)
self.assertEqual(stock_request.qty_done, stock_request.product_uom_qty) self.assertEqual(stock_request.qty_done, stock_request.product_uom_qty)
self.assertEqual(order.state, "done") self.assertEqual(order.state, "done")
@@ -613,15 +635,17 @@ class TestStockRequestBase(TestStockRequest):
"location_id": self.warehouse.lot_stock_id.id, "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)] 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(stock_request.state, "open")
self.assertEqual(len(stock_request.sudo().picking_ids), 1) self.assertEqual(len(stock_request.picking_ids), 1)
self.assertEqual(len(stock_request.sudo().move_ids), 1) self.assertEqual(len(stock_request.move_ids), 1)
self.assertEqual( 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.assertEqual(stock_request.qty_in_progress, stock_request.product_uom_qty)
self.env["stock.quant"].create( self.env["stock.quant"].create(
@@ -631,14 +655,14 @@ class TestStockRequestBase(TestStockRequest):
"quantity": 12.0, "quantity": 12.0,
} }
) )
picking = stock_request.sudo().picking_ids[0] picking = stock_request.picking_ids[0]
picking.action_confirm() picking.with_user(self.stock_request_manager).action_confirm()
self.assertEqual(stock_request.qty_in_progress, 1.0) self.assertEqual(stock_request.qty_in_progress, 1.0)
self.assertEqual(stock_request.qty_done, 0.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 = picking.move_line_ids[0]
packout1.qty_done = 1 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_in_progress, 0.0)
self.assertEqual(stock_request.qty_done, stock_request.product_uom_qty) self.assertEqual(stock_request.qty_done, stock_request.product_uom_qty)
self.assertEqual(stock_request.state, "done") self.assertEqual(stock_request.state, "done")
@@ -655,22 +679,20 @@ class TestStockRequestBase(TestStockRequest):
} }
stock_request_1 = ( 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 = ( 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 stock_request_2.product_uom_qty = 6.0
self.product.route_ids = [(6, 0, self.route.ids)] self.product.route_ids = [(6, 0, self.route.ids)]
stock_request_1.action_confirm() stock_request_1.with_user(self.stock_request_manager).action_confirm()
stock_request_2.action_confirm() stock_request_2.with_user(self.stock_request_manager).action_confirm()
self.assertEqual(len(stock_request_1.sudo().picking_ids), 1) self.assertEqual(len(stock_request_1.picking_ids), 1)
self.assertEqual( self.assertEqual(stock_request_1.picking_ids, stock_request_2.picking_ids)
stock_request_1.sudo().picking_ids, stock_request_2.sudo().picking_ids self.assertEqual(stock_request_1.move_ids, stock_request_2.move_ids)
)
self.assertEqual(
stock_request_1.sudo().move_ids, stock_request_2.sudo().move_ids
)
self.env["stock.quant"].create( self.env["stock.quant"].create(
{ {
"product_id": self.product.id, "product_id": self.product.id,
@@ -678,12 +700,12 @@ class TestStockRequestBase(TestStockRequest):
"quantity": 10.0, "quantity": 10.0,
} }
) )
picking = stock_request_1.sudo().picking_ids[0] picking = stock_request_1.picking_ids[0]
picking.action_confirm() picking.with_user(self.stock_request_manager).action_confirm()
picking.action_assign() picking.with_user(self.stock_request_manager).action_assign()
packout1 = picking.move_line_ids[0] packout1 = picking.move_line_ids[0]
packout1.qty_done = 10 packout1.qty_done = 10
picking.action_done() picking.with_user(self.stock_request_manager).action_done()
def test_cancel_request(self): def test_cancel_request(self):
expected_date = fields.Datetime.now() 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)] 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 stock_request = order.stock_request_ids
self.assertEqual(len(order.sudo().picking_ids), 1) self.assertEqual(len(order.picking_ids), 1)
self.assertEqual(len(order.sudo().move_ids), 1) self.assertEqual(len(order.move_ids), 1)
self.assertEqual(len(stock_request.sudo().picking_ids), 1) self.assertEqual(len(stock_request.picking_ids), 1)
self.assertEqual(len(stock_request.sudo().move_ids), 1) self.assertEqual(len(stock_request.move_ids), 1)
self.assertEqual( 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.assertEqual(stock_request.qty_in_progress, stock_request.product_uom_qty)
self.env["stock.quant"].create( self.env["stock.quant"].create(
@@ -729,26 +751,26 @@ class TestStockRequestBase(TestStockRequest):
"quantity": 5.0, "quantity": 5.0,
} }
) )
picking = stock_request.sudo().picking_ids[0] picking = stock_request.picking_ids[0]
picking.action_confirm() picking.with_user(self.stock_request_user).action_confirm()
self.assertEqual(stock_request.qty_in_progress, 5.0) self.assertEqual(stock_request.qty_in_progress, 5.0)
self.assertEqual(stock_request.qty_done, 0.0) self.assertEqual(stock_request.qty_done, 0.0)
picking.action_assign() picking.with_user(self.stock_request_manager).action_assign()
order.action_cancel() order.with_user(self.stock_request_manager).action_cancel()
self.assertEqual(stock_request.qty_in_progress, 0.0) self.assertEqual(stock_request.qty_in_progress, 0.0)
self.assertEqual(stock_request.qty_done, 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 # 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(order.state, "draft")
self.assertEqual(stock_request.state, "draft") self.assertEqual(stock_request.state, "draft")
# Re-confirm. We expect new pickings to be created # Re-confirm. We expect new pickings to be created
order.action_confirm() order.with_user(self.stock_request_user).action_confirm()
self.assertEqual(len(stock_request.sudo().picking_ids), 1) self.assertEqual(len(stock_request.picking_ids), 1)
self.assertEqual(len(stock_request.sudo().move_ids), 2) self.assertEqual(len(stock_request.move_ids), 2)
def test_view_actions(self): def test_view_actions(self):
expected_date = fields.Datetime.now() 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)] 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 stock_request = order.stock_request_ids
self.assertTrue(stock_request.picking_ids) self.assertTrue(stock_request.picking_ids)
self.assertTrue(order.picking_ids) self.assertTrue(order.picking_ids)
@@ -811,7 +833,9 @@ class TestStockRequestBase(TestStockRequest):
"location_id": self.warehouse.lot_stock_id.id, "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 # Cannot assign a warehouse that belongs to another company
with self.assertRaises(exceptions.ValidationError): with self.assertRaises(exceptions.ValidationError):
@@ -906,7 +930,7 @@ class TestStockRequestBase(TestStockRequest):
"for creating stock requests. Please contact your " "for creating stock requests. Please contact your "
"administrator.", "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 template_a + template_b
) )
@@ -929,7 +953,9 @@ class TestStockRequestBase(TestStockRequest):
"warehouse_id": self.warehouse.id, "warehouse_id": self.warehouse.id,
"location_id": self.virtual_loc.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() stock_request.onchange_allow_virtual_location()
self.assertTrue(stock_request.allow_virtual_location) self.assertTrue(stock_request.allow_virtual_location)
vals = { vals = {
@@ -937,7 +963,7 @@ class TestStockRequestBase(TestStockRequest):
"warehouse_id": self.warehouse.id, "warehouse_id": self.warehouse.id,
"location_id": self.virtual_loc.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() order.onchange_allow_virtual_location()
self.assertTrue(order.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() order.stock_request_ids.onchange_warehouse_id()
self.assertEqual(order.stock_request_ids[0].location_id, self.virtual_loc) self.assertEqual(order.stock_request_ids[0].location_id, self.virtual_loc)

View File

@@ -28,19 +28,4 @@
</field> </field>
</record> </record>
<record id="view_move_picking_form" model="ir.ui.view">
<field name="name">stock.move.form</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_picking_form"/>
<field name="arch" type="xml">
<group name="quants_grp" position="after">
<newline/>
<group name="allocations"
string="Stock Request Allocations">
<field name="allocation_ids"/>
</group>
</group>
</field>
</record>
</odoo> </odoo>

View File

@@ -131,7 +131,6 @@
<field name="name">Stock Request Orders</field> <field name="name">Stock Request Orders</field>
<field name="type">ir.actions.act_window</field> <field name="type">ir.actions.act_window</field>
<field name="res_model">stock.request.order</field> <field name="res_model">stock.request.order</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field> <field name="view_mode">tree,form</field>
</record> </record>

View File

@@ -130,7 +130,6 @@
<field name="name">Stock Requests</field> <field name="name">Stock Requests</field>
<field name="res_model">stock.request</field> <field name="res_model">stock.request</field>
<field name="type">ir.actions.act_window</field> <field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field> <field name="view_mode">tree,form</field>
<field name="view_id" ref="view_stock_request_tree"/> <field name="view_id" ref="view_stock_request_tree"/>
<field name="search_view_id" ref="stock_request_search" /> <field name="search_view_id" ref="stock_request_search" />