Odoo QWeb:指客户公司
Odoo QWeb: refering to customer company
创建自定义 Odoo 销售/报价报告时,如何在 Qweb 代码中始终引用 客户公司?
在 Odoo 中,数据模型有公司和个人。个人可以链接到公司。让我们举个例子:我的 Odoo 公司叫做我的公司。我们已经注册了一个客户 The Client Ltd。一个人 John Smith 已注册为 The Client Ltd.
的代表
现在,要为客户创建报价,我公司的销售人员可以将文件发送给“The Client Ltd”或“The Client有限公司,约翰·史密斯”。
在我的自定义报告中,我想打印出客户的名称公司。所以,我打电话给<span t-field="o.partner_id.name"/>
。如果将报价发给公司,则此方法有效。但是如果报价发给“The Client Ltd, John Smith”,输出只是“John Smith”。
我试过使用 <span t-field="o.partner_id.parent_id.name"/>
来引用客户公司,只要所有报价都发给在公司注册的人,例如“The Company Ltd, John Smith”,它就可以工作。但是......一旦有一个报价发给没有专人的公司,<span t-field="o.partner_id.parent_id.name"/>
评估为“我的公司”,这显然是错误的。
也尝试了几个案例。试图卖给:
- 个人(即没有公司)
- 客户有限公司(即没有人)
- The Client Ltd,John Smith。
结果
N <span t-field="o.partner_id.name"/>
id <span t-field="o.partner_id"/>
正在关注:
个人:
- N:个人
- id: 个人
客户Ltd(无人):
- N:客户有限公司
- id: The Client Ltd
客户有限公司,John Smith:
- N:约翰·史密斯
- id: The Client Ltd, John Smith
我如何确保报价始终发给客户,而不是我自己的公司?
我找到了答案。诀窍是查看父项是否存在,然后才使用 partner_id.parent_id。如果 parent_id 不存在,尝试引用它会溢出到 Odoo 公司的名称。
所以 QWeb 报告只需要一个简单的 if-then-else。这是代码块:
<t t-if="o.partner_id.parent_id">
<!-- Logic: if a parent connection exists, print parent's name-->
<span t-field="o.partner_id.parent_id"/>
</t>
<t t-else="">
<!-- If parent does not exist, just print the partner_id-->
<span t-field="o.partner_id"/>
</t>
创建自定义 Odoo 销售/报价报告时,如何在 Qweb 代码中始终引用 客户公司?
在 Odoo 中,数据模型有公司和个人。个人可以链接到公司。让我们举个例子:我的 Odoo 公司叫做我的公司。我们已经注册了一个客户 The Client Ltd。一个人 John Smith 已注册为 The Client Ltd.
的代表现在,要为客户创建报价,我公司的销售人员可以将文件发送给“The Client Ltd”或“The Client有限公司,约翰·史密斯”。
在我的自定义报告中,我想打印出客户的名称公司。所以,我打电话给<span t-field="o.partner_id.name"/>
。如果将报价发给公司,则此方法有效。但是如果报价发给“The Client Ltd, John Smith”,输出只是“John Smith”。
我试过使用 <span t-field="o.partner_id.parent_id.name"/>
来引用客户公司,只要所有报价都发给在公司注册的人,例如“The Company Ltd, John Smith”,它就可以工作。但是......一旦有一个报价发给没有专人的公司,<span t-field="o.partner_id.parent_id.name"/>
评估为“我的公司”,这显然是错误的。
也尝试了几个案例。试图卖给:
- 个人(即没有公司)
- 客户有限公司(即没有人)
- The Client Ltd,John Smith。
结果
N <span t-field="o.partner_id.name"/>
id <span t-field="o.partner_id"/>
正在关注:
个人:
- N:个人
- id: 个人
客户Ltd(无人):
- N:客户有限公司
- id: The Client Ltd
客户有限公司,John Smith:
- N:约翰·史密斯
- id: The Client Ltd, John Smith
我如何确保报价始终发给客户,而不是我自己的公司?
我找到了答案。诀窍是查看父项是否存在,然后才使用 partner_id.parent_id。如果 parent_id 不存在,尝试引用它会溢出到 Odoo 公司的名称。
所以 QWeb 报告只需要一个简单的 if-then-else。这是代码块:
<t t-if="o.partner_id.parent_id">
<!-- Logic: if a parent connection exists, print parent's name-->
<span t-field="o.partner_id.parent_id"/>
</t>
<t t-else="">
<!-- If parent does not exist, just print the partner_id-->
<span t-field="o.partner_id"/>
</t>