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
_logger = logging.getLogger(__name__)
_inherit = 'stock.picking'
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?
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
About This Community
|Asked: 6/22/15, 2:33 AM|
|Seen: 461 times|
|Last updated: 6/22/15, 2:35 AM|