Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

show existing products of a customer in a tab

By
nahian
on 2/22/16, 3:28 AM 453 views

I am new in python, I've added a drop-down field so I can select a customer and seen his/her existing products in a tab.
but I cant show the list of existing products of a customer, how can I do it, can anyone help me please.

1

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 2/22/16, 7:18 AM

Hi,

One option is to create a One2many compute field on res.partner model and call that on a tab in customer form view. So when you open the customer form, under a "Products" tab, you may see the existing products of the customer. You may check the tutorial on how to create a One2many compute or functional field. Or else you may contact me on akhilpsivan01@gmail.com for further help.

For example, you may try by adding the following code:

in your .py file:

class project_task(models.Model):

_inherit = "project.task"

customer = fields.Many2one('res.partner', string="Search Customer Name")

products = fields.One2many('product.template', compute='_get_products', string="Products")

 

@api.one

@api.depends('customer')

def _get_products(self):

if self.customer:

product_list = self.env['product.supplierinfo'].search([('name.id','=',self.customer.id)])

if product_list:

p_list = []

for supp in product_list:

p_list.append(supp.product_tmpl_id.id)

prod = self.env['product.template'].browse(p_list)

self.products = prod

in your xml file:

<record id="view_task_form2_inherited" model="ir.ui.view">

<field name="name">project.task.form.inherited</field>

<field name="model">project.task</field>

<field name="inherit_id" ref="project.view_task_form2"/>

<field name="arch" type="xml">

<field name="reviewer_id" position="after">

<field name="customer" />

</field>

<notebook position="inside">

<page string="Products">

<field name="products" />

</page>

</notebook>

</field>

</record>

thank you Akhil for the code, but by this, I get product list of supplier but I need customers products, i.e when I select customer 'A' then his bought products will show in a tab.

nahian
on 3/3/16, 2:37 AM

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!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/22/16, 3:28 AM
Seen: 453 times
Last updated: 3/5/16, 1:37 PM