【问题标题】:Odoo QWeb: refering to customer companyOdoo QWeb:指客户公司
【发布时间】:2020-06-30 23:29:06
【问题描述】:

在创建自定义 Odoo 销售/报价报告时,如何在 Qweb 代码中始终引用客户公司

在 Odoo 中,数据模型包含公司和人员。人员可以链接到公司。举个例子:我的 Odoo 公司叫做 My Company。我们已经注册了一个客户The Client LtdJohn Smith 已注册为 The Client Ltd. 的代表。

现在,要为客户创建报价,我公司的销售人员可以将文件发送给“The Client Ltd”或“The Client Ltd, John Smith”。

在我的自定义报告中,我想打印出客户公司的名称。所以,我打电话给<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(即没有人)
  • The Client Ltd,约翰·史密斯。

结果

N <span t-field="o.partner_id.name"/>
id <span t-field="o.partner_id"/>

如下:

个人:

  • N:个人
  • id:个人

客户有限公司(无人员):

  • N:客户有限公司
  • id:客户有限公司

客户有限公司,约翰·史密斯:

  • N:约翰·史密斯
  • id:The Client Ltd, John Smith

我怎样才能确保报价总是发给客户,而不是我自己的公司?

【问题讨论】:

    标签: odoo qweb odoo-13


    【解决方案1】:

    我找到了答案。诀窍是查看父母是否存在,然后才使用 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 2021-05-07
      • 2020-01-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多