Skip to Content
Menu
This question has been flagged
2 Replies
1090 Views

I need to show only the related products on the order line. How??

from odoo import models, fields, api

class SaleOrder(models.Model):
    _inherit = 'sale.order'
    order_type_id = fields.Many2one('sales.order.type', string='Order Type')

    @api.depends('order_type_id')
    def _compute_product_domain(self):
        for order in self:
            if order.order_type_id:
                order.product_id_domain = order.order_type_id.product_ids.ids
            else:
                order.product_id_domain = []
 # Kosongkan jika tidak ada order type
from odoo import models, fields

class SalesOrderType(models.Model):
    _name = 'sales.order.type'
    _description = 'Sales Order Type'
    name = fields.Char(string='Type Name', required=True)
    product_ids = fields.Many2many('product.product', string='Related Products')
from odoo import models, fields

class ProductProduct(models.Model):
    _inherit = 'product.product'
    order_type_ids = fields.Many2many('sales.order.type', string='Order Types')
Avatar
Discard
Best Answer

Hi, you can inherit the sale order view and add a domain on the product field using XPath. Let me know if you need any further assistance.

Thank you

Avatar
Discard
Author

Im sorry, but is it possible to make all of the non-related products disappear?

Best Answer

You need to apply a domain on the product field using XPath.

[('order_type_ids', '=', parent.order_type_id)]

Avatar
Discard
Related Posts Replies Views Activity
0
Sep 24
1101
3
Jun 16
6095
1
Sep 24
41
3
May 24
1785
1
Jan 23
6641