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

Inherit timesheet_grid and adjust_grid

Subscribe

Get notified when there's activity on this post

This question has been flagged
timesheetenterprisegridodoo16features
1 Reply
2067 Views
Avatar
Allan PEREZ

Hey

I'm using odoo enterprise, and I'm trying to inherit account.analytic.line and the method adjust_grid to avoid people to timesheet on a project after a date limit represented by the field date_done.

So in my module, I inherit account.analytic.line but my function is never called when I timesheet on a project, it seems that my override is not working. Any idea why ?
Here my code, I just copy paste the function from the class and add some log. I work with odoo.sh. Also my manifest depend of timesheet_grid, and my model is correctly loaded in my __init__ files

"depends": [
"base",
"project",
"timesheet_grid",
...
],

import logging
from odoo import tools, models, fields, api, _
from odoo.osv import expression
from odoo.exceptions import UserError, AccessError

_logger = logging.getLogger(__name__)

class AnalyticLine(models.Model):
_inherit = ['account.analytic.line']
def controlIfProjectIsDone(self):
_logger.debug("-------------------------")
_logger.debug("TEST")
_logger.debug("-------------------------")

def adjust_grid(self, row_domain, column_field, column_value, cell_field, change):
self.controlIfProjectIsDone()
if column_field != 'date' or cell_field != 'unit_amount':
raise ValueError(
"{} can only adjust unit_amount (got {}) by date (got {})".format(
self._name,
cell_field,
column_field,
))

additionnal_domain = self._get_adjust_grid_domain(column_value)
# Remove date from the domain
new_row_domain = []
for leaf in row_domain:
if leaf[0] == 'date':
new_row_domain += ['|', expression.TRUE_LEAF, leaf]
else:
new_row_domain.append(leaf)
domain = expression.AND([new_row_domain, additionnal_domain])
line = self.search(domain)

if line.project_id and not line.project_id.allow_timesheets:
raise UserError(_("You cannot adjust the time of the timesheet for a project with timesheets disabled."))

day = column_value.split('/')[0]


if len(line) > 1 or len(line) == 1 and line.validated: # copy the last line as adjustment
line[0].copy(self._prepare_duplicate_timesheet_line_values(
column_field, day, cell_field, change)
)
elif len(line) == 1: # update existing line
line.write({
cell_field: line[cell_field] + change
})
else: # create new one
line_in_domain = self.search(row_domain, limit=1)
if line_in_domain:
line_in_domain.copy(self._prepare_duplicate_timesheet_line_values(
column_field, day, cell_field, change)
)
else:
project, task = self._get_project_task_from_domain(domain)

if task and not project:
project = self.env['project.task'].browse([task]).project_id.id

if project:
_logger.debug("-------------------------------------------------")
_logger.debug("day %s", day)
_logger.debug("date done %s", project.date_done)
self.create([{
'project_id': project,
'task_id': task,
column_field: day,
cell_field: change,
}])

return False


0
Avatar
Discard
Avatar
Nomadoo
Best Answer

It seems like you are trying to override the adjust_grid method in the account.analytic.line model to add some additional logic. Your code looks correct for the most part, but there are a few things to check:


    Correct Inheritance:

    Ensure that your module depends on the timesheet_grid module and that it is correctly loaded before your module. The adjust_grid method is part of the timesheet_grid module, so if your module is not loaded after it, your override might not take effect.


    Check Log Output:

    The logging statements you've added (_logger.debug) should appear in the logs if the controlIfProjectIsDone method is being called. Check the logs to see if you find the log statements when timesheeting on a project.


    Method Signature:

    Verify that the method signature matches exactly with the method you are trying to override. If there have been changes in the Odoo version you are using, the method signature might differ, leading to your override not being recognized.


    Ensure Correct Module Dependencies:

    Ensure that your module's dependencies are correctly specified in the manifest file, and there are no conflicts or issues with other modules.


    Restart Odoo Service:

    After making changes to your code, restart the Odoo service to ensure that the changes are picked up.


    Check for Syntax Errors:

    Ensure that there are no syntax errors in your Python code that could prevent the correct loading of your module.

---------------------------------

    Use Decorators:

    In Odoo, decorators are often used for method overrides. Try using the @api.multi decorator on your overridden method to ensure it's recognized as a multi-record method.

@api.multi

def adjust_grid(self, row_domain, column_field, column_value, cell_field, change):

    # Your code here


---------------------------------


If, after checking these points, the issue persists, you may want to look into the Odoo server logs for any error messages or warnings that could provide more insight into why your method override is not working as expected

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
Embed video from YouTube using the website builder Odoo 16 Solved
enterprise odoo16features
Avatar
Avatar
1
Jul 23
3956
[SOLVED] Timesheet grid view
timesheet grid
Avatar
0
Nov 17
6917
Odoo Default terms and conditions on other page or backside of document
enterprise Odoo.sh odoo16features
Avatar
Avatar
1
May 25
2131
extending pos_settle_due PaymentScreen
enterprise odoo16features pointofsale
Avatar
Avatar
1
Aug 24
2514
Record does not exist or has been deleted. (Record: ir.actions.report(1,), User: 1) odoo 16 Solved
enterprise report odoo16features
Avatar
Avatar
Avatar
Avatar
3
Apr 24
9276
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