Odoo Help

0

concatenate date and time in odoo 9.0

By
supreeth
on 5/18/16, 2:53 AM 770 views

I have two fields as shown below.

>  appo_date = fields.Date(string="Appointment Date")

>  appo_time = fields.Float(string="Appointment Time")

I need to concatenate this two fields. For that i wrote a function as shown below.

def _combine(self, cr, uid, ids, field_name, args, context=None):
        values = {}
        for id in ids:
            rec = self.browse(cr, uid, [id], context=context)[0]
            values[id] = {}
            values[id] = '%f - %f' % (rec.appo_date, rec.appo_time)
        return values

And called that function in a separate field as shown below.

appo_date_and_time = fields.Char(compute='_combine', string='Appointment Date/Time', arg=('appo_date','appo_time'), method=True)

These fields are called in xml files

<field name="appo_date"/>
<field name="appo_time"/>
<field name="appo_date_and_time"/>

I am getting an error as

TypeError: _combine() takes at least 6 arguments (5 given)



2

Hi,

First of all in V9 you have to write code in new API. Your code might be as like below.

@api.multi
def _combine(self):
    for obj in self:
        obj.appo_date_and_time = '%f - %f' % (obj.appo_date, obj.appo_time)

Thats it.

This function will assign value in "appo_date_and_time" field from "appo_date" and "appo_time" fields from that same record.

I hope it is very helpful for you.


Thank you it is working

supreeth
on 5/18/16, 6:15 AM

Your welcome

Emipro Technologies Pvt. Ltd.
on 5/18/16, 6:23 AM
1
Prakash Sharma
On 5/18/16, 5:39 AM

use odoo9 syntax 

 

    @api.one
def _combine(self):
pass

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 5/18/16, 2:53 AM
Seen: 770 times
Last updated: 5/18/16, 6:16 AM