Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

loan request

Subscribe

Get notified when there's activity on this post

This question has been flagged
odoo12.0
1 Reply
4014 Views
Avatar
jenan soliman

Hello

I am working  on loan limitation, the function must do the following:

if the employee requests a loan less than the limitation, a new limitation must be calculated by subtracting the loan amount.

if an employee requests another loan, the limitation must equal the new limitation - the sum of the loan amount.

here's my code:



limit = fields.Float('limitation',compute='_check_contract_limitation')
@api.onchange('loan_amount', 'employee_id','limit')
def _check_contract_limitation(self):
for rec in self:
#hr_contract = self.env['hr.contract'].search([('employee_id.name', '=', self.employee_id.name)], limit=1)
if not rec.employee_id.contract_id:
raise ValidationError("you dont have contract record.")
elif rec.employee_id.contract_id:
rec.limit = rec.employee_id.contract_id.wage
# rec.a = hr_contract.date_start
if rec.employee_id.contract_id.date_start:
fmt = '%Y-%m-%d'
d1 = rec.employee_id.contract_id.date_start
d2 = datetime.datetime.now().date()
r = relativedelta.relativedelta(d2, d1)
contract_time = r.years
rec.a = contract_time
if contract_time == None:
raise ValidationError("check contract duration.")
else:
if contract_time >= 5:

rec.limit = rec.employee_id.contract_id.wage * 5 - rec.loan_amount
if rec.loan_amount > rec.limit:
rec.loan_amount = False
raise
ValidationError("please correct loan amount is greater than limitaion.")
return

elif
contract_time >= 0 and contract_time < 5:
rec.limit = rec.employee_id.contract_id.wage * contract_time - rec.loan_amount
if rec.loan_amount > rec.limit:
rec.loan_amount = False
raise
ValidationError("please correct loan amount is greater than limitaion.")
return





0
Avatar
Discard
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,

You can try this code:

import datetime
from dateutil.relativedelta
import relativedelta

limit = fields.Float('Limitation', compute='_check_contract_limitation')

@api.onchange('loan_amount', 'employee_id')
def _check_contract_limitation(self):
for
rec in self:
   
if not rec.employee_id.contract_id:
        raise ValidationError(
"You don't have a contract record.")
   
   
contract = rec.employee_id.contract_id
   
if not contract.date_start:
        raise ValidationError(
"Contract start date is missing.")
   
   
contract_start_date = datetime.datetime.strptime(contract.date_start, '%Y-%m-%d').date()
   
today = datetime.datetime.now().date()
   
contract_duration = relativedelta(today, contract_start_date).years

   
if contract_duration is None:
        raise ValidationError(
"Check contract duration.")
   
   
if contract_duration >= 5:
       
rec.limit = contract.wage * 5 - rec.loan_amount
    elif
0 <= contract_duration < 5:
       
rec.limit = contract.wage * contract_duration - rec.loan_amount
   
   
if rec.loan_amount > rec.limit:
       
rec.loan_amount = False
        raise ValidationError(
"Please correct the loan amount; it is greater than the limitation.")


Hope it helps

0
Avatar
Discard
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
Related Posts Replies Views Activity
Expected singleton: hr.emp.travel.location(62, 63)
odoo12.0
Avatar
Avatar
Avatar
2
Oct 25
1981
How to write Record Rule with domain based on the company_dependent Fields Solved
odoo12.0
Avatar
Avatar
Avatar
3
Oct 23
10706
sum Colum of based on id
odoo12.0
Avatar
Avatar
1
May 23
2963
How to make pagination that has a table in qweb
odoo12.0
Avatar
Avatar
2
Apr 23
3727
Inherit Element form kanban View Solved
odoo12.0
Avatar
Avatar
1
Mar 23
2878
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now