Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Save records in database

Odebírat

Get notified when there's activity on this post

This question has been flagged
databasedatarecordssave
2 Odpovědi
12712 Zobrazení
Avatar
Algode

I have a function that process some data and the result od this need save in a database.
All process of data work fine, but the problem is when i want save the data in a database, not have any error in process.

When i use "ids" in create(), as self.pool.get('hr.attendance').create(cr,uid,ids,datas)  this give me an error(see below)

What I do wrong?

This is my function: 

    def import_time(self, cr, uid, ids, context=None):
        def see_time(x1, x2, x3, z1):
            x21 = str(timedelta(hours=x2))
            x31 = str(timedelta(hours=x3))
            res1 = (datetime.strptime(x1, '%H:%M:%S') - timedelta(hours=3)) - datetime.strptime(x21, '%H:%M:%S')
            res2 = (datetime.strptime(x1, '%H:%M:%S') - timedelta(hours=3)) - datetime.strptime(x31, '%H:%M:%S')
            zz = 'action'
            if (z1%2)==0: 
                    zz = 'sign_in'
            else:
                zz = 'sign_out'
            return zz

        for lines in self.browse(cr, uid, ids):
            attendance_obj = self.pool.get('hr.attendance')
            mess = []
            cr.execute('SELECT user_time, hr_employee.id '\
                'FROM hr_py_import_time, hr_employee '\
                'WHERE user_id=id_inter')
            temp = cr.fetchall()
            cr.execute('SELECT date_start, date_end '\
                'FROM hr_employee, hr_py_turno '\
                'WHERE hr_py_turno.id=id_turn')
            turn = cr.fetchall()
            contar = -1
            for x in temp:
                te = x[0]
                us = x[1]
                te1 = te.split(' ')[1]
                contar+=1
                for y in turn:
                    res = see_time(te1, y[0], y[1], contar)
                    datas = {'employee_id':us,'name':te,'action':res,}
                    crea = self.pool.get('hr.attendance').create(cr,uid,datas)
                    attendance_obj.write(cr,uid,crea,datas,context=context)

                     #this not work too, not save any data

                    #cr.execute('''INSERT INTO hr_attendance (employee_id, name, action) VALUES( %s, %s, %s)''',(us, te, res,))

          #this is only for see the results of process

            raise osv.except_osv(_('Atención!'),_(type(res)))

Now this is my view: 

<record model="ir.ui.view" id="hr_py_import_time_menu_form">
            <field name="name">hr_py_import_time_menu_form_view</field>
            <field name="model">hr.py.import.menu</field>
            <field name="arch" type="xml">
                <form string="Importar">
                    <sheet>
                        <label for="name" string="Periodo" class="oe_inline"/>
                        <field name="name" class="oe_inline"/>
                        <button colspan="1" name="import_time" string="Importar Horas" type="object" class="oe_highlight"/>
                        <group>
                            <field name="time_s"/>
                        </group>
                    </sheet>
                </form>
            </field>
        </record>

        <record model="ir.ui.view" id="hr_py_import_time_menu_tree">
            <field name="name">hr_py_import_time_menu_tree_view</field>
            <field name="model">hr.py.import.menu</field>
            <field name="arch" type="xml">
                <tree string="Importar">
                    <field name="name"/>
                </tree>
            </field>
        </record>

The error:

crea = self.pool.get('hr.attendance').create(cr,uid,ids,datas) File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper return old_api(self, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/openerp/addons/hr_timesheet_sheet/hr_timesheet_sheet.py", line 482, in create sheet_id = context.get('sheet_id') or self._get_current_sheet(cr, uid, vals.get('employee_id'), vals.get('name'), context=context) AttributeError: 'list' object has no attribute 'get'

1
Avatar
Zrušit
Ludo - 21South

Jordan Vrtanoski is absolutely right. You only use the "ids" parameter on methods where you actually already have id's and need to either lookup data or manipulate the records.

Algode
Autor

Right, but if not use the "ids", no have error and not save any data in the database.

Avatar
Algode
Autor Nejlepší odpověď

When I use without "ids", this no give me any error but not save the record in the database. 

I don't know why and not know what can do more. 

0
Avatar
Zrušit
Jordan Vrtanoski

I also see the "write" after the "create". You don't need a "write" since create will already write the record to the database (unless there is exception in which case all changes are rolled back). First make sure that there are no exceptions in the log file. Next, check that you have the records in the database table with SELECT * from hr_attendance; It can be the case that you have not connected the records properly, so they appear "lost".

Algode
Autor

Thanks very much. The problem is solved. The problem was in the raise comand, that cause the lost of record.

Avatar
Jordan Vrtanoski
Nejlepší odpověď

The method create doesnt accept IDs, it creates new records, therefore it still doesn't have the ids. You can call the create in two ways:
[V7 and older] 
    self.pool.get('hr.attendance').create(cr, uid, values_dictionary, context=context)

[V8 style within methods decorated with @api.xxxxx ]
    hr_obj = self.env['hr.attendance']
    hr_obj.create(
values_dictionary)

 

1
Avatar
Zrušit
Enjoying the discussion? Don't just read, join in!

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

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Creating database results in "database does not Exist"
database data
Avatar
Avatar
Avatar
3
bře 15
14887
Getting data from user form Vyřešeno
database form data
Avatar
Avatar
Avatar
3
zář 23
5138
How to keep data after code refactoring?
database data odoo10
Avatar
Avatar
1
lis 18
5068
V11CE., Reset records without wiping database Vyřešeno
database records odoov11
Avatar
Avatar
2
bře 18
4152
Generate records in database automatically
database record save
Avatar
Avatar
1
dub 15
6747
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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