From b21aee4b88d09559e7067f7f2a6af85667c7d138 Mon Sep 17 00:00:00 2001 From: William Henrotin Date: Wed, 27 Feb 2019 11:34:17 +0000 Subject: [PATCH] [FIX] stock: location domain on reordering rules The model reordering rules (stock.warehous.orderpoint) has two fields waherouse_id and location_id. This commit will restrict the domain on location_id depending on the warehouse set. The user can now choose only locations child of the warehouse view location or location with no warehouse parent. Task : 1933828 closes odoo/odoo#30760 Signed-off-by: Arnold Moyaux --- addons/stock/models/stock_warehouse.py | 13 +++++++++++++ addons/stock/views/stock_warehouse_views.xml | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_warehouse.py b/addons/stock/models/stock_warehouse.py index 20a252b8307..ce2e3bfa374 100644 --- a/addons/stock/models/stock_warehouse.py +++ b/addons/stock/models/stock_warehouse.py @@ -9,6 +9,7 @@ from odoo import api, fields, models, _ from odoo.addons import decimal_precision as dp from odoo.exceptions import UserError, ValidationError from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT +from odoo.osv import expression import logging @@ -936,11 +937,23 @@ class Orderpoint(models.Model): lead_type = fields.Selection( [('net', 'Day(s) to get the products'), ('supplier', 'Day(s) to purchase')], 'Lead Type', required=True, default='supplier') + allowed_location_ids = fields.One2many(comodel_name='stock.location', compute='_compute_allowed_location_ids') _sql_constraints = [ ('qty_multiple_check', 'CHECK( qty_multiple >= 0 )', 'Qty Multiple must be greater than or equal to zero.'), ] + @api.depends('warehouse_id') + def _compute_allowed_location_ids(self): + loc_domain = [('usage', 'in', ('internal', 'view'))] + # We want to keep only the locations + # - strictly belonging to our warehouse + # - not belonging to any warehouses + other_warehouses = self.env['stock.warehouse'].search([('id', '!=', self.warehouse_id.id)]) + for view_location_id in other_warehouses.mapped('view_location_id'): + loc_domain = expression.AND([loc_domain, ['!', ('id', 'child_of', view_location_id.id)]]) + self.allowed_location_ids = self.env['stock.location'].search(loc_domain) + def _quantity_in_progress(self): """Return Quantities that are not yet in virtual stock but should be deduced from orderpoint rule (example: purchases created from orderpoints)""" diff --git a/addons/stock/views/stock_warehouse_views.xml b/addons/stock/views/stock_warehouse_views.xml index aab08987ed4..dd0f95be9fd 100644 --- a/addons/stock/views/stock_warehouse_views.xml +++ b/addons/stock/views/stock_warehouse_views.xml @@ -217,9 +217,10 @@ + - +