You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
3.0 KiB

  1. {
  2. 'name': 'Web Context Tunnel',
  3. 'category': 'Hidden',
  4. 'author': 'Akretion',
  5. 'license': 'AGPL-3',
  6. 'description':"""
  7. Web Context Tunnel.
  8. ===================
  9. The problem with OpenERP on_changes
  10. -----------------------------------
  11. OpenERP uses to pass on_change Ajax events arguments using positional
  12. arguments. This is annoying as modules often need to pass extra arguments
  13. that are not present in the base on_change signatures. As soon as two modules
  14. try to alter this signature to add their extra arguments, they are incompatible
  15. between them unless some extra glue module make them compatible again by
  16. taking all extra arguments into account. But this leads to a combinatorial
  17. explosion to make modules compatibles.
  18. The solution
  19. ------------
  20. This module provides a simple work around that will work in most of the cases.
  21. In fact it works if the base on_change is designed to pass the context
  22. argument. Else it won't work and you should go the old way. But in any case
  23. it's a bad practice if an on_change doesn't pass the context argument and you
  24. can certainly rant about these bad on_changes to the the context added in the
  25. arguments.
  26. So for an on_change passing the context, how does this module works?
  27. Well OpenERP already has an elegant solution for an extension module to alter
  28. an XML attributes: put an extension point in the view using
  29. position="attributes" and then redefine the attribute. That is already used at
  30. several places to replace the "context" attribute that the client will send to
  31. the server.
  32. The idea here is to wrap the extra arguments needed by your on_change inside
  33. that context dictionary just as it were a regular Python kwargs. In the
  34. on_change override chain, the context is then propagated naturally, no matter
  35. of the module order and without any need to hack any on_change signature.
  36. The issue with just position="attributes" and redefining the context, is that
  37. again, if two independent modules do it, they are incompatible unless a third
  38. module accounts for both of them.
  39. But with this module, an extension point can now use position="attributes" and
  40. instead of redefining the "context" attribute, you will now just define a new
  41. "context_foo" attribute this way:
  42. <attribute name="context_foo">{'my_extra_field': my_extra_field}</attribute>.
  43. This module modifies the web client in such a way that before sending the Ajax
  44. on_change event request to the server, all the node attributes starting with
  45. "context" are merged into a single context dictionnary, keeping the keys and
  46. values from all extensions. In the rare case a module really wants to override
  47. the value in context, then it needs to still override the original context
  48. attribute (or the other original attribute).
  49. And of course, if you should call your on_change by API or webservice instead
  50. of using the web client, simply ensure you are wrapping the required extra
  51. arguments in the context dictionary.
  52. """,
  53. 'version': '2.0',
  54. 'depends': ['web'],
  55. 'js': ['static/src/js/context_tunnel.js'],
  56. 'css': [],
  57. 'auto_install': False,
  58. 'web_preload': False,
  59. }