[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 <amoyaux@users.noreply.github.com>
This commit is contained in:
William Henrotin
2019-02-27 11:34:17 +00:00
parent def05a1f46
commit b21aee4b88
2 changed files with 15 additions and 1 deletions
+13
View File
@@ -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)"""
+2 -1
View File
@@ -217,9 +217,10 @@
<field name="product_id"/>
</group>
<group>
<field name="allowed_location_ids" invisible="1"/>
<field name="warehouse_id" widget="selection" groups="stock.group_stock_multi_locations"/>
<field name="product_uom" options="{'no_open': True, 'no_create': True}" groups="uom.group_uom"/>
<field name="location_id" groups="stock.group_stock_multi_locations" domain="[('usage', 'in', ('internal', 'view'))]"/>
<field name="location_id" groups="stock.group_stock_multi_locations" domain="[('id', 'in', allowed_location_ids)]"/>
<field name="group_id" groups="stock.group_adv_location"/>
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
</group>