gpt4 book ai didi

attachment - 计算附件数量并在 openerp 7.0 的 TreeView 中显示

转载 作者:行者123 更新时间:2023-12-02 03:27:30 24 4
gpt4 key购买 nike

我正在使用以下代码在 stock.picking.in 对象中添加一个新列并更新它的附件数(以在 TreeView 中显示附件数)。

class stock_picking(osv.osv):
_inherit = "stock.picking.in"
_name = 'stock.picking.in'
def count_attachments(self, cr, uid, ids, fields, arg, context):
obj_attachment = self.pool.get('ir.attachment')
for record in self:
_logger.info("record now in tree view:"+record)
record.attachment_count =0
attachment_ids = obj_attachment.search([('res_model','=','stock.picking.in'),('res_id','=',record.id)]).ids
if attachment_ids:
record.attachment_count =len(attachment_ids)
return record

_columns = {
'attachment_count' :fields.function(count_attachments,method=True,string="Attachment Count" ,type='integer')
}

选股()

然后我将以下行添加到 TreeView 中。

<field name="attachment_count">

在 TreeView 中显示计数。

但是这些值没有得到更新并且 count_attachments 没有被调用。

感谢任何帮助。提前致谢!

最佳答案

尝试跟随,

class stock_picking(osv.osv):
_inherit = "stock.picking.in"
_name = 'stock.picking.in'

def count_attachments(self, cr, uid, ids, fields, arg, context=None):
obj_attachment = self.pool.get('ir.attachment')
res = {}
for record in self:
res[record.id] = 0
_logger.info("record now in tree view:"+record)
attachment_ids = obj_attachment.search([('res_model','=','stock.picking.in'),('res_id','=',record.id)]).ids
if attachment_ids:
res[record.id] = len(attachment_ids)
return res

_columns = {
'attachment_count' :fields.function(count_attachments,method=True,string="Attachment Count" ,type='integer')
}

关于attachment - 计算附件数量并在 openerp 7.0 的 TreeView 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29666323/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com