Documentation for developers.... once again

as it was kindly explained to me that most of my messages should be here…

in terms of documentation, what’s missing, in my opinion, for newbie developers are code snippets. There are tons of them in the forum replies. It might be a good idea to organize them, perhaps with tags

for example.

#relatorio #invoice #first_line

<for each="i, line in enumerate(invoice.invoice_address.full_address.split('\n'))">
<if test="i==0">
FIRST LINE
</if>
</for>

OR

#relatorio #test #when

<choose>
<when test="o.total <= 100">
</when>
<otherwise>
</otherwise>
</choose>

OR

 #invoice #lines #count #line

class Invoice(metaclass=PoolMeta):
    'Invoice'
    __name__ = 'account.invoice'
    @property   
    def get_nbr_ligne (self):
        total=0
        for i in self.lines :
            total +=1
        return (total)  

OR

#invoice #product #code 

 class Invoice(metaclass=PoolMeta):
    'Invoice'
    __name__ = 'account.invoice'    
     
    @property   
    def get_nbr_ligne (self):
    for i in self.lines :
       if not i.product.code:

for many people, this can be an easy entry into the code and, above all, it exposes “recipes” that can help them understand. The “skilled" and “knowers” could comment on possible/desirable improvements and point out blind spots. and the ‘good’ snippets would have a ‘badge’ given by “senior” developers…

it would be much easier to understand than

Function.getter_with_context
    A boolean telling if the getter result depends on the context.
    If it does not depend, the getter is called without context and the result is stored in the transaction cache when readonly.
    The default value is True.

Of course when you have sufficient skills you needs that documentation, but when you start it seems to me to be too difficult

Could be simpler with:

 #invoice #lines #count #line

class Invoice(metaclass=PoolMeta):
    'Invoice'
    __name__ = 'account.invoice'

    @property   
    def report_total_lines(self):
        return len(self.lines)

    @property   
    def report_number_product_lines(self):
        return len([l for l in self.lines if l.product])

and pretty sure you could use this in your relatorio report:

len(invoice.lines)

The best documentation is the code himself and learning by trying to solve some (easy) issues (I learned a lot this way).

yes but you have to find where to look in the code.

when you have no clue you do not know where to look and what to look

I read a lot of code … it relly do not help much because perhaps i am too far for understanding the pythonic way, so snipets could be a good entry point. to give some start lines to deep further

Sometimes yes, otherwise I use this tool to search the code:

https://beyondgrep.com/

Also, discuss could help because users shares their problems (and the solutions).

In the past, there were code sprints that were very useful for beginners.

and what to look

anyway tell me what you need i’ll explain you how to do without

TypeError: object of type ‘generator’ has no len()

i tried len, i tried count…

Did you add correctly the brackets ‘[’ ‘]’ ?

 len([l for l in self.lines if l.product])
1 Like

maybe nope /o\
i’ll try again…

i lost the brackets…