[FIX] purchase: post message on purchase order as admin if have no read access (would...
authorMartin Trigaux <mat@openerp.com>
Tue, 29 Oct 2013 09:23:53 +0000 (10:23 +0100)
committerMartin Trigaux <mat@openerp.com>
Tue, 29 Oct 2013 09:23:53 +0000 (10:23 +0100)
bzr revid: mat@openerp.com-20131029092353-yg0wxl42352yu2rb

addons/purchase/purchase.py

index 73f7edc..7a7513f 100644 (file)
@@ -1231,9 +1231,14 @@ class account_invoice(osv.Model):
     def invoice_validate(self, cr, uid, ids, context=None):
         res = super(account_invoice, self).invoice_validate(cr, uid, ids, context=context)
         purchase_order_obj = self.pool.get('purchase.order')
-        po_ids = purchase_order_obj.search(cr, uid, [('invoice_ids', 'in', ids)], context=context)
+        # read access on purchase.order object is not required
+        if not purchase_order_obj.check_access_rights(cr, uid, 'read', raise_exception=False):
+            user_id = SUPERUSER_ID
+        else:
+            user_id = uid
+        po_ids = purchase_order_obj.search(cr, user_id, [('invoice_ids', 'in', ids)], context=context)
         for po_id in po_ids:
-            purchase_order_obj.message_post(cr, uid, po_id, body=_("Invoice received"), context=context)
+            purchase_order_obj.message_post(cr, user_id, po_id, body=_("Invoice received"), context=context)
         return res
 
     def confirm_paid(self, cr, uid, ids, context=None):