Odoo Help


Expense Management based on Country and Datetime

Peter Mayer
on 2/5/16, 7:52 AM 780 views

Hi guys,I'm relatively new to Odoo (2 months) and currently programming a custom module which inherits "hr.expense.line" in order to show the country and the start and end of the journey on the expense lines. Based on these informations i want to calculate the amount of expenses. I need a proper method to override the "_amount" method in "hr.expense.lines". This method should calculate the difference between the 2 datetime fields and regard the different countries.  I'd also like to get the allowable expenses dynamically from a website. How is this possible in odoo(e.g. screen scraper or foreign db)? I'm thankful for any kind of help, below is my start code.

# -*- coding: utf-8 -*-
from openerp import models, fields,api
from datetime import datetime, timedelta
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
import openerp.addons.decimal_precision as dp
class spesen_model(models.Model):
_inherit = 'hr.expense.line'
x_country = fields.Selection( [('d','Deutschland'), ('s','Schweiz'),('au','Österreich')],
x_time_begin = fields.Datetime('Anfangsdatum')
x_time_end = fields.Datetime('Enddatum')
@api.depends('x_country', 'x_time_begin', 'x_time_end')
def _amount(self):
for expense in self:
var = 0.0
if expense.x_country == 'd':
var += 100.0
elif expense.x_country == 's':
var += 170.0
elif expense.x_country == 'au':
var += 230.0
expense.total_amount = var

total_amount = fields.Float(compute='_amount', string='Total', digits_compute=dp.get_precision('Account'))


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.


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)


Asked: 2/5/16, 7:52 AM
Seen: 780 times
Last updated: 2/11/16, 9:43 AM