Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Consulting
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

How to change the value of a field which depends on other fields automatically ?

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
python3odoo11
2 Replies
15552 Rodiniai
Portretas
Dhouha

I have installed a custom module named "bt_hr_overtime" because i want to calculate the overtime of each employee. This module use a scheduled action which called run_overtime_scheduler. The probleme is the overtime hours is depending of the check in hour and check ou hour . So if the employees modify his attendance information the overtime hours don't change which is not correct. Any idea on how to make the overtime hours change automatically when the attendance information changed. i have created a button to recalculate the overtime hours.

overtime.py

@api.model
def run_overtime_scheduler(self):
    """ This Function is called by scheduler. """

current_date = date.today()
working_hours_empl = self.env['hr.contract']
attend_signin_ids = self.env['hr.attendance'].search([('overtime_created', '=', False)])
for obj in attend_signin_ids:
    if obj.check_in and obj.check_out:
        start_date = datetime.datetime.strptime(obj.check_in, DEFAULT_SERVER_DATETIME_FORMAT)
end_date = datetime.datetime.strptime(obj.check_out, DEFAULT_SERVER_DATETIME_FORMAT)
difference = end_date - start_date
hour_diff = str(difference).split(':')[0]
min_diff = str(difference).split(':')[1]
tot_diff = hour_diff + '.' + min_diff
actual_working_hours = float(tot_diff)
contract_obj = self.env['hr.contract'].search([('employee_id', '=', obj.employee_id.id), ('work_hours', '!=', 0)])
for contract in contract_obj:
    working_hours = contract.work_hours
if actual_working_hours > working_hours:
    overtime_hours = actual_working_hours - working_hours
vals = {
    'employee_id': obj.employee_id and obj.employee_id.id or False,
    'manager_id': obj.employee_id and obj.employee_id.parent_id and obj.employee_id.parent_id.id or False,
    'start_date': obj.check_in,
    'overtime_hours': round(overtime_hours, 2),
    'attendance_id': obj.id,
}
self.env['bt.hr.overtime'].create(vals)
obj.overtime_created = True

overtime.xml

<record id="bt_overtime_management_form" model="ir.ui.view">
        <field name="name">bt.hr.overtime.form</field>
        <field name="model">bt.hr.overtime</field>
        <field name="arch" type="xml">
            <form string="Overtime">
            <header>
                <button name="action_submit" type="object" string="Submit" groups="base.group_user" attrs="{'invisible':[('state', '!=', 'draft')]}"/>
                <button name="action_cancel" type="object" string="Cancel" groups="base.group_user,hr.group_hr_manager" attrs="{'invisible':[('state', '!=', 'confirm')]}"/>
                <button name="action_approve" type="object" string="Approve" groups="hr.group_hr_manager" attrs="{'invisible':[('state', '!=', 'confirm')]}"/>
                <button name="action_refuse" type="object" string="Refuse" groups="hr.group_hr_manager" attrs="{'invisible':[('state', '!=', 'confirm')]}"/>
                <field name="state" widget="statusbar" statusbar_visible="draft,confirm,refuse,validate,cancel"/>
                <button name="recalculate" type="object" string="Recalculate" class="oe_highlight"/>
            </header>
            <sheet>
                <div class="oe_button_box" name="button_box">
                    <button name="action_view_attendance" type="object" 
                    class="oe_stat_button" icon="fa-user" string="Attendance">
                    </button>
                </div>
                <group>
                    <group>
                        <field name="employee_id" required="True" readonly="0"/>
                        <field name="manager_id" readonly="0"/>
                    </group>
                    <group>
                        <field name="start_date" readonly="0"/>
                        <field name="overtime_hours" readonly="0" />
                        <field name="attendance_id" invisible="1"/>
                    </group>
                </group>
               <notebook>
                    <page string="Notes">
                        <field name="notes"/>
                    </page>
               </notebook>
            </sheet>
           </form>
        </field>
      </record> 


0
Portretas
Atmesti
Portretas
Sudhir Arya (ERP Harbor Consulting Services)
Best Answer

You can make overtime field as compute field and define other fields in api.depends('field1', 'field2').

If you don't want to use compute field, override create, write methods and check your other fields in the vals. If they are in the vals, then calculate the overtime and update the overtime field by passing it's value to vals.


 

3
Portretas
Atmesti
Dhouha
Autorius

But i need to change overtime_hours in everytime the employee modify their check in/out in the model hr.attendance is it possible ?

Dhouha
Autorius

Can i use @api.onchange as another solution ?

Dhouha
Autorius

Could you help me please. i'm stuck with this problem and i'm new in odoo and i'm don't know how to make overtime field as a computed field . Should i modify this function run_overtime_scheduler ?

Portretas
Zbik
Best Answer

Install the base_automation module.
It will allow you to run various actions automatically and depending on what, for example, will be saved in another model and record. Bellow description of this module:

This module allows to implement action rules for any object.
============================================================

Use automated actions to automatically trigger actions for various screens.

**Example:** A lead created by a specific user may be automatically set to a specific
sales channel, or an opportunity which still has status pending after 14 days might
trigger an automatic reminder email.


UPDATE:

1. Install base_automation
2. Enable developer mode
3. Got to menu /Settings/Technical/Automation/Automated actions
4. Click on create, select Trigger Condition = On Creation & Update, select model = hr.attendance
5. Now OR:
5a. Select Action To Do = Execute Python Code and create your code (first you read help info in field)
5b. Select Action To Do = Execute several actions and select server action/s (create a server action beforehand)

​

1
Portretas
Atmesti
Dhouha
Autorius

how could i use this model to relate the update of the field overtime_hours to fields check in /out from the hr.attendance model ?

Zbik

You use trigger on_write on model hr.attendance and server action = your action.

Dhouha
Autorius

can i use @api.onchange as another solution ?

Zbik

onchange is not a good solution. This method shuld be used for manipulate record values presented in the form. See documentation: https://www.odoo.com/documentation/12.0/reference/orm.html#module-odoo.api

Dhouha
Autorius

Could you help me please. i'm stuck with this problem and i'm new with odoo, i don't know how to use trigger on_write on model hr.attendance

Zbik

My answer is updated - with steps.

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

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

Registracija
Related Posts Replies Rodiniai Veikla
How to set a filter as default filter in odoo Solved
python3 odoo11
Portretas
Portretas
Portretas
2
vas. 24
16635
How to set default stage to when recruitement record is created Solved
python3 odoo11
Portretas
Portretas
1
gruod. 22
5747
how to modify fields of hr.attendance via a modification request automatically Solved
python3 odoo11
Portretas
Portretas
Portretas
2
birž. 22
7697
how to update field of attendance via an attendance request modification
python3 odoo11
Portretas
Portretas
Portretas
2
birž. 22
5688
Field Value Update In Another Module Depend On Calculation
python3 odoo11
Portretas
0
geg. 22
4561
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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