以下Python脚本不会创建日期字段:
from datetime import datetime
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
class DealInvoice(models.Model):
_inherit = 'account.invoice'
x_date_deal = fields.Date(string='Date Deal',
required=True,
readonly=True,
default=(date.today()),
index=True,
states={'draft': [('readonly', False)], 'sent': [('readonly', False)]},
help='Item date deal.')
@api.constrains('x_date_deal')
def _x_date_deal_check(self):
for record in self:
if record.x_date_deal and record.x_date_deal [0] <= str(date.today()):
raise ValidationError(_("Date deal must be before current date."))
答案 0 :(得分:0)
下面的代码给出错误“未定义日期”。最后,我只想验证一个日期是今天还是过去不超过5天。谢谢你的帮助。
从odoo导入api,字段,模型,_ 从odoo.exceptions导入ValidationError 从日期时间导入日期 今天= date.today
类AccountInvoice(models.Model): _inherit ='帐户。发票' _name ='account.invoice'
x_date_deal = fields.Date(string='Date of Deal', required=True, readonly=False, index=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, help='Date of Deal') @api.constrains('x_date_deal') def _delivery_date_check(self): for record in self: if record.x_date_deal and record.x_date_deal > today: raise ValidationError(_("Deal Date must be ...."))