在不同型号的树状视图中显示一个2多个字段[Odoo]

2024-05-18 18:57:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我想显示在特定发票中应用的所有税款及其金额[在模型的树状视图中]帐户.发票] 这是输出:

enter image description here

列Tax Lines显示表中存在的税的id账户发票税(但我想显示他们的名字和相应的金额)

模型帐户.发票有一个名为tax_line_ids[tax Lines]的字段,其中包含存储在单独表中的发票上的所有税款记录账户发票税,在其自身的树视图中如下所示:

enter image description here

我想提取税名及其相应的金额,以便反映在其中帐户.发票的树视图

下面是我的python代码,它似乎不起作用:

@api.one
def taxz(self):
    tax_pool = self.pool.get("account.tax")
    found_taxes = tax_pool.read(cr, uid, [tax_id,], ["tax_line_ids"], context)
    found_tax = found_taxes[0] if found_taxes else None
    tax_line_ids = found_tax["tax_line_ids"]
    _logger.critical("context type: " + type(context))
    _logger.critical("context content: " + str(context))
    _logger.critical(tax_line_ids)

视图的xml代码:

^{pr2}$

Tags: 模型视图idscontextline帐户发票logger
2条回答

您可以添加一个char字段,以便在treeview的显示中使用它:

class Invoice(models.Model):
        _inherit = 'account.invoice'

        tax_line_tree_view = fields.Char(compute='get_tax_list')

        @api.multi
        def get_tax_list(self):
             tax_disp = ""
             for rec in self:
                  if rec.taxe_line:
                       for tax in taxe_line:
                            tax_disp = tax_disp + "["+tax.name+"], " 
                       rec.tax_line_tree_view = tax_disp[:-2] # [:-2] just to remove the last ', ' characters.
                  else:
                       rec.tax_line_tree_view  = tax_disp

在树视图所在的XML文件中,添加以下字段:

^{pr2}$

而不是税号。在

我希望这能回答你的问题。在

试试这个:

    class Invoice(models.Model):
        _inherit = 'account.invoice'

        tax_line_ids = fields.Many2many('account.invoice.tax',
                                        'invoice_taxes', 
                                        'invoice_id', 
                                        'taxt_id',
                                        'List of taxes',
                                    compute='get_tax_list', store=True)



        @api.depends('tax_line', 'tax_line.amount')
        def get_tax_list(self):
            for rec in self:
                if rec.taxe_line:
                    rec.tax_line_ids = [(6,0,rec.tax_line.ids)]
                else:
                    rec.tax_line_ids = [(5,0,0)]

但是这样做只会在树视图中显示没有金额的税收列表 如果要显示重写account.invoice.tax中的name_get方法所需的数量 但这将影响所有x2many字段。在

^{pr2}$

如果您不希望这样做,则需要将类型更改为Char,并重新计算字段 或者创建另一个model来节省税收并为该模型定义{}。在

正如你现在看到的,这对我有效,如果你仍然得到keyErro,你一定是做了一些错误的事情检查你的代码缩进继承值。。。公司名称:

enter image description here

相关问题 更多 >

    热门问题