【问题标题】:bool object has no attribute in odoo 10bool 对象在odoo 10中没有属性
【发布时间】:2018-07-11 05:31:46
【问题描述】:
Error: AttributeError: 'bool' object has no attribute 'split'

Error to render compiling AST
AttributeError: 'bool' object has no attribute 'split'
Template: 549
Path: /templates/t/t/div/table/tr/td[1]/t
Node: <t t-foreach="get_container_number(doc)" t-as="cotainer_no">
                <span style="text-transform:uppercase; font-family:'Times New Roman'; font-size:10px;" t-esc="cotainer_no"/><br data-oe-id="549" data-oe-model="ir.ui.view" data-oe-field="arch" data-oe-xpath="/t[1]/t[1]/div[1]/table[1]/tr[1]/td[1]/t[1]/br[1]"/>
            </t>

python中的代码:

class bl_report(models.AbstractModel):
_name = 'report.export_document.bl_report'

@api.multi
def render_html(self,docids, data=None):
    report_obj = self.env['report']
    report = report_obj._get_report_from_name('export_document.bl_report')
    docargs = {
               'doc_ids': self.ids,
               'doc_model': report.model,
               'docs': self.env['document.export'].browse(data.get('doc_ids')),
               'data' : data,
               'get_container_number':self._get_container_number,
               'get_shipping_unit':self._get_shipping_unit,
               }

    print "=============docard",docargs
    return report_obj.render('export_document.bl_report', docargs)

def _get_container_number(self,doc):
    result1 = doc.no_of_container.split(',')
    return result1

def _get_shipping_unit(self,doc):
    result1 = doc.qty_packed.split(',')
    return result1

【问题讨论】:

  • 你为什么要传递一个布尔值?
  • split() 是作用于字符串的函数,但您在参数 doc 中传递的是 bool 类型
  • @keer 实际上,doc.no_of_container 需要是该错误的 bool 类型
  • 不,我没有传递任何 bool 类型。 no_of_container 在 Char 类型字段中

标签: xml python-3.x odoo odoo-10


【解决方案1】:

请确保您没有通过添加验证的 bool 字段:

def _get_container_number(self,doc):
    if doc.no_of_container:
        result1 = doc.no_of_container.split(',')
        return result1
    return False

def _get_shipping_unit(self,doc):
    if doc.qty_packed:
        result1 = doc.qty_packed.split(',')
        return result1
    return False

希望这个回答对你有帮助。

【讨论】:

  • 没用。实际上,当我将这个模块复制到我的系统上进行模板自定义时,这个模块完全可以在其他单台笔记本电脑上运行,这将显示错误。我刚刚将模板从 Times new roman 更改为 Tahoma
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-16
  • 2021-07-06
  • 1970-01-01
  • 1970-01-01
  • 2022-07-01
  • 2023-03-27
  • 1970-01-01
相关资源
最近更新 更多