Odoo Help

0

Sample code of computation

By
louie
on 2/8/15, 7:56 PM 487 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)

                             }

2

Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
3712
| 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')
         }

1
louie
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

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: 2/8/15, 7:56 PM
Seen: 487 times
Last updated: 3/28/15, 3:13 AM