Hi,

the products field in model product.template[1] has per default a
hard coded::

    mode="form,tree"

which displays the first product in a one2many form instead of the
usual list.
This default greatly helps to ease the understanding of product (aka
variant) and templates for setups using simple products without
variants.

But for setups using variants, it seems better to have a::

    mode="tree,form"

which shows all products (variants) in a list of the product template
form.

I think about if it is a good general pattern for the appearance of a
one2many field in a form view:

    * if it has more than one entry, show initially a list
    * otherwise show initially a form

What do you think? For product and variant it would fit perfect IMHO,
since even if a setup uses variants, there can also be products without.

As the view_attribute[2] is already used to set *spell* and *state*
PYSON encoded conditions for attributes defined in the XML, I tried to
implement on this base.

But the following code (in version 4.0), but it doesn't work,  
the view_attribute[2] does not *dynamically* set the 
*mode*[3] attribute::


    class Template:
        __metaclass__ = PoolMeta
        __name__ = "product.template"


        @classmethod
        def view_attributes(cls):
            res = super(Template, cls).view_attributes()

            res.append((
                "/form/notebook/page[@id='general']/field[@name='products']",
                'mode',
                If(Greater(Len(Eval('products')), 1),
                'tree,form', 'form,tree')
            ))
            return res

Are there any ideas how it could work? What is missing?

TIA and regards
Udo Spallek

[1]
http://hg.tryton.org/modules/product/file/tip/view/template_form.xml#l29
[2]
http://doc.tryton.org/4.8/trytond/doc/ref/models/models.html?highlight=view_attribute#trytond.model.ModelView.view_attributes
[3] http://doc.tryton.org/4.8/trytond/doc/topics/views/index.html#field
-- 
virtual things
Preisler & Spallek GbR

Windeckstr. 77
81375 München

Tel: +49 (89) 710 481 55
i...@virtual-things.biz
https://www.virtual-things.biz

-- 
You received this message because you are subscribed to the Google Groups 
"tryton-dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton-dev/20180424175308.2e2eb9b2%40bender.fritz.box.

Attachment: pgphk2M81HoVj.pgp
Description: Digitale Signatur von OpenPGP

Reply via email to