Merge lp:~openerp/openobject-server/trunk-wip-niv into lp:openobject-server

Proposed by Nicolas Vanhoren (OpenERP)
Status: Merged
Merged at revision: 3506
Proposed branch: lp:~openerp/openobject-server/trunk-wip-niv
Merge into: lp:openobject-server
Diff against target: 28 lines (+15/-3)
1 file modified
openerp/osv/orm.py (+15/-3)
To merge this branch: bzr merge lp:~openerp/openobject-server/trunk-wip-niv
Reviewer Review Type Date Requested Status
Vo Minh Thu (community) Approve
Review via email: mp+67297@code.launchpad.net

Description of the change

Improved modifiers.

To post a comment you must log in.
Revision history for this message
Vo Minh Thu (thu) wrote :

Before merging, can you add test cases to the modifiers_tests() function?

I think you can reuse the modifiers variable instead of using a default_values intermediary variable. This would simplify the last loop a bit.

Some variable name consistency would be nice too. exceptions instead of modifs, (a, value) instead of (modif[0], modif[1]) and renaming a into attr, or attr in a.

  default_values[a] = False
    if field.get(a):
       default_values[a] = bool(field.get(a))

can be simplified to

  default_values[a] = bool(field.get(a))

  field.get("states") or {}

can be just

  field.get("states", {})

At line 18, no need for parens.

review: Approve
Revision history for this message
Vo Minh Thu (thu) wrote :

The approve above is a mistake. Or is modulo the changes...

Revision history for this message
Nicolas Vanhoren (OpenERP) (niv-openerp) wrote :

Tu sais, c'aurait été genre trois fois plus rapide que tu le fasses toi même plutôt que de m'emmerder avec de vaines critiques subjectives sur le nommage de variables.

Je te rappelle que c'est quand même ton boulot que j'ai fait à ta place parce que je voulais que ce soit plus vite fait. D'autant plus que tu n'aurais pas testé le résultat avec des cas réels, ce qui fait qu'à la moindre erreur j'aurais du revenir te demander de le fixer, puis à l'erreur suivante ç'aurait été pareil, etc...

Alors voila ce qu'on va faire: T'es pas content? Fais le toi même, moi je touche plus à rien.

3500. By Nicolas Vanhoren (OpenERP)

[merge]

3501. By Antony Lesuisse (OpenERP)

[FIX] apply some merge review feeback

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/osv/orm.py'
2--- openerp/osv/orm.py 2011-07-05 12:22:22 +0000
3+++ openerp/osv/orm.py 2011-07-12 14:37:01 +0000
4@@ -77,9 +77,21 @@
5 ROOT_USER_ID = 1
6
7 def transfer_field_to_modifiers(field, modifiers):
8- for a in ('invisible', 'readonly', 'required'):
9- if field.get(a):
10- modifiers[a] = bool(field.get(a))
11+ default_values = {}
12+ state_exceptions = {}
13+ for attr in ('invisible', 'readonly', 'required'):
14+ state_exceptions[attr] = []
15+ default_values[attr] = bool(field.get(attr))
16+ for state, modifs in (field.get("states",{})).items():
17+ for modif in modifs:
18+ if default_values[modif[0]] != modif[1]:
19+ state_exceptions[modif[0]].append(state)
20+
21+ for attr, default_value in default_values.items():
22+ if state_exceptions[attr]:
23+ modifiers[attr] = [("state", "not in" if default_value else "in", state_exceptions[attr])]
24+ else:
25+ modifiers[attr] = default_value
26
27
28 # Don't deal with groups, it is done by check_group().