Hello all,
I am trying to perform a filter/search through a wizard for a One2manyfield. The One2manyfield connects to the model stock.picking. I created a TransientModel in which a user can pick a Sale Order and the wizard should return a form with a filtered one2many field. The form will then only show the pickings which have the Sale Order that the user selected as Origin. The TransientModel looks like this:
class SearchPacking(models.TransientModel):
_name = 'search.packing'
_description = 'Search a packing'
sale_order_id = fields.Many2one('sale.order',string="Sale Order")
def search_filtered_packing(self):
return {
'type':'ir.actions.act_window',
'view_type':'form',
'view_mode':'form',
'src_model':'search.packing',
'res_model':'pickpack.packview',
'target':'new',
'res_id':self.env.context.get('active_id'),
'domain':[('origin','=',self.sale_order_id)]
}
The model pickpack.packview is a model that shows all the pickings with picking type "Pack" in a batch. It has a one2many field that looks like this:
class PackView(models.Model):
// OTHER DEFINITIONS
pickings = fields.One2many('stock.picking','packviews',string='Operations to pack',readonly=False,store=True, compute='_compute_operations_to_pack')
@api.one
@api.depends('batch_id')
def _compute_operations_to_pack(self):
self.ensure_one()
res = self.env['stock.picking']
for picking in res.search([('batch_id','=',self.batch_id.id),('picking_type_id.name','=','Pack')]):
res += picking
self.pickings = res
What happens now if I click the button in the wizard that calls search_filtered_packing (after selecting a Sales Order) is that I just get the same model back, without any filters.
The One2Many field is searchable on Sales Order in the tree view. Can anyone see what is going wrong here?
Thanks in advance.