2014-04-10 11:58 GMT+02:00 Cédric Krier <[email protected]>:

> On 09 Apr 05:29, jmartin wrote:
> > 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_sale.party', 'product'],
>                    # Fixed
> >
> depends=['_parent_sale.party']),
> # Fixed
> >         '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?
>
> So I guess the product_domain is not correctly filled by the on_change.
> You should check the value of this field in the UI.
>

Sorry. I don't know how to do that. -_-'

Anyway. I can see in my Eclipse development environment that the method
on_change_with_product_domain() is not called when I change the party of
the sale.sale. It is only called when I save the sale.sale record.

Note. I fixed the code as I shown above.


>
> --
> Cédric Krier - B2CK SPRL
> Email/Jabber: [email protected]
> Tel: +32 472 54 46 59
> Website: http://www.b2ck.com/
>



-- 

Jesús Martín

Zikzakmedia SL
Dr. Fleming, 28, baixos
08720 Vilafranca del Penedès
☏ 93 890 21 08

Reply via email to