有多少个文件都是相同的值?

2024-05-20 13:17:09 发布

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

我有这个代码:

在.py文件中:

class newsaleorderline(models.Model):
    _inherit='sale.order.line'

    supply_tax_id = fields.Many2many('account.tax',string='Supply Taxes',domain=['|', ('active', '=', False), ('active', '=', True)])         
    labour_tax_id = fields.Many2many('account.tax',string='Labour Taxes',domain=['|', ('active', '=', False), ('active', '=', True)])

在.xml文件中:

^{pr2}$

当我试图更改supply_tax_id时,它发生了变化,但是在保存supply_tax_idlabour_tax_id两者都是相同的。我不知道它是怎么联系在一起的。我希望supply_tax_id和{}应该是不同的值,字段应该来自{}。在

请帮我找到这个问题的解决办法。谢谢大家的建议。在


Tags: 文件代码idfalsetruefieldsstringdomain
1条回答
网友
1楼 · 发布于 2024-05-20 13:17:09

Odoo正在您的数据库中生成关系表。您可以在字段定义中自行指定表名:

class MyModel(models.Model):
    _name = "my.model"

    my_m2m_field = fields.Many2Many(
        comodel_name="another.model", # required
        relation="my_model_another_model_rel", # optional
        column1="my_model_id", # optional
        column2="another_model_id", # optional
        string="Another Records" # optional
    )

您的示例没有在字段定义中使用relation参数,因此Odoo自己生成一个名称。它使用两个模型(表)名称,并在名称末尾添加一个“\u rel”:

sale_order_line_account_tax_rel

这里的问题是:您在两个不同的Many2Many字段上使用相同的两个模型,这两个字段最终将在一个关系表中结束。因此,在使用这些字段时,这两个字段将在客户机中表示相同的数据。在

解决方案:使用参数relation,并为关系表定义两个不同的名称。在

相关问题 更多 >