|
1 | 1 | # Copyright 2022 ACSONE SA
|
2 | 2 | # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
3 | 3 | from odoo import _, api, fields, models
|
| 4 | +from odoo.osv.expression import AND, OR |
4 | 5 |
|
5 | 6 |
|
6 | 7 | class StorageCategoryProductCapacity(models.Model):
|
@@ -95,7 +96,34 @@ def _domain_location_storage_type(self, candidate_locations, quants, products):
|
95 | 96 | ]
|
96 | 97 | # Build the domain using the 'allow_new_product' field
|
97 | 98 | if self.allow_new_product == "empty":
|
98 |
| - location_domain.append(("location_is_empty", "=", True)) |
| 99 | + # We should include the destination location of the current |
| 100 | + # stock move line to avoid excluding it if already selected |
| 101 | + # Indeed, if the current move line point to the last void location, |
| 102 | + # calling the putaway apply will recompute the destination location |
| 103 | + # to the related stock.move destination as the rules consider |
| 104 | + # there is no more room available (which is not true). |
| 105 | + exclude_sml_ids = self.env.context.get("exclude_sml_ids") |
| 106 | + if exclude_sml_ids: |
| 107 | + lines_locations = ( |
| 108 | + self.env["stock.move.line"].browse(exclude_sml_ids).location_dest_id |
| 109 | + ) |
| 110 | + if lines_locations: |
| 111 | + location_domain = AND( |
| 112 | + [ |
| 113 | + location_domain, |
| 114 | + OR( |
| 115 | + [ |
| 116 | + [ |
| 117 | + ("location_is_empty", "=", False), |
| 118 | + ("id", "in", lines_locations.ids), |
| 119 | + ], |
| 120 | + [("location_is_empty", "=", True)], |
| 121 | + ] |
| 122 | + ), |
| 123 | + ] |
| 124 | + ) |
| 125 | + else: |
| 126 | + location_domain.append(("location_is_empty", "=", True)) |
99 | 127 | elif self.allow_new_product == "same":
|
100 | 128 | location_domain += self._get_product_location_domain(products)
|
101 | 129 | elif self.allow_new_product == "same_lot":
|
|
0 commit comments