【问题标题】:Problem adding datefield to invoice odoo12将日期字段添加到发票odoo12的问题
【发布时间】:2019-05-09 13:52:01
【问题描述】:

以下 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."))

【问题讨论】:

  • 如果该字段尚未创建,则表示该字段 x_date_deal 在数据库中的表 account_invoice 上不存在,请检查您的 __init__.py 文件以确保您的文件正在导入,然后重启 Odoo 并升级模块。
  • 如果您的意思是在视图中看不到新创建的字段,那是因为您需要使用继承对其进行修改。
  • 通过不同的方式解决了:
  • from odoo import api, fields, models class AccountInvoice(models.Model): _inherit = 'account.invoice' x_date_deal = fields.Date(string="Date of Deal")
  • 我刚刚看到了readonly=True 选项。使用它会使 Odoo 忽略用户放在那里的任何内容。它应与_compute 一起使用

标签: invoice datefield odoo-12


【解决方案1】:

下面的代码给出了错误“日期未定义”。最后,我只想确认日期是今天还是过去不超过 5 天。谢谢你的帮助。

从 odoo 导入 api、字段、模型、_ 从 odoo.exceptions 导入 ValidationError 从日期时间导入日期 今天 = 日期.今天

类 AccountInvoice(models.Model): _inherit = 'account.invoice' _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 ...."))

【讨论】:

    猜你喜欢
    • 2013-01-28
    • 1970-01-01
    • 2019-09-05
    • 2020-11-22
    • 1970-01-01
    • 2021-04-03
    • 1970-01-01
    • 2021-11-28
    • 2015-07-06
    相关资源
    最近更新 更多