from openerp import models, fields, api
from datetime import datetime
from dateutil.relativedelta import relativedelta
from openerp import _
class my_financial_grant(models.Model):
_name = "financial.grant"
_description = "financial grants"
_rec_name="grant_code"
grant_code = fields.Integer(string='Code')
school_term = fields.Selection([('1','1'),('2','2'),('3','3'),('4','4')],"Quarter", required="true")
day_of_grant = fields.Date(string='Financial Grant Date',required="true")
academic_year = fields.Char(string='Academic Year')#,compute='set_Academic_Year')
registration_id = fields.Many2one("registration.registration","Registration", required="true" ,ondelete="cascade")
employee_id = fields.Char(string='Employee Name')
required_hours= fields.Float(string='Required Hours', default='1',required="true")
completed_hours= fields.Float(string='Completed Hours',required="true")
presence_avarage = fields.Float(string="Presence Average", compute='presence_avarage_count', store=True)
percentage_presence_avarage = fields.Float(string="Presence Percentage %", compute='presence_avarage_count', store=True)
#employee
his_job = fields.Char(string='Current Job',compute='set_Employee')
grade = fields.Char(string='Current Grade',compute='set_Employee')
diplom_id = fields.Char(string='Current Diploma',compute='set_Employee')
year_employment = fields.Date(string='Employment Year',compute='set_Employee')
seniority = fields.Integer(string='Seniority',compute='set_Employee')
years_off = fields.Integer(string='Current SWY',compute='set_Employee')
seniority_pay = fields.Integer(string='Seniority Pay Years',compute='set_Employee')
g_spy = fields.Integer(string='Grant SPY')#copy seniority_pay
sem_owe_him = fields.Integer(string='Current Indebtedness',compute='set_Employee')
g_indebtedness = fields.Integer(string='Grant Indebtedness')#copy sem_owe_him
#financial grants linked with g_job
category = fields.Char(string='Category',compute='set_Employee')
classe = fields.Char(string='Class',compute='set_Employee')
category_class_basic_grant = fields.Integer(string='Basic Grant',compute='set_Employee')
seniority_classamount_amount = fields.Integer(string='Seniority Amount',compute='set_Employee')
performance_bonus = fields.Integer(string='Performance Bonus',compute='set_Employee')
g_bg = fields.Integer(string='Grant Basic Grant') # copy category_class_basic_grant
g_scm = fields.Integer(string='Seniority Amount') # copy seniority_classamount_amount
g_pb = fields.Integer(string='Grant Performance Bonus') # copy performance_bonus
#grade linked with grade
grade_premium = fields.Integer(string='Grade Premium',compute='set_Employee')
g_gp = fields.Integer(string='Grant Grade Premium')# copy grade_premium
#diplom linked with diplom
diplom_premium = fields.Integer(string='Diplom Premium',compute='set_Employee')
g_dp = fields.Integer(string='Grant Diploma Premium')# copy diplom_premium
@api.onchange('registration_id')
@api.depends('registration_id')
def set_Academic_Year(self):
if self.registration_id:
self.academic_year = self.registration_id.academic_year
@api.onchange('registration_id')
@api.depends('registration_id','employee_id')
def set_Employee(self):
if self.registration_id:
#employee
self.employee_id =self.registration_id.employee_id.emp_name
self.sem_owe_him = self.registration_id.employee_id.we_owe_him
self.year_employment = self.registration_id.employee_id.year_employment
self.years_off = self.registration_id.employee_id.years_off
self.seniority = self.registration_id.employee_id.seniority
self.seniority_pay = self.registration_id.employee_id.seniority_pay
#ladder
self.his_job = self.registration_id.employee_id.ladder_id.ladder_name
self.category = self.registration_id.employee_id.ladder_id.category
self.classe = self.registration_id.employee_id.ladder_id.classe
self.category_class_basic_grant = self.registration_id.employee_id.ladder_id.category_class_basic_grant
self.seniority_classamount_amount = self.registration_id.employee_id.ladder_id.seniority_classamount_amount
self.performance_bonus = self.registration_id.employee_id.ladder_id.performance_bonus
#grade
self.grade = self.registration_id.employee_id.grade.n_grade
self.grade_premium = self.registration_id.employee_id.grade.grade_premium
#diplom
self.diplom_id = self.registration_id.employee_id.diplom_id.n_diplom
self.diplom_premium = self.registration_id.employee_id.diplom_id.diplom_premium
#seniority_grant = fields.Integer(string="Seniority Grant")#, compute='presence_avarage_count', store=True)
#initial_grant = fields.Integer(string="Initial Grant")#, compute='presence_avarage_count', store=True)
#presence_grant = fields.Integer(string="Presence Grant")#, compute='presence_avarage_count', store=True)
#final_grant = fields.Integer(string="Final Grant", store=True)
a = fields.Integer(string="a", store=True)
b = fields.Integer(string="b", store=True)
c = fields.Integer(string="c", store=True)
d = c = fields.Integer(string="d", store=True)
g_final = fields.Integer(string="My Grant", store=True)
#do not make multiple records in self if
@api.one
@api.depends('required_hours','completed_hours')#,'seniority_classamount_amount','seniority_pay','category_class_basic_grant','diplom_premium','performance_bonus','grade_premium','sem_owe_him')
def presence_avarage_count(self):
for r in self:
if r.required_hours > r.completed_hours :
r.presence_avarage = (float)(r.completed_hours / r.required_hours)
r.percentage_presence_avarage = r.presence_avarage * 100
else:
r.presence_avarage = -2
#@api.one
#@api.depends('presence_avarage','g_spy','g_indebtedness','g_bg','g_scm','g_pb','g_gp','g_dp')
# for t in self:
# if t.presence_avarage > 0:
# # t.g_final = (((t.g_spy * t.g_scm) + (2 * t.g_pb) + t.g_bg + t.g_gp + t.g_dp) * 3 * t.presence_avarage) + t.g_indebtedness
# t.a = t.g_spy * t.g_scm
# t.b = t.g_pb * 2
# t.c = t.a + t.g_bg + t.g_gp + t.g_dp + t.b
# t.d = 3 * t.c * t.presence_avarage
# t.g_final = t.d + t.g_indebtedness
# else:
# t.g_final = -3
#_sql_constraints = [ ('grant_unique', 'unique (school_term,registration_id)', 'Do not repeat the same Grant ')]
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
4
Replies
1304
Views
no that not the c
for one registration we have at most 4 financial grants
onr financial grant is unique for one registration
you see
_sql_constraints = [ ('grant_unique', 'unique (school_term,registration_id)', 'Do not repeat the same Grant ')]
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up
The problem is that your field 'registration_id' can contain multiple values while your code uses self. You'll need to rewrite that.
I did'nt get you that much
my 'registration_idis unique
class my_registration(models.Model):
_name = "registration.registration"
_description = "registrations"
_rec_name="rsnumber"
rsnumber = fields.Char(string ='Serie Number', required="true")
_sql_constraints = [ ('rsnumber_unique', 'unique (rsnumber)', 'The Serie Number Exist')]
Unique yes but you can attach multiple registrations to onefinancial grant, right? If that is the case then you cannot use self but need to loop over records as you'll get a singleton issue.