İçereği Atla
Odoo Menü
  • Portal
  • Ücretsiz deneyin
  • Uygulamalar
    Finans
    • Muhasebe
    • Faturalama
    • Masraf Yönetimi
    • Elektronik Çizelge (BI)
    • Belgeler
    • İmza
    Satış
    • Müşteri İlişkileri Yönetimi (CRM)
    • Satış
    • Satış Noktası Mağaza
    • Satış Noktası Restoran
    • Abonelikler
    • Kiralama
    Web Sitesi
    • Web Sitesi Oluşturucu
    • eTicaret
    • Blog
    • Forum
    • Canlı Sohbet
    • eÖğrenme
    Tedarik Zinciri
    • Envanter
    • Üretim
    • Ürün Yaşam Döngüsü Yönetimi
    • Satın Alma
    • Bakım
    • Kalite
    İnsan Kaynakları
    • Çalışanlar
    • İşe Alım
    • İzin
    • Değerlendirme
    • Referans
    • Filo Yönetimi
    Pazarlama
    • Sosyal Medyada Pazarlama
    • E-posta ile Pazarlama
    • SMS ile Pazarlama
    • Etkinlikler
    • Pazarlama Otomasyonu
    • Anket
    Hizmetler
    • Proje Yönetimi
    • Çalışma Çizelgeleri
    • Saha Hizmeti
    • Yardım Masası
    • Planlama
    • Randevular
    Verimlilik
    • Sohbet
    • Onay
    • Nesnelerin İnterneti
    • VoIP
    • Bilgi Bankası
    • WhatsApp
    Üçüncü taraf uygulamalar Odoo Stüdyo Odoo Bulut Platformu
  • Sektörler
    Perakende satış
    • Kitapçı
    • Giyim Mağazası
    • Mobilya Mağazası
    • Gıda Marketi
    • Hırdavat Dükkanı
    • Oyuncak Dükkanı
    Gıda ve Konaklama
    • Bar ve Pub
    • Restoran
    • Fast Food Restoranı
    • Konuk Evi
    • İçecek Distribütörü
    • Otel
    Gayrimenkul
    • Emlak Acentesi
    • Mimarlık Firması
    • İnşaat
    • Emlak Yönetimi
    • Bahçe Tasarımı
    • Mülk Sahipleri Derneği
    Uzmanlık
    • Muhasebe Firması
    • Odoo Partner
    • Pazarlama Ajansı
    • Hukuk Firması
    • Yetenek Kazanımı
    • Denetim ve Belgelendirme
    Üretim
    • Tekstil
    • Metal
    • Mobilyalar
    • Gıda
    • Bira fabrikası
    • Kurumsal Hediye
    Sağlık ve Spor
    • Spor Kulübü
    • Optik Mağazası
    • Fitness Merkezi
    • Sağlıklı Yaşam Merkezi
    • Eczane
    • Kuaför Salonu
    Ticaret
    • Tamirci
    • BT Donanım & Destek
    • Güneş Enerjisi Sistemleri
    • Ayakkabı İmalatçısı
    • Temizlik Hizmetleri
    • HVAC Hizmetleri
    Diğerleri
    • Kar Amacı Gütmeyen Kuruluş
    • Çevre Ajansı
    • Reklam Panosu Kiralama
    • Fotoğrafçılık
    • Bisiklet Kiralama
    • Yazılım Bayisi
    Tüm Sektörlere Göz Atın
  • Topluluk
    Öğrenim
    • Eğitim Araçları
    • Dokümantasyon
    • Sertifikasyonlar
    • Eğitim Etkinlikleri
    • Blog
    • Podcast
    Eğitim ve Gelişim
    • Eğitim Programı
    • Scale Up! İşletme Oyunu
    • Odoo'yu Ziyaret Edin
    Yazılım
    • İndirin
    • Sürümleri Kıyaslayın
    • Sürümler
    İş Birliği
    • Github
    • Forum
    • Etkinlikler
    • Çeviriler
    • Partner Olun
    • Partnerler için Hizmetler
    • Muhasebe Firmanızı Kaydettirin
    Hizmetler
    • Partner Bulun
    • Muhasebeci Bulun
    • Bir danışmanla görüşün
    • Kurulum Hizmetleri
    • Müşteri Referansları
    • Destek
    • Sürüm Yükseltme
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Demo randevusu alın
  • Fiyatlandırma
  • Yardım

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

  • Müşteri İlişkileri Yönetimi
  • e-Commerce
  • Muhasebe
  • Envanter
  • PoS
  • Proje Yönetimi
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
Yardım

add compute field to calculate employee loan amount

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
computev17
1 Cevapla
2311 Görünümler
Avatar
SmithJohn45

i have wrote 3 views which are used in below compute code, queries i tested on pgAdmin but i don't know why it is throwing error.

please help to resolve the issue, i am badly stuck here.

for rec in self:
    # clean_id = self._origin.id
    clean_id = 448 # BECAUSE above line throws error...
    req_date = rec.request_date
    query = """SELECT id, name, tenure_days, tenure_months, tenure_years FROM employee_tenure WHERE id = %s"""
    self.env.cr.execute(query, (clean_id,))
    result = self.env.cr.dictfetchall()
    #
    for row in result:
        if row.get('tenure_months') > 12:
            # get payslip line amount for rule_id 107
            query2 = """SELECT pl_amount FROM emp_pf_amount WHERE employee_id = %s"""
            self.env.cr.execute(query2, (clean_id,))
            result2 = self.env.cr.dictfetchall()
            x_amount = 0
            for pl_row in result2:
                x_amount = pl_row.get('pl_amount')
                rec['x_loan_applicable_amount'] = x_amount
            dt_string = req_date.strftime("%Y-%m-%d")
            dt1 = datetime.datetime.strptime(dt_string, "%Y-%m-%d")
            dt_month = dt1.month
            dt_month1 = '07'
            dt_date1 = '01'
            dt_month2 = '06'
            dt_date2 = '30'
            if dt_month in (7,8,9,10,11,12):
                dt_year1 = dt1.year
                dt_year2 = dt1.year + 1
            else:
                dt_year1 = dt1.year - 1
                dt_year2 = dt1.year

            dt_range = 'to_date(\''+dt_year1+'-'+dt_month1+'-'+dt_date1+'\','+'\'YYYY-MM-DD\''+') AND '+'to_date(\''+dt_year2+'-'+dt_month2+'-'+dt_date2+'\','+'\'YYYY-MM-DD\''+')'

            query3 = """SELECT emp_allocation_amount FROM emp_ann_leave_amount WHERE employee_id = %s AND date_from between %s"""
            self.env.cr.execute(query3, (clean_id, (dt_range,)))
            result3 = self.env.cr.dictfetchall()
            for pi_row in result3:
                x_amount += pi_row.get('pi_amount')
                rec['x_loan_applicable_amount'] = x_amount
        else:
            rec['x_loan_applicable_amount'] = 1


tested this here...


regards

0
Avatar
Vazgeç
SmithJohn45
Üretici

i tested dt_range for syntax and it is showing as below:

to_date('2023-07-01','YYYY-MM-DD') AND to_date('2024-06-30','YYYY-MM-DD')

may be i am overlooking or something else, seniors experts please help to have working code.

regards

Avatar
SmithJohn45
Üretici En İyi Yanıt

i have managed, the code below is working fine. this is for juniors like me. just one thing i have work on which is clean_id , i have passed hard coded value because it is throwing error on the lines i have remarked.

for rec in self:

    # clean_id = rec.id

    # clean_id = self.id

    # clean_id = self._origin.id

    clean_id = 448

    req_date = rec.request_date

    query = """SELECT id, name, tenure_days, tenure_months, tenure_years FROM employee_tenure WHERE id = %s"""

    self.env.cr.execute(query, (clean_id,))

    result = self.env.cr.dictfetchall()

    # 

    for row in result:

        if row.get('tenure_months') > 12:

            # get payslip line amount for rule_id 107

            query2 = """SELECT pl_amount FROM emp_pf_amount WHERE employee_id = %s"""

            self.env.cr.execute(query2, (clean_id,))

            result2 = self.env.cr.dictfetchall()

            x_amount = 0

            for pl_row in result2:

                x_amount = pl_row.get('pl_amount')

                rec['x_loan_applicable_amount'] = x_amount

#

# get payslip input amount for rule_id 16

            # to create date_from and date_to from request_date year

            dt_string = req_date.strftime("%Y-%m-%d")

            dt1 = datetime.datetime.strptime(dt_string, "%Y-%m-%d")

            dt_month = dt1.month

            dt_month1 = '07'

            dt_date1 = '01'

            dt_month2 = '06'

            dt_date2 = '30'

            if dt_month in (7,8,9,10,11,12):

                dt_year1 = dt1.year

                dt_year2 = dt1.year + 1

            else:

                dt_year1 = dt1.year - 1

                dt_year2 = dt1.year

            dt_year1 = str(dt_year1)

            dt_year2 = str(dt_year2)

            # dt_range = 'to_date(\''+dt_year1+'-'+dt_month1+'-'+dt_date1+'\','+'\'YYYY-MM-DD\''+') AND '+'to_date(\''+dt_year2+'-'+dt_month2+'-'+dt_date2+'\','+'\'YYYY-MM-DD\''+')'

            dt_from = '\''+dt_year1+'-'+dt_month1+'-'+dt_date1+'\''

            dt_to = '\''+dt_year2+'-'+dt_month2+'-'+dt_date2+'\''

# query3 = """SELECT emp_allocation_amount FROM emp_ann_leave_amount WHERE employee_id = %s AND date_from between %s"""

            query3 = """SELECT emp_allocation_amount FROM emp_ann_leave_amount WHERE employee_id = %s AND date_from BETWEEN %s AND %s"""

            self.env.cr.execute(query3, (clean_id, dt_from, dt_to))

            result3 = self.env.cr.dictfetchall()

            for pi_row in result3:

                x_amount += pi_row.get('emp_allocation_amount')

                rec['x_loan_applicable_amount'] = x_amount

        else:

            rec['x_loan_applicable_amount'] = 1

happy coding.

regards

0
Avatar
Vazgeç
SmithJohn45
Üretici

also the problem is resolved for clean_id which mentioned in my Answer above.

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Üye Ol
İlgili Gönderiler Cevaplar Görünümler Aktivite
Ya es posible hacer Upgrade de v17 a v17.1 ?
v17
Avatar
Avatar
1
Eki 25
1314
How to add a new Many2one field in res.config.settings? Çözüldü
v17
Avatar
Avatar
Avatar
Avatar
4
Eki 25
3706
Add field to ALL models in Odoo
v17
Avatar
Avatar
Avatar
2
Eyl 25
2384
How to disable Email notification - You have been assigned to Çözüldü
v17
Avatar
Avatar
Avatar
Avatar
4
Eyl 25
7776
Selection Field Options Disappear from Database (PostgreSQL enum) on Module Upgrade
v17
Avatar
0
Ağu 25
1264
Topluluk
  • Eğitim Araçları
  • Dokümantasyon
  • Forum
Açık Kaynak
  • İndirin
  • Github
  • Runbot
  • Çeviriler
Hizmetler
  • Odoo.sh Hosting
  • Destek
  • Sürüm Yükseltme
  • Özel Geliştirmeler
  • Eğitim
  • Muhasebeci Bulun
  • Partner Bulun
  • Partner Olun
Hakkında
  • Şirketimiz
  • Pazarlama Gereçleri
  • İletişim
  • Kariyer
  • Etkinlikler
  • Podcast
  • Blog
  • Müşteriler
  • Hukuki • Gizlilik
  • Güvenlik
الْعَرَبيّة 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, müşteri ilişkileri yönetimi, eTicaret, muhasebe, envanter, satış noktası, proje yönetimi gibi şirketinizin tüm ihtiyaçlarını karşılayan bir açık kaynak işletme uygulamaları paketidir.

Odoo’nun eşsiz değer önermesi, aynı anda hem kullanımının çok kolay olup hem de tamamen entegre olmasıdır.

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