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

how to modify fields of hr.attendance via a modification request automatically

S'inscrire

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

Cette question a été signalée
python3odoo11
2 Réponses
7799 Vues
Avatar
Dhouha

i'm using odoo 11. i have create a custom module for attendance modification request which be approuved by the manager of attendance . My goal is to limit the acces to the modification of attendance and when the manager press approuve "hr.attendance" will be modified automatically whith the new values of check_in and check_out (if it's the same employee and same date between "hr.attendance" and my request modification). The problem is when i press approuve there is no error but in the same time there is no modification. Here is my code. Any idea for help please ?

modification_request.xml

<record model="ir.ui.view" id="view_attendance_modification_request_form">
    <field name="name">attendance.modification.request.form</field>
    <field name="model">attendance.modification.request</field>
    <field name="arch" type="xml">
        <form string="Attendance modification Request">
            <header>
                <field name="state" statusbar_visible="draft,waiting,approved,cancel" widget="statusbar" />
                <button name="submit_modification" string="Submit for manager" type="object" class="btn-primary"
                        attrs="{'invisible': [('state','not in','draft')]}"/>
                <button name="modification_approval" type="object" string="Approve" class="oe_highlight"
                        groups="hr_attendance.group_hr_attendance_manager"
                        attrs="{'invisible': [('state','not in','waiting')]}"/>
                <button name="modification_rejection" type="object" string="Cancel" class="oe_highlight"
                        groups="hr_attendance.group_hr_attendance_manager"
                        attrs="{'invisible': [('state','not in','waiting')]}"/>
            </header>
            <sheet>

                <h2>
                    <group>

                        <field name="employee_id"/>
                    </group>
                </h2>
                <group  col="4" colspan="4">
                    <field name="time_check_in_1"/>
                    <field name="time_check_out_1"/>
                </group>

                <label for="note"/>
                <field name="note"/>
            </sheet>
            <field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/>
            <field name="activity_ids" widget="mail_activity"/>
            <field name="message_ids" widget="mail_thread"/>


        </form>
    </field>
</record>

modification_request.py

 class AttendanceModificationRequest(models.Model):
_name = 'attendance.modification.request'
_description = 'Attendance modification Request'
_inherit = ['mail.thread', 'mail.activity.mixin']

def _get_employee_id(self):
    employee_rec = self.env['hr.employee'].search([('user_id', '=', self.env.uid)], limit=1)
    return employee_rec.id
employee_id = fields.Many2one('hr.employee',"Employee", readonly=True,default=_get_employee_id, required=True)
user_id = fields.Many2one('res.users', string='User', track_visibility='onchange', readonly=True,
                          states={'draft': [('readonly', False)]}, default=lambda self: self.env.user)
state = fields.Selection([
    ('draft', 'Pending'),
    ('waiting', 'Waiting for approval'),
    ('approved', 'Approved'),
    ('cancel', 'Cancelled')], readonly=True,
    help="Gives the state of the attendance request modification .",
    default='draft')
modification_date = fields.Date("Date")
time_check_in_1 = fields.Datetime("Check in")
time_check_out_1 = fields.Datetime("Check out")
note = fields.Text("Note")
attendance_id = fields.Many2one('hr.attendance', string='Attendance')
@api.multi
def modification_approval(self):
    attend_signin_ids = self.env['hr.attendance']
    check_in_date = datetime.strptime(self.time_check_in_1, "%Y-%m-%d %H:%M:%S").date()
    check_out_date = datetime.strptime(self.time_check_out_1, "%Y-%m-%d %H:%M:%S").date()

    for obj in attend_signin_ids :
      attendance_check_in_date = datetime.strptime(obj.check_in, "%Y-%m-%d %H:%M:%S").date()
      attendance_check_out_date = datetime.strptime(obj.check_out, "%Y-%m-%d %H:%M:%S").date()
      if (obj.employee_id == self.employee_id) and (check_in_date == attendance_check_in_date):
           obj.check_in = self.time_check_in_1
           obj.check_out = self.time_check_out_1

    return self.write({
        'state': 'approved'
    })



0
Avatar
Ignorer
Avatar
Anusha
Meilleure réponse

Hi,

  Change the    attend_signin_ids to self.env['hr.attendance'].search([('employee_id','=',self.employee_id.id)])

def modification_approval(self):
    attend_signin_ids = self.env['hr.attendance'].search([('employee_id','=',self.employee_id.id)])
    check_in_date = datetime.strptime(self.time_check_in_1, "%Y-%m-%d %H:%M:%S").date()
    check_out_date = datetime.strptime(self.time_check_out_1, "%Y-%m-%d %H:%M:%S").date()

    for obj in attend_signin_ids :
      attendance_check_in_date = datetime.strptime(obj.check_in, "%Y-%m-%d %H:%M:%S").date()
      attendance_check_out_date = datetime.strptime(obj.check_out, "%Y-%m-%d %H:%M:%S").date()
      if (check_in_date == attendance_check_in_date):
           obj.write({'check_in': self.time_check_in_1,
                      'check_out': self.time_check_out_1})

    return self.write({
        'state': 'approved'
    })


0
Avatar
Ignorer
Dhouha
Auteur

Thanks for you answer but there's an error that display " strptime() argument 1 must be str, not bool" Do you know how to fix it ?

Anusha

check_in_date = datetime.strptime(str(self.time_check_in_1), "%Y-%m-%d %H:%M:%S").date()

conver the datetime to string in strptime()

Dhouha
Auteur

Thank you very much it works and it shows another error which said " ValueError: time data 'False' does not match format '%Y-%m-%d %H:%M:%S'". I try to found a solution so i viewed the date of the table "hr.attendance" but they are the same format ""2019-05-08 10:06:51"".I don't know where the problem is ?

Avatar
Muhammad Mohiuddin
Meilleure réponse

@Dhouha have you solved this problem?

0
Avatar
Ignorer
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é
How to set a filter as default filter in odoo Résolu
python3 odoo11
Avatar
Avatar
Avatar
2
févr. 24
16692
How to set default stage to when recruitement record is created Résolu
python3 odoo11
Avatar
Avatar
1
déc. 22
5797
How to change the value of a field which depends on other fields automatically ? Résolu
python3 odoo11
Avatar
Avatar
Avatar
2
déc. 22
15628
how to update field of attendance via an attendance request modification
python3 odoo11
Avatar
Avatar
Avatar
2
juin 22
5739
Field Value Update In Another Module Depend On Calculation
python3 odoo11
Avatar
0
mai 22
4610
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