Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
9043 Näkymät

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
Hylkää
Paras vastaus

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
Hylkää
Tekijä Paras vastaus

Thanks!

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
maalisk. 15
8399
1
maalisk. 22
3023
1
jouluk. 23
20905
6
maalisk. 24
37252
3
toukok. 16
10113