Skip to Content

Welcome!

Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

Sign up

You need to be registered to interact with the community.
This question has been flagged
1 Reply
58 Views

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

Avatar
Discard

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!

Avatar
Discard

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!