Skip to Content
Menu
This question has been flagged
1 Reply
2509 Views

Hi all,

I try to add a functional field in stock.pack.operation,

Here it is my code, which is i tried,


from openerp import fields, models, api

class stock_inherited(models.Model):

    _inherit = 'stock.pack.operation',


    @api.depends('picking_id.partner_id')

    def _compute_child_contact_ids(self):

         partner_id = int(record.picking_id.partner_id)

         is_company = record.picking_id.partner_id.is_company

         parent_id = record.picking_id.partner_id.parent_id

         record.filters = is_company +','+parent_id+','+partner_id

         return self.filters

    

     partner_id = fields.Many2one(string="Partner ID", related='picking_id.partner_id', store=True)

     filters = fields.Char(compute="_compute_child_contact_ids", string="Filters", store=True)


here partner_id gets exact partner ids, but the filters field is empty.

thanks in advance...!

Avatar
Discard
Best Answer

Hi,

Because you need either give @api.one or use a for loop to iterate in the recordset. Try like this:

from openerp import models, fields, api

class stock_inherited(models.Model):

_inherit = 'stock.pack.operation'

@api.depends('picking_id.partner_id')
def _compute_child_contact_ids(self):
for record in self:
partner_id = record.picking_id.partner_id.id
is_company = record.picking_id.partner_id.is_company
parent_id = record.picking_id.partner_id.parent_id
record.filters = is_company +','+parent_id+','+partner_id




partner_id = fields.Many2one(string="Partner ID", related='picking_id.partner_id')
filters = fields.Char(compute="_compute_child_contact_ids", string="Filters")

I don't understand the way you need partner_id and parent_id, you need exactly the name or record id? Please tell what you exactly need in filters.


Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
16338
2
Mar 24
474
1
Oct 23
2243
1
Nov 22
380
0
Aug 22
10069