Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

Search function getting right value in many2one field?

By
DM
on 2/25/15, 12:32 PM 1,244 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,

3

Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
3577
| 5 4 9
Pondicherry, India
--Dhinesh - Technical Consultant, Sodexis Inc--

Passionate coder in Python/OpenERP. Knows Django/Flask MVC frameworks. Did code in Java, PHP.

Contact me at: dvdhinesh.mail@gmail.com

Dhinesh - Technical Consultant, Sodexis Inc
On 2/25/15, 1:09 PM

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')])

-1
DM
On 2/26/15, 12:12 PM

Thanks!

Your Answer

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

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/25/15, 12:32 PM
Seen: 1244 times
Last updated: 10/23/15, 9:18 AM