Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
1271 Widoki

I have a page inside notebook which is "Product Info". Inside this page, I have added two fields : product_id, product_image. So whenever I select a product, it will automatically show relevant image of that product.I want to this product_id field as a one2many relation type with product.product alongside with product_image and attachment file field similar like order_line so that I can select as much product as I want. I have gotten the structure. But now, its not showing my existing product but want me to create new one which I dont want. I want to select my existing product. If I need to create one, i will do it in product.product model as usual rule. Can anyone suggest me what I need to do?

here my code:

.py:

from odoo import models, fields, api

class CrmLead(models.Model):

_inherit = 'crm.lead'

product_ids = fields.One2many('product.product', 'crm_lead_id', string='Products')

class ProductProduct(models.Model):

_inherit = 'product.product'

crm_lead_id = fields.Many2one('crm.lead', string='CRM Lead')

product_image = fields.Binary(string='Product Image')

 

.xml:

techtrioz.crm.lead.form.inherit

crm.lead



Any suggestion, what to do?




Any suggestion, what to do?



Awatar
Odrzuć
Najlepsza odpowiedź

To enable the selection of existing products within your product_ids field, consider changing its type in the CrmLead model to Many2many instead of One2many . This adjustment should allow you to directly choose multiple existing products. Here's the suggested code: 

product_ids = fields.Many2many( 'product.product' , 'crm_lead_product_rel' , string= 'Products' ) 

Ensure that your view form for CrmLead is appropriately configured to display the product_ids field, and confirm there are existing products in the database. If the issue persists, feel free to share additional details for further assistance.

Awatar
Odrzuć
Autor

Thank you so much. Here, whenever I try to select a product from add line that I made previously, another short page pop up. But I want to select products inside line just like order_line . What I need to do here?
here my code:
.py:
from odoo import models, fields, api

class CrmLead(models.Model):
_inherit = 'crm.lead'

product_ids = fields.Many2many('product.product', string='Products', edit="inline")
combined_info = fields.Char(string='Product Info', compute='_compute_combined_info')
def _compute_combined_info(self):
for product in self:
product.combined_info = f"{product.default_code} - {product.name}"
from odoo import models, fields, api

class ProductImage(models.Model):
_inherit = 'product.product'
_description = 'Product Image'

product_image = fields.Binary(string='Design')
combined_info = fields.Char(string='Product Info', compute='_compute_combined_info')

def _compute_combined_info(self):
for product in self:
product.combined_info = f"{product.default_code} - {product.name}"

.xml:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="wise_crm_lead_view_form_inherit" model="ir.ui.view">
<field name="name">techtrioz.crm.lead.form.inherit</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_lead_view_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='internal_notes']" position='after'>
<page string="Product Info" name="product_info">
<tree position="inside" editable="bottom">
<field name="product_ids" widget="one2many_list">
<tree>
<!-- <field name="default_code" string="Products"/> -->
<field name="combined_info" string="Product Info"/>
<field name="product_image" widget="image" options='{"size": [80, 80]}'/>
</tree>
</field>
</tree>
</page>
</xpath>
</field>
</record>
</odoo>

Najlepsza odpowiedź

Please change the name of one2many with prefix before product_ids. It maybe works.

Awatar
Odrzuć
Autor

It worked. Thank you

Powiązane posty Odpowiedzi Widoki Czynność
1
sty 24
1150
1
sty 24
1432
1
sty 24
1238
2
sie 25
1267
0
maj 25
676