Merge lp:~camptocamp/sale-reports/7.0-conditional_discount_print-rde into lp:~sale-core-editors/sale-reports/7.0

Proposed by Romain Deheele - Camptocamp
Status: Merged
Approved by: Pedro Manuel Baeza
Approved revision: 27
Merged at revision: 25
Proposed branch: lp:~camptocamp/sale-reports/7.0-conditional_discount_print-rde
Merge into: lp:~sale-core-editors/sale-reports/7.0
Diff against target: 64 lines (+29/-2)
2 files modified
sale_order_webkit/report/sale_order.mako (+4/-0)
sale_order_webkit/report/sale_order.py (+25/-2)
To merge this branch: bzr merge lp:~camptocamp/sale-reports/7.0-conditional_discount_print-rde
Reviewer Review Type Date Requested Status
Nicolas Bessi - Camptocamp (community) code review, no test Approve
Pedro Manuel Baeza code review Approve
Leonardo Pistone Approve
Review via email: mp+206678@code.launchpad.net

Description of the change

Hello,

This branch transposes conditional discount printing from official rml addons
http://bazaar.launchpad.net/~openerp/openobject-addons/7.0/revision/8878:
when printing the sale order report, do not print the discount column if user doesn't belong to the group that enables to see it.

Regards,

Romain

To post a comment you must log in.
Revision history for this message
Leonardo Pistone (lepistone) wrote :

Romain,

- lines seem a bit long to the naked eye
- you could catch only the exception you want to catch + a comment saying why you return False (i.e. "group does not exist)

thanks!

review: Needs Fixing (code review)
26. By Romain Deheele - Camptocamp

[UPD] PEP8 nits + comments

Revision history for this message
Romain Deheele - Camptocamp (romaindeheele) wrote :

Thanks Leonardo,
I updated it accordingly.

Revision history for this message
Leonardo Pistone (lepistone) wrote :

thanks

review: Approve
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Hello,

Thanks for the patch

3 + return group_id in [x.id for x in res_users_obj.browse(
54 + cr,
55 + uid,
56 + uid,
57 + context=context).groups_id]

Just a matter of taste but it is quite ugly and probably a copy paste from original report.
Something like:

groups = res_users_obj.browse(cr, uid, uid, context=context).group_id
return any(x for x in groups if x.id == group_id)

Should be more readable

regards

Nicolas

review: Needs Fixing (code review, no test)
27. By Romain Deheele - Camptocamp

[UPD] more readable style

Revision history for this message
Romain Deheele - Camptocamp (romaindeheele) wrote :

Thanks Nicolas, indeed, your proposition is more readable.

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) :
review: Approve (code review)
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

LGTM

review: Approve (code review, no test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'sale_order_webkit/report/sale_order.mako'
2--- sale_order_webkit/report/sale_order.mako 2013-12-27 17:16:59 +0000
3+++ sale_order_webkit/report/sale_order.mako 2014-02-17 14:35:14 +0000
4@@ -206,7 +206,9 @@
5 <th class="amount main_col3">${_("UoM")}</th>
6 <th class="amount main_col4">${_("Unit Price")}</th>
7 <th class="main_col5">${_("VAT")}</th>
8+ %if show_discount(user.id):
9 <th class="amount main_col6">${_("Disc.(%)")}</th>
10+ %endif
11 <th class="amount main_col7">${_("Price")}</th>
12 </tr>
13 </table>
14@@ -225,7 +227,9 @@
15 <td class="amount main_col3">${ line.product_uos and line.product_uos.name or line.product_uom.name }</td>
16 <td class="amount main_col4">${formatLang(line.price_unit)}</td>
17 <td class="main_col5">${ ', '.join([tax.description or tax.name for tax in line.tax_id]) }</td>
18+ %if show_discount(user.id):
19 <td class="amount main_col6">${line.discount and formatLang(line.discount, digits=get_digits(dp='Sale Price')) or ''} ${line.discount and '%' or ''}</td>
20+ %endif
21 <td class="amount main_col7">${formatLang(line.price_subtotal, digits=get_digits(dp='Sale Price'))}&nbsp;${order.pricelist_id.currency_id.symbol}</td>
22 </tr>
23 %if line.formatted_note:
24
25=== modified file 'sale_order_webkit/report/sale_order.py'
26--- sale_order_webkit/report/sale_order.py 2013-01-25 09:40:48 +0000
27+++ sale_order_webkit/report/sale_order.py 2014-02-17 14:35:14 +0000
28@@ -28,11 +28,34 @@
29 def __init__(self, cr, uid, name, context):
30 super(SaleOrderReport, self).__init__(cr, uid, name, context=context)
31 self.localcontext.update({'time': time,
32- 'company_vat': self._get_company_vat})
33+ 'company_vat': self._get_company_vat,
34+ 'show_discount': self._show_discount,
35+ })
36+
37+ def _show_discount(self, uid, context=None):
38+ """ check if the user belongs to group_discount_per_so_line group
39+ """
40+ cr = self.cr
41+ pool = pooler.get_pool(self.cr.dbname)
42+ res_users_obj = pool.get('res.users')
43+ model_data_obj = pool.get('ir.model.data')
44+ try:
45+ group_id = model_data_obj.get_object_reference(
46+ cr,
47+ uid,
48+ 'sale',
49+ 'group_discount_per_so_line')[1]
50+ except ValueError:
51+ #group named group_discount_per_so_line doesn't exist
52+ return False
53+ groups = res_users_obj.browse(cr, uid, uid, context=context).group_id
54+ return any(x for x in groups if x.id == group_id)
55
56 def _get_company_vat(self):
57 res_users_obj = pooler.get_pool(self.cr.dbname).get('res.users')
58- company_vat = res_users_obj.browse(self.cr, self.uid, self.uid).company_id.partner_id.vat
59+ company_vat = res_users_obj.browse(
60+ self.cr, self.uid, self.uid
61+ ).company_id.partner_id.vat
62 return company_vat
63
64 report_sxw.report_sxw('report.sale.order.webkit',

Subscribers

People subscribed via source and target branches