I'm trying to add a field to stock.picking that would compute the set of packages created during the transfer operation.
stock.picking has a One2many relation to the package operations, and each package operation has a Many2one relation with the resulting package, so the relations might look like this:
Picking A is related to 3 Pack Ops: [1, 2, 3].
Pack Op 1 is related to Package x.
Pack Op 2 and 3 are both related to package y.
I want the set of packages [x, y]. However, if I loop through the packing operations, I will get [x, y, y]. I need this set in a QWeb template, so I don't have access to full Python functionality.
This is the code I have so far:
# -*- coding: utf-8 -*-
from openerp import models, fields, api
import logging
_logger = logging.getLogger(__name__)
class Picking(models.Model):
_inherit = 'stock.picking'
@api.depends('pack_operation_ids')
def _compute_result_packages(self):
self.result_packages = self.mapped('pack_operation_ids.result_package_id')
result_packages = fields.One2many(compute=_compute_result_packages, comodel_name='stock.quant.package')
However, updating the module where this Python file is imported does not change the model (checked via Settings -> Technical -> Database Structure -> Models and via erppeek 1.6.1).
There are other changes in the same file that are successfully applied, so it seems I must have defined the field incorrectly.
How do I set up a computed field for this kind of relation?