Search code examples
pythonpostgresqlodooopenerp-7

Openerp 7- how to run datetime update query


I am having problem with this update query and I don't understand the error here. please help me to solve this.

Field

'sign_in' : fields.datetime("Sign In"),

Variable

sgn_in1 = datetime.datetime.strptime(sign_in, DATETIME_FORMAT1).time()

Query

cr.execute("""UPDATE allowance.attendances SET sign_in = %s WHERE id =%s"""%(sign_in1,colmn_id))

Error

ProgrammingError: syntax error at or near ":" LINE 1: UPDATE allowance.attendances SET sign_in = 08:15:00


Solution

  • Query should be like this,

    cr.execute("UPDATE allowance_attendances SET sign_in = '%s' WHERE id =%s"%(sign_in1,colmn_id))
    

    Datetime / time / date value must be passed in single quote. For integer / long it's not required.

    While you execute direct query in database then the odoo model doesn't contains . (dot) in name, it's only allowed to use while you perform operation via odoo ORM methods.

    so Model shouldn't be allowance.attendances, it should be allowance_attendances