تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
1117 أدوات العرض

How can I create a table under a vendor/contact that shows a list of products associated with that vendor? I'd like to be able to open up a contact and see all of the products that have that contact set as the vendor, but I'm not sure how to do this. I'm guessing it's a many2one relationship?

الصورة الرمزية
إهمال
أفضل إجابة

I am new here and would like to know on how to go about creating this report. Does anyone have step by step instructions or video? Thank you. 

الصورة الرمزية
إهمال
أفضل إجابة

Hi,

You can try this code:


from odoo import models, fields, api

class ProductVendor(models.Model):
_name = 'custom_module.product_vendor'
_description = 'Product Vendor Relationship'

product_id = fields.Many2one('product.product', string='Product')
vendor_id = fields.Many2one('res.partner', string='Vendor')



Add a Many2many field to link contacts to products in models.py:

from odoo import models, fields, api

class ResPartner(models.Model):
_inherit = 'res.partner'

product_ids = fields.Many2many('product.product', 'custom_module_product_vendor', 'vendor_id', 'product_id', string='Products')



Create a file views/res_partner_views.xml:

<odoo>
    <data>
        <record id="view_res_partner_form_inherit" model="ir.ui.view">
            <field name="name">res.partner.form.inherit</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_form"/>
            <field name="arch" type="xml">
                <xpath expr="//page[@name='contacts']/group[@name='contact']/field[@name='function']" position="after">
                    <field name="product_ids" widget="many2many_tags" options="{'no_create': True}" context="{'default_vendor_id': id}"/>
                </xpath>
            </field>
        </record>
    </data>
</odoo>


Hope it helps

الصورة الرمزية
إهمال
الكاتب

Thanks for the reply! I'm new to Odoo and am not sure where I would go to try the code. Can you provide a more detailed explanation of where to do that at?