From ad50d13b6a2fca724f3c5024b4d2acdbf8732709 Mon Sep 17 00:00:00 2001 From: Olivier Dony <odo@openerp.com> Date: Mon, 5 Sep 2016 15:00:10 +0200 Subject: [PATCH] [FIX] stock: select picking type deterministically The default order on `sequence` was not specific enough, causing semi-random selection of picking type and warehouse when several types exist with the same sequence. The problem was made more likely by the fact that warehouses create their own picking types. The algorithm to determine the sequences for the new types was not handling properly the case of a NULL sequence. The patch fixes both issues: the selection of the default picking type (e.g. for purchase orders), and the algorithm for choosing the sequence for new picking types. --- addons/stock/models/stock_picking.py | 2 +- addons/stock/models/stock_warehouse.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index 61ad4964c4f2..6b7141aabd7a 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -15,7 +15,7 @@ from odoo.exceptions import UserError class PickingType(models.Model): _name = "stock.picking.type" _description = "The picking type determines the picking view" - _order = 'sequence' + _order = 'sequence, id' name = fields.Char('Picking Type Name', required=True, translate=True) color = fields.Integer('Color') diff --git a/addons/stock/models/stock_warehouse.py b/addons/stock/models/stock_warehouse.py index 4bcc8edfb98b..051bc2774a62 100644 --- a/addons/stock/models/stock_warehouse.py +++ b/addons/stock/models/stock_warehouse.py @@ -188,7 +188,7 @@ class Warehouse(models.Model): color = available_colors and available_colors[0] or 0 # suit for each warehouse: reception, internal, pick, pack, ship - max_sequence = PickingType.search_read([], ['sequence'], limit=1, order='sequence desc') + max_sequence = PickingType.search_read([('sequence', '!=', False)], ['sequence'], limit=1, order='sequence desc') max_sequence = max_sequence and max_sequence[0]['sequence'] or 0 warehouse_data = {} -- GitLab