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