How to find default company of the logged in user

Hi All,

frappe.defaults.get_user_default("company") always seems to return default company for the site and not the default company of the logged in user. How do I get default company of the logged in user? I am trying to set default value for a report filter based on the logged in user's default company.

    <td id="LC14" class="blob-line-code js-file-line">			<span class="s2">"fieldname"</span><span class="o">:</span><span class="s2">"company"</span><span class="p">,</span></td>
  </tr>
  <tr>
    
    <td id="LC15" class="blob-line-code js-file-line">			<span class="s2">"label"</span><span class="o">:</span> <span class="s2">"Company"</span><span class="p">,</span></td>
  </tr>
  <tr>
    
    <td id="LC16" class="blob-line-code js-file-line">			<span class="s2">"fieldtype"</span><span class="o">:</span> <span class="s2">"Link"</span><span class="p">,</span></td>
  </tr>
  <tr>
    
    <td id="LC17" class="blob-line-code js-file-line">			<span class="s2">"options"</span><span class="o">:</span> <span class="s2">"Company"</span><span class="p">,</span></td>
  </tr>
  <tr>
    
    <td id="LC18" class="blob-line-code js-file-line">			<span class="s2">"default"</span><span class="o">:</span><span class="nx">frappe</span><span class="p">.</span><span class="nx">defaults</span><span class="p">.</span><span class="nx">get_user_default</span><span class="p">(</span><span class="s2">"company"</span><span class="p">)&nbsp; <br></span></td>
  </tr>
  <tr>
    
    <td id="LC19" class="blob-line-code js-file-line">		<span class="p">},</span></td></tr></tbody></table><br><br><br>Kind regards,<br>Mayur Patel<br></div>



Note:

 

If you are posting an issue,

 

  1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
  2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/11e0d574-71d5-4d7e-a7f1-c01254adc394%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.
{
It should get the users default. Maybe it's not set / there are multiple defaults.

@rushabh_mehta
via mobile

On 22-Aug-2014, at 7:28 PM, MP <ma...@gmail.com> wrote:

Hi All,

frappe.defaults.get_user_default("company") always seems to return default company for the site and not the default company of the logged in user. How do I get default company of the logged in user? I am trying to set default value for a report filter based on the logged in user's default company.

    <td id="LC14" class="blob-line-code js-file-line">			<span class="s2">"fieldname"</span><span class="o">:</span><span class="s2">"company"</span><span class="p">,</span></td>
  </tr>
  <tr>
    
    <td id="LC15" class="blob-line-code js-file-line">			<span class="s2">"label"</span><span class="o">:</span> <span class="s2">"Company"</span><span class="p">,</span></td>
  </tr>
  <tr>
    
    <td id="LC16" class="blob-line-code js-file-line">			<span class="s2">"fieldtype"</span><span class="o">:</span> <span class="s2">"Link"</span><span class="p">,</span></td>
  </tr>
  <tr>
    
    <td id="LC17" class="blob-line-code js-file-line">			<span class="s2">"options"</span><span class="o">:</span> <span class="s2">"Company"</span><span class="p">,</span></td>
  </tr>
  <tr>
    
    <td id="LC18" class="blob-line-code js-file-line">			<span class="s2">"default"</span><span class="o">:</span><span class="nx">frappe</span><span class="p">.</span><span class="nx">defaults</span><span class="p">.</span><span class="nx">get_user_default</span><span class="p">(</span><span class="s2">"company"</span><span class="p">)&nbsp; <br></span></td>
  </tr>
  <tr>
    
    <td id="LC19" class="blob-line-code js-file-line">		<span class="p">},</span></td></tr></tbody></table><br><br><br>Kind regards,<br>Mayur Patel<br></div>



Note:

 

If you are posting an issue,

 

  1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
  2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/11e0d574-71d5-4d7e-a7f1-c01254adc394%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.



Note:

 

If you are posting an issue,

 

  1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
  2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/DE3B9E23-E828-41EB-8C38-057BBD5BE609%40gmail.com.

    For more options, visit https://groups.google.com/d/optout.
{
The fault lies with the new permissions system which replaced the user defaults. User permissions are based on doctype names and not field names. 

@rushabh Let's discuss this on Monday. 

Sent from my phone

On 23-Aug-2014, at 9:35, Rushabh Mehta <rm...@gmail.com> wrote:

It should get the users default. Maybe it's not set / there are multiple defaults.

@rushabh_mehta
via mobile

On 22-Aug-2014, at 7:28 PM, MP <ma...@gmail.com> wrote:

Hi All,

frappe.defaults.get_user_default("company") always seems to return default company for the site and not the default company of the logged in user. How do I get default company of the logged in user? I am trying to set default value for a report filter based on the logged in user's default company.

    <td id="LC14" class="blob-line-code js-file-line">			<span class="s2">"fieldname"</span><span class="o">:</span><span class="s2">"company"</span><span class="p">,</span></td>
  </tr>
  <tr>
    
    <td id="LC15" class="blob-line-code js-file-line">			<span class="s2">"label"</span><span class="o">:</span> <span class="s2">"Company"</span><span class="p">,</span></td>
  </tr>
  <tr>
    
    <td id="LC16" class="blob-line-code js-file-line">			<span class="s2">"fieldtype"</span><span class="o">:</span> <span class="s2">"Link"</span><span class="p">,</span></td>
  </tr>
  <tr>
    
    <td id="LC17" class="blob-line-code js-file-line">			<span class="s2">"options"</span><span class="o">:</span> <span class="s2">"Company"</span><span class="p">,</span></td>
  </tr>
  <tr>
    
    <td id="LC18" class="blob-line-code js-file-line">			<span class="s2">"default"</span><span class="o">:</span><span class="nx">frappe</span><span class="p">.</span><span class="nx">defaults</span><span class="p">.</span><span class="nx">get_user_default</span><span class="p">(</span><span class="s2">"company"</span><span class="p">)&nbsp; <br></span></td>
  </tr>
  <tr>
    
    <td id="LC19" class="blob-line-code js-file-line">		<span class="p">},</span></td></tr></tbody></table><br><br><br>Kind regards,<br>Mayur Patel<br></div>



Note:

 

If you are posting an issue,

 

  1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
  2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/11e0d574-71d5-4d7e-a7f1-c01254adc394%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.



Note:

 

If you are posting an issue,

 

  1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
  2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/DE3B9E23-E828-41EB-8C38-057BBD5BE609%40gmail.com.

    For more options, visit https://groups.google.com/d/optout.



Note:

 

If you are posting an issue,

 

  1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
  2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/3EA900A7-647D-4340-8FFD-A0A1A792851E%40iwebnotes.com.

    For more options, visit https://groups.google.com/d/optout.
{

On 23-Aug-2014, at 1:16 pm, Anand Doshi <an...@iwebnotes.com> wrote:

The fault lies with the new permissions system which replaced the user defaults. User permissions are based on doctype names and not field names. 

@rushabh Let's discuss this on Monday. 

Cool - but then didn't we set the defaults based on DocTypes (?) - if not, thats an easy fix.


Sent from my phone

On 23-Aug-2014, at 9:35, Rushabh Mehta <rm...@gmail.com> wrote:

It should get the users default. Maybe it's not set / there are multiple defaults.

@rushabh_mehta
via mobile

On 22-Aug-2014, at 7:28 PM, MP <ma...@gmail.com> wrote:

Hi All,

frappe.defaults.get_user_default("company") always seems to return default company for the site and not the default company of the logged in user. How do I get default company of the logged in user? I am trying to set default value for a report filter based on the logged in user's default company.

    <td id="LC14" class="blob-line-code js-file-line">			<span class="s2">"fieldname"</span><span class="o">:</span><span class="s2">"company"</span><span class="p">,</span></td>
  </tr>
  <tr>
    
    <td id="LC15" class="blob-line-code js-file-line">			<span class="s2">"label"</span><span class="o">:</span> <span class="s2">"Company"</span><span class="p">,</span></td>
  </tr>
  <tr>
    
    <td id="LC16" class="blob-line-code js-file-line">			<span class="s2">"fieldtype"</span><span class="o">:</span> <span class="s2">"Link"</span><span class="p">,</span></td>
  </tr>
  <tr>
    
    <td id="LC17" class="blob-line-code js-file-line">			<span class="s2">"options"</span><span class="o">:</span> <span class="s2">"Company"</span><span class="p">,</span></td>
  </tr>
  <tr>
    
    <td id="LC18" class="blob-line-code js-file-line">			<span class="s2">"default"</span><span class="o">:</span><span class="nx">frappe</span><span class="p">.</span><span class="nx">defaults</span><span class="p">.</span><span class="nx">get_user_default</span><span class="p">(</span><span class="s2">"company"</span><span class="p">)&nbsp; <br></span></td>
  </tr>
  <tr>
    
    <td id="LC19" class="blob-line-code js-file-line">		<span class="p">},</span></td></tr></tbody></table><br><br><br>Kind regards,<br>Mayur Patel<br></div><div><br class="webkit-block-placeholder"></div>



Note:

 

If you are posting an issue,

 

  1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
  2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/11e0d574-71d5-4d7e-a7f1-c01254adc394%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.



Note:

 

If you are posting an issue,

 

  1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
  2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/DE3B9E23-E828-41EB-8C38-057BBD5BE609%40gmail.com.

    For more options, visit https://groups.google.com/d/optout.



Note:

 

If you are posting an issue,

 

  1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
  2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/3EA900A7-647D-4340-8FFD-A0A1A792851E%40iwebnotes.com.

    For more options, visit https://groups.google.com/d/optout.



Note:

 

If you are posting an issue,

 

  1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
  2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/A93FAA31-352E-49C5-B41F-E2DDC79BEEDE%40gmail.com.

    For more options, visit https://groups.google.com/d/optout.
{
Hi Rushabh, Anand,

Is there further update on this?

Kind regards,
Mayur Patel



Note:

 

If you are posting an issue,

 

  1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
  2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/88709788-9cef-45dd-a766-1c475377cd48%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.
Hi Mayur,

For now, use frappe.defaults.get_user_default("Company") with capital "C".


-Anand.


On Tue, Aug 26, 2014 at 6:08 PM, MP <ma…@gmail.com> wrote:
Hi Rushabh, Anand,

Is there further update on this?

Kind regards,
Mayur Patel



Note:



If you are posting an issue,


  1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.

  2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.

  3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email

  4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.



    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/88709788-9cef-45dd-a766-1c475377cd48%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



Note:

 

If you are posting an issue,

 

  1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
  2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/CAAQzbF3YskwuWQXSbujcy8f5s7xjpxN-bNOaWci%3DeZUdvy7_Xg%40mail.gmail.com.

    For more options, visit https://groups.google.com/d/optout.
1 Like
Thanks Anand.

Kind regards,
Mayur Patel



Note:

 

If you are posting an issue,

 

  1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
  2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/e3d9aa24-59ab-482f-981a-ba8d47825514%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.
Actually, use:
frappe.defaults.get_user_default("Company") || frappe.defaults.get_global_default("company")


so that global default company is used as fallback!

-Anand.


On Tue, Sep 2, 2014 at 9:30 PM, MP <ma…@gmail.com> wrote:
Thanks Anand.

Kind regards,
Mayur Patel



Note:



If you are posting an issue,


  1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.

  2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.

  3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email

  4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.



    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/e3d9aa24-59ab-482f-981a-ba8d47825514%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



Note:

 

If you are posting an issue,

 

  1. ERPNext is a free and open source software and support is given on this forum by a team (https://frappe.io/webnotes). So please consider donating if you find this forum useful (https://frappe.io/buy). Even a small amount would be helpful.
  2. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  3. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  4. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/CAAQzbF0nf4jBtY3sM5FNY-gSag2WZSrsPkd8PRxn1zi01mT9bg%40mail.gmail.com.

    For more options, visit https://groups.google.com/d/optout.

@rushabh and @anand,

In our ERPNext instance we have 7 companies (2 new companies are going to be added soon for taxation purpose). I am employed by company B (in my employee record, the company is set as B). All my leave applications are added against company B. I am assigned to two companies (A and B) as part of User Permissions Manager so that I can create purchase order for both Company A and B. Please note there are about 23 users who has this kind of configuration.

In our custom report, we have a company filter. Ideally, we want to set company filter based on logged in user’s employee record. There is an issue with using “frappe.defaults.get_user_default(“Company”) || frappe.defaults.get_global_default(“company”)”. It always return the first record from user permissions manager for company doctype for the logged in user. So when I logged it set the company filter as Company A.

Is there a way to get the value for company field based on logged user’s employee record? Thanks.

Hi Mayur,

Have a look at this example: https://frappe.io/tutorial/form-client-scripting

You can use it to get the Employee record.

-Anand.

@anand
Thanks. I can see that using this script:

frappe.ui.form.on("Library Transaction", "library_member",
    function(frm) {
        frappe.call({
            "method": "frappe.client.get",
            args: {
                doctype: "Library Member",
                name: frm.doc.library_member
            },
            callback: function (data) {
                frappe.model.set_value(frm.doctype,
                    frm.docname, "member_name",
                    data.message.first_name
                    + (data.message.last_name ?
                        (" " + data.message.last_name) : ""))
            }
        })
    });

I should be able to get the employee’s company by passing user_id (frappe.user.name) as a filter. couple of questions:

  • Can I still pass frm as an argument to function? Please note this is for a custom report. It doesn’t have cur_frm.
  • Once I get the employee’s company value, how can I use it to set the company filter’s on the report page to this value?

Share the structure of your report so we can help you with the best solution (on a new thread)