Merge lp:~openerp-dev/openobject-server/6.1-opw-579669-nep into lp:openobject-server/6.1

Proposed by Nehal Panchal (OpenERP)
Status: Rejected
Rejected by: Naresh(OpenERP)
Proposed branch: lp:~openerp-dev/openobject-server/6.1-opw-579669-nep
Merge into: lp:openobject-server/6.1
Diff against target: 13 lines (+4/-0)
1 file modified
openerp/addons/base/ir/ir_attachment.py (+4/-0)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/6.1-opw-579669-nep
Reviewer Review Type Date Requested Status
Naresh(OpenERP) (community) Needs Fixing
Review via email: mp+126935@code.launchpad.net

Description of the change

Hello,

While creating an attachment by OpenERP, directory specified with resource model should be considered.

Steps to reproduce:
1. Create a directory with resource model for example:Invoice.
2. When you print Invoice report, attachment will be created with Document directory which is wrong.

This fixes the issue.

Thanks

To post a comment you must log in.
Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

Hello,

I think this is not the right place to fix this.
The issue should be fixed from class document_file's create defined in document.py as this inherits ir_attachment

Secondly the main root of the problem is that in create we already check for the directory context and vals dict if we didn't find any we use the default one i.e the root directory. In your case the ir_attachment create is triggered from the report engine which will never set this field in context nor in vals which in turn pop's up this bug.

So as a solution make changes in the create overridden in document.py something like
if document not in context nor in vals:
     if type in vals and type == folder per resource
             search the directory based on the resource and use.

Note: its just a snippet

Thanks,
Naresh

review: Needs Fixing
Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

needs to be fixed from addons

Unmerged revisions

4282. By Nehal Panchal (OpenERP)

[FIX] base : Fixed the issue while creating an attachment by OpenERP,directory specified with resource model should be considered

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/addons/base/ir/ir_attachment.py'
2--- openerp/addons/base/ir/ir_attachment.py 2012-08-21 14:16:05 +0000
3+++ openerp/addons/base/ir/ir_attachment.py 2012-09-28 11:45:28 +0000
4@@ -122,6 +122,10 @@
5 return super(ir_attachment, self).unlink(cr, uid, ids, context)
6
7 def create(self, cr, uid, values, context=None):
8+ if 'parent_id' in values and context.get('active_model'):
9+ parent_ids_updated = self.pool.get('document.directory').search(cr, uid, [('ressource_type_id','=',context.get('active_model'))])
10+ if parent_ids_updated:
11+ values.update(parent_id=parent_ids_updated[0])
12 self.check(cr, uid, [], mode='create', context=context, values=values)
13 return super(ir_attachment, self).create(cr, uid, values, context)
14