Skip to Content
Menu
This question has been flagged

When searching for products in Purchase Order Line, the search window is showing "[Supplier Product code] Supplier Product name" (if existing), instead of "[Internal Reference] Product Name".


Is it possible to make the search window for Purchase Order Lines to always show "[Internal Reference] Product Name", even though there are data in "Supplier Product code" and "Supplier Product name"?


Thanks,

Rickard

Avatar
Discard
Best Answer

Hello Rickard Wallster,

On Purchase Order Line, Product search window If you want to display "[Internal Reference] Product Name" instead of the "[Supplier Product code] Supplier Product name". Then you need to overwrite the base product.product 'name_get' method and you need to remove If/else condition for the seller. I have modified the below method as per your requirement you can use this method.

Please inherit product.product object in any custom module and you can add the below method.
Note: Below method was copy from odoo v12.

@api.multi
def name_get(self):
# TDE: this could be cleaned a bit I think

def _name_get(d):
name = d.get('name', '')
code = self._context.get('display_default_code', True) and d.get('default_code', False) or False
if code:
name = '[%s] %s' % (code,name)
return (d['id'], name)

partner_id = self._context.get('partner_id')
if partner_id:
partner_ids = [partner_id, self.env['res.partner'].browse(partner_id).commercial_partner_id.id]
else:
partner_ids = []

# all user don't have access to seller and partner
# check access and use superuser
self.check_access_rights("read")
self.check_access_rule("read")

result = []

# Prefetch the fields used by the `name_get`, so `browse` doesn't fetch other fields
# Use `load=False` to not call `name_get` for the `product_tmpl_id`
self.sudo().read(['name', 'default_code', 'product_tmpl_id', 'attribute_value_ids', 'attribute_line_ids'], load=False)

product_template_ids = self.sudo().mapped('product_tmpl_id').ids

if partner_ids:
supplier_info = self.env['product.supplierinfo'].sudo().search([
('product_tmpl_id', 'in', product_template_ids),
('name', 'in', partner_ids),
])
# Prefetch the fields used by the `name_get`, so `browse` doesn't fetch other fields
# Use `load=False` to not call `name_get` for the `product_tmpl_id` and `product_id`
supplier_info.sudo().read(['product_tmpl_id', 'product_id', 'product_name', 'product_code'], load=False)
supplier_info_by_template = {}
for r in supplier_info:
supplier_info_by_template.setdefault(r.product_tmpl_id, []).append(r)
for product in self.sudo():
# display only the attributes with multiple possible values on the template
variable_attributes = product.attribute_line_ids.filtered(lambda l: len(l.value_ids) > 1).mapped('attribute_id')
variant = product.attribute_value_ids._variant_name(variable_attributes)

name = variant and "%s (%s)" % (product.name, variant) or product.name
sellers = []
if partner_ids:
product_supplier_info = supplier_info_by_template.get(product.product_tmpl_id, [])
sellers = [x for x in product_supplier_info if x.product_id and x.product_id == product]
if not sellers:
sellers = [x for x in product_supplier_info if not x.product_id]

mydict = {
'id': product.id,
'name': name,
'default_code': product.default_code,
}
result.append(_name_get(mydict))
return result

Hope this may help you!

Thanks & Regards,

Email: odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

Avatar
Discard
Author

Thanks Jainesh.

So far I have only made customisations using Studio and Odoo interface developer mode, since I don't have access to the server yet. I was hoping this was achievable by creating a custom view or so, but I will try your solution later on when I have access to the server.

Author Best Answer

Hi Racheal

I have tried different workarounds so now I don't really know what was the baseline. But you can try out the following:
1. Open a Purchase Order.
2. Using Studio, click on the PO lines. Edit List View.
3. Click on Product column. Remove all data in Context.

I hope that works out for you.

In later versions it seems like they removed this weird behaviour.


 

Avatar
Discard
Best Answer

You can remove the "[Supplier Product code]" Prefix by setting "display_default_code" to False in the context, e.g.



{'partner_id': parent.partner_id, 'display_default_code': False}

Avatar
Discard
Author

Hi Felix
I appreciate your help. But the solution you suggested will remove "default_code". What I want to do is to show default_code, even though there is data in product_code for that vendor.

I tried context {'partner_id': parent.partner_id, 'display_product_code': False} instead. But that didn't work.

Hi Rickard,
I am running into the same issue.  I would only like the Internal Reference displayed.  Were you able to come up with a solution using Studio?

Related Posts Replies Views Activity
1
Feb 18
10921
1
Jan 23
1263
1
Oct 20
5009
1
Aug 19
5134
1
Jan 19
4673