İç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

List employee in form with a button

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
many2onewritebuttonrecords
2 Cevaplar
7261 Görünümler
Avatar
Algode

When press the button need list all employee and some data of this.

I create an module class prepare_adv() and other adv(), the second are as One2many fields in the first. 

in prepare_adv have a button that onclick need list in adv() all of employees and some datas of this. 

This is the function of button that need save the recors in adv() and them view in prepare_adv():

def onclick(self, cr, uid, ids, context=None):
        employee_obj = self.pool.get('hr.employee')
        contract_obj = self.pool.get('hr.contract')
        res = {}
        for advances in self.browse(cr,uid,ids,context=context):
            res[advances.id] = {
                'id_intern': 0,
                'employee_name': 0,
                'wage_base': 0,
            }
            for empl in employee_obj.browse(cr,uid,ids,context=context):
                res[advances.id]['wage_base'] = contract_obj.browse(cr,uid,empl.id).wage
                res[advances.id]['id_intern'] = empl.id_inter
                res[advances.id]['employee_name'] = empl.id 
                lines = [(0,0,res)]
                self.write(cr, uid, [advances.id], {'advancs': lines,}, context=context)
        return True

This no save nothing of records. What i do wrong ?

1
Avatar
Vazgeç
Algode
Üretici

Some can help me please...

Avatar
Cyril Gaspard (GEM)
En İyi Yanıt

Hi,

I believe you do not understand what is a on2many field :

if you display in view prepare_adv the field you defined in on2many field in adv to do the relation between the 2 class, and select an adv in prepare_adv and save your change, the line prepare_adv in one2many view in adv will be displayed automatically (by refreshing the view if you work on 2 notebooks).

I don't know if this is the result you want, but one prepare_adv can be display only in one adv with a one2many field.

If you want to display the list of all employee in adv one2many line corresponding to the prepare_adv id, you must create a field many2many with employee class relation in prepare_adv named employee_ids, and add it the one2many form view in adv by using widget one2many_list.

Your button in prepare adv will be used to update the field employee_ids list.

UPDATE :

button code :

class prepare_adv(models.Model):
    _name = 'prepare.adv'

 @api.one
    def on_click(self):
        self.ensure_one()
        per = time.strftime('%m/%Y')

        cr = self.env.cr
        cr.execute('''SELECT hr_employee.id, id_inter, wage FROM hr_employee, hr_contract WHERE hr_employee.id=employee_id''')
        temp = cr.fetchall()
        adv_to_create = []

        prepare_adv_id = self._ids[0]
        for record in temp:
            adv_to_create += [(0, 0, {'advances_id': prepare_adv_id,' period_id': per, 'id_intern': record[1],
                                                    'employee_name': record[0], 'wage_base': record[2]
                                           })]
        prepare_adv.advancs = adv_to_create
        return True

function field :

    @api.multi

    @api.depends('wage_base')

    def _compute_wage_advance(self):

        for record in self:

            record.advances_40 = record.wage_base * 0.40

1
Avatar
Vazgeç
Avatar
Algode
Üretici En İyi Yanıt

Hi Cyril Gaspard,

Thanks to you for answer. 

Now, I have this:

prepare_adv()
 _______________________________________________________________________
|      Ref:  ______________                             Period: _________ - ___________       |
|      _button_here                                                                                                   |
|............................................................................................................................|
|      ________________________________________________________________      |
|      |    id     |     employee      |   wage_of_contract   |   compute_40%_of_wage   | <---|----  this is my adv()
|      |-----------|-------------------------|--------------------------------|----------------------------------------|       |


adv.id and adv.employee have in hr_employee, and adv.wage_of_contract have in hr_contract, now, adv.compute_40%_of_wage is automatic compute from adv.wage_of_contract.
I need create this every month but one time, with all employee available. I solved the problem to save datas in adv() and can see this in prepare_adv() but have other problem :)
The problem is the next: when is only one row fine, save and can see perfect; but if it is more than one row show the next error: 

Expected singleton: hr.py.advances(104, 105, 103)

Save the data in adv() but show the error mentioned.
I have understood that need create new rows for news records. 


This is my code of function from button (this are in prepare_adv()): 

def on_click(self, cr, uid, ids, context=None):
        res = {}
        for adv in self.browse(cr,uid,ids):
            cr.execute('''SELECT hr_employee.id, id_inter, wage FROM hr_employee, hr_contract WHERE hr_employee.id=employee_id''')
            temp = cr.fetchall()
            per = time.strftime('%m/%Y')
            for record in temp:
                datas = {'advances_id':adv.id,'period_id':per,'id_intern':record[1],'employee_name':record[0],'wage_base':record[2]}
                crea = self.pool.get('hr.py.advances').create(cr,uid,datas,context=context)
                self.pool.get('hr.py.advances').write(cr,uid,crea,datas,context=context)
            return True

This is my adv() class:

class adv(models.Model):
    _name = 'adv'

    advances_id = fields.Many2one('prepare.adv')
    period_id = fields.Char()
    id_intern = fields.Integer(string='Cod.')
    employee_name = fields.Many2one('hr.employee', string='Funcionario')
    wage_base = fields.Float(string='Salario')
    advances_40 = fields.Integer(compute='_compute_wage_advance', string='40% Adelanto Quinc.')

    @api.depends('wage_base')
    def _compute_wage_advance(self):
        self.advances_40 = self.wage_base * 0.40

This id my prepare_adv() class:

class prepare_adv(models.Model):
    _name = 'prepare.adv'

    state = fields.Selection([('draft','Borrador'),('done','Aprobado')], default='draft', string='Status', select=True, readonly=True, copy=False)
    referenc = fields.Char(string='Referencia',default='Anticipo - ' + time.strftime('%m/%Y'))    
    date_from = fields.Datetime(string='Periodo', default=lambda *a: time.strftime('%Y-%m-01'), required=True, readonly=True, states={'draft': [('readonly', False)]})
    date_to = fields.Datetime(string='-', default=lambda *a: str(datetime.now() + relativedelta.relativedelta(months=+1, day=1, days=-1))[:10], required=True, readonly=True, states={'draft': [('readonly', False)]})
    per_id = fields.Char(string='per', default= time.strftime('%m/%Y'))
    advancs = fields.One2many('adv','advances_id')

This is the view of prepare_adv():

<div class="oe_title">
                            <label for="referenc" class="oe_edit_only"/>
                            <h1>
                                <field name="referenc"/>
                            </h1>
                        </div>
                        <div class="oe_right">
                            <label for="date_from" class="oe_edit_only"/><field name="date_from" class="oe_inline"/><label for="date_to">-</label><field name="date_to" class="oe_inline"/>
                        </div>
                        <group>
                            <button string="Cargar" name="charge_employee" states="draft" type="object" class="oe_highlight"/>
                        </group>
                        <notebook>
                            <page>
                                <field name="advancs" nolabel="1"/>
                            </page>
                        </notebook>

How create news row for view all amount of employee (around of 72 employee)? 
 

 

1
Avatar
Vazgeç
Cyril Gaspard (GEM)

why did you do a create and after a write with same datas on same model? just need to create => self.pool.get('hr.py.advances').create(cr,uid,datas,context=context) self.pool.get('hr.py.advances').write(cr,uid,crea,datas,context=context) Else error you have is due to: in a write, you must give a list of ids, not just one id, replace in your write call crea by [crea] : self.pool.get('hr.py.advances').write(cr,uid,[crea],datas,context=context)

Algode
Üretici

I have understood that need create and them write this in the database, is wrong ? Try with self.pool.get('hr.py.advances').write(cr,uid,[crea],datas,context=context) but show the same error: Expected singleton: hr.py.advances(108, 109)

Cyril Gaspard (GEM)

in your field advances_id = fields.Many2one('prepare.adv') where is defined the class prepare.adv you are using in this field ????

Algode
Üretici

hr_py_prepare_advances is the prepare.adv, sorry

Algode
Üretici

Now is right.

Algode
Üretici

^^ now is right the previous code, because I modified. The problem not solved it yet :(

Algode
Üretici

Return this with your new code: cr.execute('''SELECT hr_employee.id, id_inter, wage FROM hr_employee, hr_contract WHERE hr_employee.id=employee_id''') NameError: global name 'cr' is not defined

Cyril Gaspard (GEM)

forget to define cr in v8 : cr = self.env.cr , I update the code. bye

Algode
Üretici

Thanks to you for your time to answer me... but the code not save any data in the adv() if change this code [[0, 0, {'advances_id': prepare_adv_id,' period_id': per, 'id_intern': record[1], 'employee_name': record[0], 'wage_base': record[2] }]] for [((0, 0, {'advances_id': prepare_adv_id,' period_id': per, 'id_intern': record[1], 'employee_name': record[0], 'wage_base': record[2] }))] save but show the same erro of Expected singleton: adv(150,151).

Cyril Gaspard (GEM)

your error id due to a function which can be have just one id in input, try to change @api.depends('wage_base') def _compute_wage_advance(self): self.advances_40 = self.wage_base * 0.40 by @api.multi @api.depends('wage_base') def _compute_wage_advance(self): for record in self: record.advances_40 = record.wage_base * 0.40 I update my code with this

Algode
Üretici

Sorry for many thanks but need say to you more one time, Thanks very much, for your time and for you help Problem solved.

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
Record create/write in Odoo8.0 new API Çözüldü
update write records odoo8.0
Avatar
Avatar
Avatar
8
Ara 16
19475
Hello, how could I create a button that creates a new record in another model containing data from my current model? from my python module
python module models button records
Avatar
Avatar
Avatar
2
Oca 25
2291
How to use Char field in other form view as Drop down ???
many2one records python2.7 openerp odoov10
Avatar
0
Tem 19
770
[v10] Pass active_id through button to fill fields Çözüldü
action many2one button autocomplete active_id
Avatar
Avatar
9
Haz 17
10418
relation between record of one2many and another field Çözüldü
v8 domain many2one one2many records
Avatar
Avatar
2
Nis 17
8397
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