Odoo Help


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.


Sample code of computation

on 2/8/15, 7:56 PM 372 views

alright, because what i want is to subtract the dateofinspection in yeareffect. so any suggestion what im going to use or much better code to do that.???

class appraisal-report (osv.Model):

                _name = 'appraisal.report'

               _description = 'Appraisal Report'

              _columns = {

                        'dateofinspection': fields.date ('Date of Inspection'),

                       'yeareffect': fields.integer ('Year Effect' size=64, required=True)



Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
| 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/9/15, 12:23 AM

from openerp.osv import orm, fields
from dateutil.relativedelta import relativedelta
from datetime import datetime
from openerp import tools

class appraisal-report (orm.Model):
     _name = 'appraisal.report'
     _description = 'Appraisal Report'

    def difference_year(self, cr, uid, ids, name, args, context=None):
        res = {}
        for record in  self.browse(cr, uid, ids, context=context):
            yeareffect = datetime.strptime(record.yeareffect, '%Y') # Your year field
            dateofinspection = datetime.strptime(record.dateofinspection, tools.DEFAULT_SERVER_DATE_FORMAT) # Your date field
            difference = relativedelta(yeareffect, dateofinspection).years # (01-01-2020, 10-02-2015)
            res[record.id] = str(difference)
        return res
    _columns = {
        'dateofinspection': fields.date ('Date of Inspection'),
        'yeareffect': fields.char('Year Effect', size=64, required=True),
        'difference': fields.function(difference_year, string="Difference", type='char')

On 2/10/15, 4:41 AM

hi, i try your code and it works on me.. tnx

Always try to accept the answer by clicking the tick mark if it works for you, so that in future people can use it.

Dhinesh - Technical Consultant, Sodexis Inc
on 2/10/15, 5:01 AM

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)


Asked: 2/8/15, 7:56 PM
Seen: 372 times
Last updated: 3/28/15, 3:13 AM