Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

Create multi records from one server action

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
development
1 Répondre
2743 Vues
Avatar
Ali Ammar
ValueError: : "Expected singleton: hr.salary.details(1, 2)" while evaluating
'for record in records:\n record.calculate_salary()'

my server action xml code:

 

< field name = "name" > calculate salary field > 

 

 

list field> 

code field> 

                 for record in records:

                         record.calculate_salary()

field > 

records >                                                            

my function: 

def calculate_salary(self):

         for rec in self:

             salary = []

             get_date = datetime. today (  ) 

             month = int(get_date.month ) -1_ 

             salary . append({ 'name': ('salary for') + " " + str(rec.employee1_name_id['name'])+ " " + str(month ),

                                 'employee1_name': rec. employee1_name_id [ 'name' ],

                                 'salary_id': rec.id ,

                                 'employee_number': rec. employee_number_id ,

                                 'employee_job_title': rec. employee_job_title , 

                                'employee_salary': rec . employee_salary ,

                                 'hawafez_salary': rec. hawafez_salary , 

                                'cooperation_box': rec . cooperation_box ,

                                 ':rec. total_salary ,                                

                            })

             rec. env [ 'hr.salary.months' ].create( salary )


0
Avatar
Ignorer
Avatar
Malay Khamar (Serpent Consulting Services Pvt. Ltd.)
Meilleure réponse

Hi Ali Ammar,

As you are already added a loop into your function, So you can directly use the records in the server code.

Just like :

       field name="code"> records.calculate_salary()

Also at the last line , you can directly use a self instead of rec for salary month object. Just like:

                 self. env [ 'hr.salary.months' ].create( salary )

And try to defined the object in a variable outside of the loop and use that variable into the code for better code execution and performance.

I already Provide the solution for this in your previous question which was closed by you. 
Have you checked that. 

Updated Answer:

Please try with the below code 



# Server Action
record id="generate_salary" model="ir.actions.server">
field name="name">calculate salary
field name="model_id" ref="hr_salary.model_hr_salary_details"/>
field name="binding_model_id" ref="hr_salary.model_hr_salary_details"/>
field name="binding_view_types">list
field name="state">code
field name="code">
if records:
records.calculate_salary()
/field>
/record>


# Let the system take the default api
def calculate_salary(self):
salary_mnth_obj = self.env['hr.salary.months']
for rec in self:
salary_mnth_obj.create({
'name': ('salary for') + " " + str(rec.employee1_name_id.name),
'employee1_name': rec. employee1_name_id.name,
'salary_id': rec.id ,
'employee_number': rec.employee_number_id,
'employee_job_title': rec. employee_job_title,
'employee_salary': rec . employee_salary,
'hawafez_salary': rec. hawafez_salary,
'cooperation_box': rec . cooperation_box ,
})
return True
Hope it will help you.
2
Avatar
Ignorer
Ali Ammar
Auteur

I do all that you say
I still have the same error
if I delete the create method I don't have error
but when I add it and run for multi record I faced the error

Malay Khamar (Serpent Consulting Services Pvt. Ltd.)

Hi ,
Can you please try with the below code.

# Server Action
record id="generate_salary" model="ir.actions.server">
field name="name">calculate salary</field>
field name="model_id" ref="hr_salary.model_hr_salary_details"/>
field name="binding_model_id" ref="hr_salary.model_hr_salary_details"/>
field name="binding_view_types">list</field>
field name="state">code</field>
field name="code">
if records:
records.calculate_salary()
/field>
/record>

# Let the system take the default api
def calculate_salary(self):
salary_mnth_obj = self.env['hr.salary.months']
for rec in self:
salary_mnth_obj.create({
'name': ('salary for') + " " + str(rec.employee1_name_id.name),
'employee1_name': rec. employee1_name_id.name,
'salary_id': rec.id ,
'employee_number': rec.employee_number_id,
'employee_job_title': rec. employee_job_title,
'employee_salary': rec . employee_salary,
'hawafez_salary': rec. hawafez_salary,
'cooperation_box': rec . cooperation_box ,
})
return True

Hope it will help you.

Malay Khamar (Serpent Consulting Services Pvt. Ltd.)

Hi Ali Ammar,
Please check the updated answer. I hope it will help you.

Ali Ammar
Auteur

raise exception.with_traceback(None) from new_cause
ValueError: <class 'ValueError'>: "Expected singleton: hr.salary.details(1, 2, 3)" while evaluating
'if records:\n records.calculate_salary()'

after I run your code

Malay Khamar (Serpent Consulting Services Pvt. Ltd.)

Then you must be check the code for the create and compute methods of the model "hr.salary.months" and the api decorators for those methods.
I hope it will help you.

Ali Ammar
Auteur

the problem in create method and I don't know how to solve

Malay Khamar (Serpent Consulting Services Pvt. Ltd.)

Please share the create method.
Thanks

Ali Ammar
Auteur

I didn't write any thing else over the above code
create method still like itself

Malay Khamar (Serpent Consulting Services Pvt. Ltd.)

Ok , then try to add a create method in the model and check the result. Hope it will help you.

Ali Ammar
Auteur

What should I write in this method?

Ali Ammar
Auteur

I solve singleton error
thanx
but now it's create only the first record in my selected records as much i select records

Malay Khamar (Serpent Consulting Services Pvt. Ltd.)

Please print the self into your code and check if it takes the multiple records or not.
User active_ids from the context instead of the self.
Hope it will help you

Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
Odoo 17: How to Create a Custom Table Header in List (Tree) View Using OWL
development
Avatar
0
déc. 25
98
How to create custom Table header by using odoo 17
development
Avatar
Avatar
1
déc. 25
304
Oddo Integration with Intune
development
Avatar
0
déc. 25
1742
@guia@¿Cómo hablar con una persona en Air France?
development
Avatar
0
déc. 25
2
How do I change the name of the module, or rather the name assigned to the module, after I created it in Odoo Studio?
development
Avatar
Avatar
1
déc. 25
554
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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