Blank field in report if not printed by Admin user (cannot print from a duplicate user of admin either)

Asked by Damiano

Hi all,
I have a sales report that includes some bank information.

If the pdt document is printed by the admin user it displays correctly all fields, if it's printed with any other user, EVEN A DUPLICATE OF THE ADMIN USER (so with exactly the same privileges), those fields are blank on the pdf (all other fields are correctly displayed).

I am currently using OE 6.0.3

In the .py file:

    def _get_supplier(self,o):
        supplier=pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr,self.uid,self.uid).name
        partner_obj=pooler.get_pool(self.cr.dbname).get('res.partner').browse(self.cr,self.uid,self.uid)
        benef=partner_obj.bank_ids[0].owner_name
        return {'supplier':supplier,
                'benef':benef,
               }

In the rml file:

       <td>
           <para style="times_roman_9_left">[[ get_supplier(o) ['benef'] ]]</para>
       </td>
    </tr>

Why is this happening? Please help

Question information

Language:
English Edit question
Status:
Answered
For:
Odoo Addons (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:

This question was reopened

Revision history for this message
Serpent Consulting Services (serpent-consulting-services) said :
#1

Damiano,

I guess you are trying to get the name of the bank of the partner of USER's Company.

Ok, Lets just uncomplicate.

The actual problem resides within your code.

CODE: supplier=pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr,self.uid,self.uiduld ).name
Note : You should never pass like this. It should be " .browse(self.cr,self.uid, WHATEVER ID) but NEVER self.UID.

Same happens with partner_obj=pooler.get_pool(self.cr.dbname).get('res.partner').browse(self.cr,self.uid,self.uid)

When an admin user prints the report, his ID is 1 and your company is also 1, so things go smoothly.

When any other prints it, his ID is 2 and you pass self.uid as an ID of company, but there is no company with ID 2 and hence all the mess happens.

Correcting this part of code will suffice your need.

Regards,
Serpent Consulting Services,
http://www.serpentcs.com

Revision history for this message
Damiano (damiano-f) said :
#2

Hi, thanks for your feedback, but It is still not working.

I did:
partner_obj=pooler.get_pool(self.cr.dbname).get('res.partner').browse(self.cr,self.uid, [1])

Actually this is a sales order, and the goal is to display the bank according to the shop.
There are 2 shops (each with it's company), and i'd need to dynamically change it according to the company:

To recap:
company 1

Revision history for this message
Damiano (damiano-f) said :
#3

To recap:
company 1 shop 1
company 2 shop 2

Can you please explain me the meaning of browse(self.cr,self.uid, [1])
Thanks

Revision history for this message
digitalsatori(Shine IT) (digitalsatori) said :
#4

Hi Damiano,

You confused a few things. I will try to make it clear for you.
The purpose of pool.get('object.name') is to get particular object service(osv), which is an instance of a class with 'object.name' as the value of _name class attribute (or a class inherit from such mentioned class). With the help of ORM, you are able to do create, ulink, write, search, browse, etc. etc. method calls and the result will represents in the database table(normally named 'object_name') as they are binded.

for your particular question: Can you please explain me the meaning of browse(self.cr,self.uid, [1])
that browse method is to make "Resource" with provided ids browse objects, which are like normal python object, so that you can access all the field value easily through attribute access. eg.
to get bank info through shop (it is not a good example because in generic OpenERP there will not show company id unless you install multi-company module)
self.pool.get('sale.shop').browse(cr, uid, SHOP_ID).company_id.bank_ids[0].owner_name

Hopefully this information is useful for you

Tony Gu

Can you help with this problem?

Provide an answer of your own, or ask Damiano for more information if necessary.

To post a message you must log in.