Merge lp:~numerigraphe-team/report-print-send/7.0-user-browse-lp1116672-ls into lp:~report-print-send-core-editors/report-print-send/7.0

Proposed by Lionel Sausin - Initiatives/Numérigraphe
Status: Merged
Merged at revision: 14
Proposed branch: lp:~numerigraphe-team/report-print-send/7.0-user-browse-lp1116672-ls
Merge into: lp:~report-print-send-core-editors/report-print-send/7.0
Diff against target: 33 lines (+3/-5)
1 file modified
base_report_to_printer/ir_report.py (+3/-5)
To merge this branch: bzr merge lp:~numerigraphe-team/report-print-send/7.0-user-browse-lp1116672-ls
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp code review Approve
Loïc Bellier - Numérigraphe (community) Approve
Pedro Manuel Baeza code review Approve
Review via email: mp+216356@code.launchpad.net

Description of the change

Fix missing arguments in browse call which prevents user-defined defaults to be considered.

To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Lionel, you can use this better form:

user = self.pool['res.users]).browse(cr, uid, uid, context=context)

Regards.

review: Needs Fixing (code review)
Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

Hi Pedro,
I avoided this form on purpose because it's the first thing people break when they inherit ORM methods, and I read it's getting deprecated in v8 (not sure, can't find the reference).
Would you still like me to change it?

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

What is exactly been deprecated?

- About self.pool[], here it's a good explanation why it's better: http://hypered.io/blog/2013-12-30-self-pool-get/
- About (cr, uid, uid... instead of (cr, uid, [uid], the explanation is simple: ORM methods allow lists or single ids, and in this case, you save to access to 0 index of the returned one-element list.

Regards.

Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

I was talking about using a single ID sorry.

14. By Numérigraphe

[IMP] Use short notation for browse and use pool[] instead of pool.get() as suggested by Pedro Manuel Baeza

Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

Changed!

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Uhm, I'm not aware about that deprecation, but it can be. I always avoid single ID on read, write, and so on overrides, but I see no problem with browse method. Do you know anyone that overrides this method?

In summary, I have no hard feeling about any form, so please let it as you want.

I find this discussion very instructive :)

Regards.

review: Approve (code review)
Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

About the single id thing I followed your advice.
In v8 it'll be out for read() at least according to this: https://twitter.com/RaphaelCollet/status/403095308722139136
...but we'll need to fix a whole pile of code anyway if they deprecate it, so one more won't make a difference.

Revision history for this message
Loïc Bellier - Numérigraphe (lb-b) :
review: Approve
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) :
review: Approve (code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'base_report_to_printer/ir_report.py'
2--- base_report_to_printer/ir_report.py 2013-10-02 12:08:48 +0000
3+++ base_report_to_printer/ir_report.py 2014-04-17 16:35:03 +0000
4@@ -47,7 +47,6 @@
5 return options
6
7 def print_direct(self, cr, uid, report_id, result, format, printer, context=None):
8- user_obj = self.pool.get('res.users')
9 fd, file_name = mkstemp()
10 try:
11 os.write(fd, base64.decodestring(result))
12@@ -85,8 +84,8 @@
13
14 def behaviour(self, cr, uid, ids, context=None):
15 result = {}
16- printer_obj = self.pool.get('printing.printer')
17- printing_act_obj = self.pool.get('printing.report.xml.action')
18+ printer_obj = self.pool['printing.printer']
19+ printing_act_obj = self.pool['printing.report.xml.action']
20 # Set hardcoded default action
21 default_action = 'client'
22 # Retrieve system wide printer
23@@ -94,9 +93,8 @@
24 if default_printer:
25 default_printer = printer_obj.browse(cr, uid, default_printer, context=context)
26
27-
28 # Retrieve user default values
29- user = self.pool.get('res.users').browse(cr, uid, context)
30+ user = self.pool['res.users'].browse(cr, uid, uid, context=context)
31 if user.printing_action:
32 default_action = user.printing_action
33 if user.printing_printer_id: