Следующий скрипт 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."))