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.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
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.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up