Minor documentation improvement

Bug #1288708 reported by Martin Bramwell
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OERPLib
New
Undecided
Unassigned

Bug Description

Add to the section "Update data through browsable records" . . .

| and is also equivalent to:
|
| >>> setattr(partner, 'name', "Caporal Jones")
| >>> oerp.write_record(partner)

Revision history for this message
Sébastien Alix (sebastien-alix) wrote :

Hi Martin,

Hi don't know if it is relevant this kind of documentation with setattr/getattr, as it is a common feature of Python. I mean it applies to every objects:

>>> order_obj = getattr(oerp, 'get')('sale.order')
>>> order = getattr(order_obj, 'browse')(4)

(same behaviour for setattr)

Have you some reasons to put that in the tutorial for this specific case?
But this kind of example would have its place in the 'example' folder of the project. What do you think?

Revision history for this message
Martin Bramwell (martinhbramwell) wrote :

I suggest it because I was not 100% certain that it would work until I tried it.

My entire programming design depends on text declarations of tasks to be performed. I was at first dismayed that attributes had to be set by name specifically. I am from a Java programming background, in which introspection is nowhere as near as easy as in Python.

I really appreciate the quality of your documentation, and thought to propose that inclusion because it would have helped me to have seen that there noted explicitly.

Revision history for this message
Sébastien Alix (sebastien-alix) wrote :

I understand, reflection is used a lot for such tools.
But now I think about it, there is another way to access data (and which is available in OpenERP too I think), like a dictionary interface:

>>> partner['name'] == partner.name
True

But at this time, there is no possibility to set a value, it's just an accessor:

>>> partner['name'] = "Test"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'res_partner' object does not support item assignment

I could implement this operation (I have to check if there would be no regression to do it).
And this specific API on browse_records will be present in the documentation of course. It would be ok for you?

Revision history for this message
Martin Bramwell (martinhbramwell) wrote :

> I could implement this operation (I have to check if there would be no regression to do it).
> And this specific API on browse_records will be present in the documentation of course.
> It would be ok for you?

setattr is probably all I need. As long as there is that reminder in the docs, I don't see the need to complicate your code with it.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.