Hi,

I'm trying to add a domain in the product field os sale.line that is filled 
from the sale.sale form view, in order to avoid make sales of some products 
grouped by their categories to some parties. This is the code:

class SaleLine:
    __name__ = 'sale.line'
    product_domain = fields.Function(fields.One2Many(
            'product.product', None, 'Product Category Domain',
            on_change_with=['_parent_party', 'product'],
            depends=['_parent_party']),
        'on_change_with_product_domain')

    @classmethod
    def __setup__(cls):
        super(SaleLine, cls).__setup__()
        product_domain = ('id', 'not in', Eval('product_domain', []))
        if product_domain not in cls.product.domain:
            cls.product.domain.append(product_domain)

    def on_change_with_product_domain(self, name=None):
        pool = Pool()
        ProductCategory = pool.get('party.party-product.category')
        Template = pool.get('product.template')
        party = self.sale.party
        product_categories = ProductCategory.search([('party', '=', party)])
        products = []
        for product_category in product_categories:
            templates = Template.search([
                    ('category', '=', product_category.category)])
            for template in templates:
                for product in template.products:
                    products.append(product.id)
        return products

* In other file there is defined the m2m record that relates party with 
product.category

The module avoids that a product will be sold to the customer if the 
product belongs to any of the categories listed for this customer. But it 
does this in a strange way. I can select all products of the list in the 
sale.line record, and when I'm going to save the sale.sale record, tryton 
says me that the field product of sale.line is not correct accordingly with 
its domain. I would like that products which I can not sell to the 
customer, will be excluded from those I can select, but how can I do that?






Reply via email to