This question has been flagged
2 Replies
7599 Views

Hello Odoo community!

I want to replace that 4 with attribute record.control_id but when i do that record.control_id outputs pp.control(4,) which is correct but how to retrieve raw data only 4? without pp.control?

Code example below:
 
def end_date(self, cr, uid, ids, values, arg, context):
            y = self.pool.get('pp.control')
            x={}

            for record in self.browse(cr, uid, ids):
                other_table2 = y.search(cr, uid,[('id','=',record.control_

id)])
                #other_table2 = y.search(cr, uid,[('id','=','4')])
                res2 = y.browse(cr, uid, other_table2[0])                          
                x[record.id] = (datetime.strptime(res2.start_date, '%Y-%m-%d') + relativedelta(months=record.platform_duration)).strftime('%Y-%m-%d')             
            return x

  _columns = {
    'name': fields.many2one('xref.option', 'Platform', required=True, domain="[('type','=','Platform')]"),
    'platform_start': fields.integer('Platform Start', help='Month during which platform will first be required'),
    'platform_duration': fields.integer('Duration', help='Number of months that that the platform is required)'),
    'control_id': fields.many2one('pp.control', 'Plan'),
    #'end_date': fields.char(compute='_end_date', string='End Date', help='Calculated as start date plus duration in months'),
    'end_date' : fields.function(end_date, method=True, string='End Date', type="char")

 

Thank you,

Avatar
Discard
Best Answer

Hi, what you need is the id of the many2one field.
other_table2 = y.search(cr, uid,[('id','=',record.control_ id.id)]) will give you #other_table2 = y.search(cr, uid,[('id','=','4')])

Avatar
Discard
Author Best Answer

Thanks!

Avatar
Discard