为odoo发票创建自定义文件名



我想更改发票的pdf文件名。我想在文件名中添加月份和年份。

知道如何验证日期字段吗?

欢呼本

它使用这种语法对"打印报告名称":

object._get_report_base_filename()
+'_'+
str(object.invoice_date.month) 
+'_'+
str(object.invoice_date.year)

这只适用于设置了invoice_date的情况。在汇票模式下,发票没有任何日期,因此出现错误:

500
nAttributeError: 'bool' object has no attribute 'month'nnDuring handling of the above exception, 
another exception occurred:nnTraceback (most recent call last):n  File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 2034, 
in report_downloadn    report_name = safe_eval(report.print_report_name, {'object': obj, 'time': time})n  
File "/home/odoo/src/odoo/odoo/tools/safe_eval.py", line 348, in safe_evaln    
raise ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr))nValueError: : 
"'bool' object has no attribute 'month'" while evaluatingn"\tobject._get_report_base_filename() 
\t\t+'_'+ \tstr(object.invoice_date.month)  \t\t+'_'+ \tstr(object.invoice_date.year)"n", "message": ": 
"'bool' object has no attribute 'month'" while evaluatingn"\tobject._get_report_base_filename() \t\t+'_'+ 
\tstr(object.invoice_date.month)  \t\t+'_'+ \tstr(object.invoice_date.year)"", 
"arguments": [": "'bool' object has no attribute 'month'" while evaluatingn"\tobject._get_report_base_filename() 
\t\t+'_'+ \tstr(object.invoice_date.month)  \t\t+'_'+ \tstr(object.invoice_date.year)""], "context": {}}}

这可能是因为空值返回为False。

我尝试使用if语句:

if (object.invoice_date == False): 'Jan' else: str(object.invoice_date.month)

但这不起作用。Odoo说语法不被识别。

知道如何验证日期字段吗?

欢呼本

您不需要在表达式中使用:,并且它位于值

之后你可以这样写:x if expression else y

例子:

str(object.invoice_date.month) if object.invoice_date else 'Jan'