Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Timesheets multiple days

Subscribe

Get notified when there's activity on this post

This question has been flagged
developmentconfiguration
3 Replies
1317 Views
Avatar
SBB nv

Hello,

I often work on projects for an entire month. I use the Timesheet app that is connected with my Project and my Sales Order to make an invoice. 


Is it possible to add a start date (eg. 1st of the month),then an end date, so that the timesheets will be filled in with 8 hours a day, each working day of that period? 


I have seen some extra plugins that uses calendar view and a start and end date, but then the total amount of hours are calculated and not the working hours. 


I think that this is not a really specific topic and that more people will find this usefull. 


Thanks 

0
Avatar
Discard
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,

Please refer to the code below:

Python:


from odoo import models, fields

from datetime import timedelta


class ProjectTask(models.Model):

    _inherit = 'project.task'


    timesheet_start_date = fields.Date(string="Timesheet Start Date")

    timesheet_end_date = fields.Date(string="Timesheet End Date")

    daily_hours = fields.Float(string="Hours per Day", default=8.0)


    def action_create_timesheets(self):

        """

        Automatically generates timesheet entries for each working day

        (Monday to Friday) between the 'timesheet_start_date' and

        'timesheet_end_date' fields defined on the task.


        Each day will be filled with the number of hours defined in

        'daily_hours' field (default 8.0). Timesheet entries are

        created for the current user (must be linked to an employee).


        This method is triggered manually via a button on the task form.


        Raises:

            Skips any task that has missing start or end date.

            Does not check for existing timesheet duplication.

        """

        timesheet_model = self.env['account.analytic.line']

        for task in self:

            if not (task.timesheet_start_date and task.timesheet_end_date):

                continue

            current_date = task.timesheet_start_date

            while current_date <= task.timesheet_end_date:

                if current_date.weekday() < 5:  # Monday to Friday only

                    timesheet_model.create({

                        'name': f'Timesheet for {current_date}',

                        'project_id': task.project_id.id,

                        'task_id': task.id,

                        'unit_amount': task.daily_hours,

                        'date': current_date,

                        'employee_id': self.env.user.employee_id.id,

                        'user_id': self.env.uid,

                    })

                current_date += timedelta(days=1)


XML:


<record id="view_task_form2" model="ir.ui.view">

    <field name="name">project.task.form.timesheet.autofill</field>

    <field name="model">project.task</field>

    <field name="inherit_id" ref="project.view_task_form2"/>

    <field name="arch" type="xml">

        <xpath expr="//form//header" position="inside">

            <button name="action_create_timesheets"

                    string="Create Timesheets"

                    type="object"

                    class="oe_highlight"/>

        </xpath>

        <xpath expr="//form/sheet/notebook/page[@name='page_timesheets']"

               position="after">

            <page string="Timesheet Autofill">

                <group>

                    <field name="timesheet_start_date"/>

                    <field name="timesheet_end_date"/>

                    <field name="daily_hours"/>

                </group>

            </page>

        </xpath>

    </field>

</record>

Result:

When the button is clicked, timesheets are automatically created based on the provided data.


Hope it helps.

0
Avatar
Discard
Avatar
SBB nv
Author Best Answer

Wow, thanks for the quick reply. This custom module will not work in Odoo Online, but I will defenitely test it on our system. 

Thanks

0
Avatar
Discard
Avatar
D Enterprise
Best Answer

Hii,

Use a custom module:

Define a form (wizard) to input:

Start Date

End Date

Employee

Project/Task

Logic to fill working days only:

from datetime import timedelta

from odoo import models, fields, api

import datetime


class AutoTimesheetWizard(models.TransientModel):

    _name = 'auto.timesheet.wizard'


    employee_id = fields.Many2one('hr.employee', required=True)

    project_id = fields.Many2one('project.project', required=True)

    task_id = fields.Many2one('project.task', required=False)

    start_date = fields.Date(required=True)

    end_date = fields.Date(required=True)


    def action_fill_timesheets(self):

        user = self.employee_id.user_id

        date = self.start_date

        while date <= self.end_date:

            if date.weekday() < 5: # Monday to Friday (0-4)

                self.env['account.analytic.line'].create({

                    'name': 'Auto-filled timesheet',

                    'project_id': user.id ,

                    'unit_amount': 8,

                    'date': date,

                })

            date += timedelta(days=1)


i hope it is use full

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

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

Sign up
Related Posts Replies Views Activity
Dynamic Dashboard Background and Text on Dark/Light Theme Switch in Odoo 16 sh
development configuration
Avatar
Avatar
1
Nov 25
253
Bulk PDF download error
development configuration
Avatar
0
Oct 25
523
I am trying to set up a mass BOM edit. My Python code is giving forbidden opcode(s) error. Odoo 18
development configuration
Avatar
Avatar
Avatar
2
Sep 25
1062
Google Calendar Sync - Odoo Calendar
development configuration
Avatar
Avatar
Avatar
3
Aug 25
1989
How to set up contacts to require confirmation from a significant person when saving a new contact?
development configuration
Avatar
Avatar
Avatar
2
Jul 25
1907
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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