|
7 | 7 |
|
8 | 8 | from odoo import api, fields, models
|
9 | 9 | from odoo.fields import Command
|
10 |
| -from odoo.tools import float_compare, index_exists |
| 10 | +from odoo.tools import float_compare, groupby, index_exists |
11 | 11 |
|
12 | 12 | _logger = logging.getLogger(__name__)
|
13 | 13 | OUT_MOVE_LINE_DOMAIN = [
|
@@ -703,18 +703,18 @@ def _order_allowed_locations(self, valid_locations):
|
703 | 703 | valid_no_mix = valid_locations.filtered("do_not_mix_products")
|
704 | 704 | loc_ordered_by_qty = []
|
705 | 705 | if valid_no_mix:
|
706 |
| - StockQuant = self.env["stock.quant"] |
707 |
| - domain_quant = [("location_id", "in", valid_no_mix.ids)] |
708 |
| - loc_ordered_by_qty = [ |
709 |
| - item["location_id"][0] |
710 |
| - for item in StockQuant.read_group( |
711 |
| - domain_quant, |
712 |
| - ["location_id", "quantity"], |
713 |
| - ["location_id"], |
714 |
| - orderby="quantity", |
| 706 | + for location, items in groupby( |
| 707 | + valid_no_mix.quant_ids.sorted("quantity"), |
| 708 | + lambda quant: quant.location_id, |
| 709 | + ): |
| 710 | + loc_ordered_by_qty.extend( |
| 711 | + [ |
| 712 | + location.id |
| 713 | + for item in items |
| 714 | + if (float_compare(item["quantity"], 0, precision_digits=2) > 0) |
| 715 | + ] |
715 | 716 | )
|
716 |
| - if (float_compare(item["quantity"], 0, precision_digits=2) > 0) |
717 |
| - ] |
| 717 | + |
718 | 718 | valid_location_ids = set(valid_locations.ids) - set(loc_ordered_by_qty)
|
719 | 719 | ordered_valid_location_ids = loc_ordered_by_qty + [
|
720 | 720 | id_ for id_ in self.ids if id_ in valid_location_ids
|
|
0 commit comments