Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
881 Vizualizări

Hello everyone,

I'm using Odoo online 16.

When I create a PO an choose a vendor to purchase from, I need their products only to be shown on the product drop-down list; to prevent mixing their products with other vendors.


How can I do this? Thanks in advance.

Imagine profil
Abandonează

With this change you can no longer order generic products such as office supplies, janitorial supplies, warehouse packaging supplies, consumable computer supplies, etc.

Most of the time, this change is requested because there is a perception people will order the wrong things from the wrong Vendor but in reality it rarely happens.

The Vendor will tell you straight away "we don't sell that".

Cel mai bun răspuns

It's possible to make a small change to the XML (you can start it in Odoo Studio but this type of domain is not supported so you have to edit the XML for the extension view):

<data>
  <xpath expr="//field[@name='product_template_id']" position="attributes">
    <attribute name="domain">[('seller_ids.partner_id','=',parent.partner_id),('purchase_ok', '=', True)]</attribute>
  </xpath>
</data> 


Imagine profil
Abandonează
Cel mai bun răspuns

Using Odoo Studio:


1. Create a new 'Many2many' field (related to 'product.product') on the Purchase Order model.

   * Name it like vendor_products.

   * Set it as computed, with a dependency on 'partner_id'.

   * In the compute method, search for products where the selected vendor ('partner_id') is listed in the product's vendor list ('seller_ids').

   * Mark this field as invisible on the form.


2. Add a domain to the product field in the Purchase Order Line model.


     [('id', 'in', parent.vendor_products)]


Let me know if you'd like a demo feel free to contact me via WhatsApp at 7538824350 or send me a DM.

Imagine profil
Abandonează
Cel mai bun răspuns

Hi,

Please refer to the code:



from odoo import api, fields, models

class PurchaseOrderLine(models.Model):

    _inherit = "purchase.order.line"


    product_ids = fields.Many2many(

        'product.product',

        string="Allowed Products",

        compute="_compute_product_ids",

        store=False,

    )


    product_id = fields.Many2one(

        'product.product',

        string="Product",

        domain="[('id', 'in', product_ids)]",

    )


    @api.depends('order_id.partner_id')

    def _compute_product_ids(self):

        for line in self:

            if line.order_id.partner_id:

                products = self.env['product.product'].search([

                    ('purchase_ok', '=', True),

                    ('seller_ids.partner_id', '=', line.order_id.partner_id.id)

                ])

                line.product_ids = products

            else:

                line.product_ids = False


Hope it helps.

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
3
aug. 25
1261
1
iul. 25
1135
1
iul. 25
1421
1
iul. 25
1849
0
iul. 25
940