Ossi Mantylahti
Ossi Mantylahti

Reputation: 68

Odoo QWeb: refering to customer company

When creating a custom Odoo Sales / Quote report, how do I refer always to the customer company in Qweb code?

In Odoo the data model has Companies and Persons. Persons can be linked to the companies. Let's have an example: my Odoo company is called My Company. We have registered a client The Client Ltd. And a person John Smith has been registered as a representative for The Client Ltd.

Now, to to create a quote for The Client the salespersons of My Company can send the documents to either "The Client Ltd" or "The Client Ltd, John Smith".

In my custom report I'd like to print out the name of the client company. So, I call <span t-field="o.partner_id.name"/>. This works if the quote is issued to the company. But if the quote is issued to "The Client Ltd, John Smith", the output is just "John Smith".

I've tried refering to the client company with <span t-field="o.partner_id.parent_id.name"/> and it works as long as all quotes are issued to persons registered with a company, like "The Company Ltd, John Smith". But... as soon as there is one quote issued to a company without a dedicated person, the <span t-field="o.partner_id.parent_id.name"/> evaluates to "My Company" which is obviously wrong.

Tried also with couple of cases. Trying to sell to:

Results with

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

are following:

Individual Person:

The client Ltd (without person):

The client ltd, John Smith:

How can I ensure that the offers are always issued to clients, not to my own company?

Upvotes: 0

Views: 163

Answers (1)

Ossi Mantylahti
Ossi Mantylahti

Reputation: 68

I found an answer. The trick is to see if a parent exists and only then use partner_id.parent_id. If parent_id does not exist, an attempt to refer to it overflows to Odoo company's name.

So the QWeb report requires just one simple if-then-else. Here is the code block:

    <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>

Upvotes: 0

Related Questions