[FIX] stock: _compute_package_info when children are packages
When we put a pack in a pack and try to validate the picking, we get an error saying we are trying to create a pack operation without a location id. This is caused by the 'quant.package' location computation, when we validate a picking, odoo will create the pack operations in the next picking if there are any. And when it tries to create a pack operation of a pack in pack, it cannot get the location id of the top level package quant because in the compution of the location_id, it only looks at quants having a package_id correspeding to the package. And there are not any when the it's a package of package. To solve this issue, we fixed the function '_compute_children_quant_ids' that doesn't work either because of the same reasons. And then we use it in function '_compute_package_info' to get the quants if there are any. This bug has been introduced in rev: https://github.com/odoo/odoo/commit/fe9b31c0e703cf4f3f4f4001ab199f7a4353f9b9
This commit is contained in:
@@ -615,21 +615,17 @@ class QuantPackage(models.Model):
|
||||
@api.one
|
||||
@api.depends('parent_id', 'children_ids', 'quant_ids.package_id')
|
||||
def _compute_children_quant_ids(self):
|
||||
res = dict.fromkeys(self.ids, self.env['stock.quant'])
|
||||
children_quants = self.env['stock.quant'].search(['package_id', 'child_of', self.ids])
|
||||
for quant in children_quants:
|
||||
res[quant.package_id.id] |= quant
|
||||
for package in self:
|
||||
package.children_quant_ids = res[package.id].ids
|
||||
package.children_quant_ids = self.env['stock.quant'].search([('package_id', 'child_of', package.id)]).ids
|
||||
|
||||
@api.depends('quant_ids.package_id', 'quant_ids.location_id', 'quant_ids.company_id', 'quant_ids.owner_id', 'ancestor_ids')
|
||||
def _compute_package_info(self):
|
||||
res = {}
|
||||
quants = self.env['stock.quant'].search([('package_id', 'in', self.ids)]) # TDE FIXME: was child_od
|
||||
for quant in quants:
|
||||
res[quant.package_id.id] = {'location_id': quant.location_id.id, 'owner_id': quant.owner_id.id, 'company_id': quant.company_id.id}
|
||||
for package in self:
|
||||
values = res.get(package.id, {'location_id': False, 'company_id': self.env.user.company_id.id, 'owner_id': False})
|
||||
quants = package.children_quant_ids
|
||||
if quants:
|
||||
values = quants[0]
|
||||
else:
|
||||
values = {'location_id': False, 'company_id': self.env.user.company_id.id, 'owner_id': False}
|
||||
package.location_id = values['location_id']
|
||||
package.company_id = values['company_id']
|
||||
package.owner_id = values['owner_id']
|
||||
|
||||
Reference in New Issue
Block a user