You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在ODOO 10中停止抛出指定验证错误?(以日期校验为例)

How to Disable the Task Date Validation Error in Odoo 10

Got it, let's figure out how to turn off that specific validation error in Odoo 10. First off, you really shouldn't modify core Odoo files directly—doing that will cause headaches when you upgrade later. Instead, use Odoo's built-in inheritance system. Here are your go-to options:

This is the best practice because it keeps your changes separate from core code, so upgrades won't wipe them out. You'll need to create a custom module (if you don't have one already) and add this code to its Python file:

from odoo import models, api

class ProjectTask(models.Model):
    _inherit = 'project.task'

    @api.constrains('date_start', 'date_end')
    def _check_dates(self):
        # Completely disable the date validation by doing nothing here
        pass
        
        # If you want to keep partial validation (e.g., only for certain tasks),
        # you can add custom logic instead. For example:
        # if self.env.user.has_group('some.group'):
        #     super(ProjectTask, self)._check_dates()

After adding this, install your custom module, and the validation error will no longer trigger.

Only use this for testing purposes—since modifying core files will be overwritten when you upgrade Odoo. To do this:

  1. Locate the project.py file in Odoo's project module.
  2. Find the _check_dates method you mentioned.
  3. Either comment out the entire method or just the line that raises the error:

Comment the entire method:

# @api.constrains('date_start', 'date_end')
# def _check_dates(self):
#     if any(self.filtered(lambda task: task.date_start and task.date_end and task.date_start > task.date_end)):
#         raise ValidationError(_('错误!任务开始日期必须早于结束日期。'))

Or just comment the error raise line:

@api.constrains('date_start', 'date_end')
def _check_dates(self):
    if any(self.filtered(lambda task: task.date_start and task.date_end and task.date_start > task.date_end)):
        # raise ValidationError(_('错误!任务开始日期必须早于结束日期。'))
        pass

Important Notes:

  • Always prioritize Option 1—custom modules are the Odoo-approved way to modify behavior.
  • If you use Option 2, make sure to back up your changes before any Odoo upgrade, as core files will be replaced.
  • For the custom module approach, ensure your module declares a dependency on the project module in its __manifest__.py file.

内容的提问来源于stack exchange,提问作者Sachin Burnawal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:17:26