Skip to Content
Menu
This question has been flagged
7 Replies
4059 Views

Dear all.

I hope everyone safe.

On Odoo, when we issue a supplier bill, we can see the VAT number right next to supplier name (suppler_name - vat_number on partner_id field), when we're choosing the supplier from the partner_id field.

I need to achieve the same effect on customer invoices.

So, when user clicks on the partner_id many2one field, I need to show "Customer Name - VAT_NUMBER".

I look into the supplier bill xml and found:

<group modifier = {}>...
<field string="Supplier" 
                name="partner_id" 
                widget="res_partner_many2one" 
                context="{'default_customer': 0, 
                        'search_default_supplier': 1, 
                        'default_supplier': 1, 
                        'default_is_company': True, 
                        'show_vat': True}" 
                domain="[('supplier', '=', True)]" 
                on_change="1" 
                can_create="true" 
                can_write="true" 
                modifiers="{'readonly':[['state','not in',['draft']]]}"/>
...
</group>


On the customer invoice I have:

<field string="Customer" 
                name="partner_id" 
                widget="res_partner_many2one" 
                context="{'search_default_customer':1, 
                        'show_address': 1, 
                        'default_is_company': True, 
                        'show_vat': True}" 
                options="{&quot;always_reload&quot;: True, 
                &quot;no_quick_create&quot;: True}" 
                domain="[('customer', '=', True)]" 
                required="1"/>
...


I cannot find any option, widget or field that allows me to achieve the same effect.

Looking for both codes, I thought the "show_vat" did the trick but it's already selected for the customer invoices and I cannot get the same effect.

Can anyone help me please?

Thank you all very much and keep safe

PM

UPDATE: I need do show the VAT number on the partner_id field itself when user is selecting the customer.


UPDATE II: Please refer to this image: https://ibb.co/567p81x

Avatar
Discard
Best Answer

Hi Paulo:

The value is displayed provided both of the following conditions are true:

  1. show_vat = True

  2. partner.vat has a value in it

Check to make sure the VAT field for that Partner has a value in it.

EDIT:

The context definition on the Invoice form has a parameter 'show_address' in it which causes the api to return the name + address + vat.

context="{'search_default_customer':1, 'show_address': 1, 'default_is_company': True, 'show_vat': True}"

If you customize the view and remove the 'show_address' parameter like so, you get the same result as on the Vendor Bill.

<xpath expr="//field[@name='partner_id']" position="attributes">
    <attribute name="context">{'search_default_customer':1, 'default_is_company': True, 'show_vat': True}</attribute>
</xpath>

NOTE: This will cause the address to be no longer displayed on the form. Only the name + vat will be displayed.


Screenshot of Invoice form with customized context on partner_id.


Avatar
Discard
Author

Thank you Paresh,

I think you correctly understood my question. I am referring to the VAT number shown on the partner_id field when we are choosing a supplier from the list, when issuing a new supplier bill.

If supplier has a VAT number, Odoo shows on partner_id many2one selection list:"Partner Name - VAT Number".

The same does not happens to customer invoices, and I need to achieve the same result.

Customer has a VAT number associated to his account.

Regards

I have edited and added a screenshot to my earlier post. Taking care of the 2 things mentioned above works fine with the default out of the box functionality. Check whether some customization has been done at your site.

Author

Paresh,

Thank you once again.

My English is not very good a perhaps I did not explain myself correctly. Please refer to the following image link for you to see what I need to achieve: https://ibb.co/567p81x

Regards

Hi Paulo: I have updated the EDIT section in my earlier response based on your clarification.

Author

Great Paresh,

It's working as expected. Thank you very much.

Best regards

PM

Best Answer

Check partner python file name_get method, using this method can append two fields  and show in many2one dropdown list.

Edit,

https://github.com/odoo/odoo/blob/13.0/odoo/addons/base/models/res_partner.py

Check _get_name method line no 657

if self._context.get('show_vat') and partner.vat:
name = "%s ‒ %s" % (name, partner.vat)
return name

def name_get(self):
res = []

for partner in self:

name = partner._get_name()

res.append((partner.id, name))
return res

The above code appending customer and vat number in many2one list.

check context set and get value. You can debug the above code

to check supplier bill form the above vat if statement is executed or not.





Avatar
Discard
Author

Dear Prakash,

I am using Odoo 12 and the core code for /base/models/res_partner.py is exactly as you described on your code sample.

Anyway, the same code is shared by both customer/supplier and the approach I need is working fine for supplier on core Odoo, and not for the customer.

I think it's something else and not this specific code.

Thank you very much

Related Posts Replies Views Activity
0
Feb 22
1114
6
Aug 19
8545
1
Feb 24
765
0
Feb 24
291
2
Sep 22
2566