Skip to content

Commit

Permalink
Reload only already loaded fields after update, create and wkf_action
Browse files Browse the repository at this point in the history
  • Loading branch information
dbroeglin committed Mar 30, 2012
1 parent 2b218ae commit 7bd6f2f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
*.swp
13 changes: 10 additions & 3 deletions lib/app/models/open_object_resource.rb
Expand Up @@ -362,17 +362,18 @@ def save(context={}, reload=true)
def create(context={}, reload=true)
self.id = rpc_execute('create', to_openerp_hash!, context)
IrModelData.create(:model => self.class.openerp_model, :module => @ir_model_data_id[0], :name=> @ir_model_data_id[1], :res_id => self.id) if @ir_model_data_id
reload_from_record!(self.class.find(self.id, :context => context)) if reload
reload_fields(context) if reload
@persisted = true
end

#compatible with the Rails way but also supports OpenERP context
def update(context={}, reload=true)
rpc_execute('write', [self.id], to_openerp_hash!, context)
reload_from_record!(self.class.find(self.id, :context => context)) if reload
reload_fields(context) if reload
@persisted = true
end


#compatible with the Rails way but also supports OpenERP context
def destroy(context={})
rpc_execute('unlink', [self.id], context)
Expand All @@ -399,7 +400,7 @@ def on_change(on_change_method, field_name, field_value, *args)
#wrapper for OpenERP exec_workflow Business Process Management engine
def wkf_action(action, context={}, reload=true)
self.class.rpc_exec_workflow_with_all(object_db, object_uid, object_pass, self.class.openerp_model, action, self.id) #FIXME looks like OpenERP exec_workflow doesn't accept context but it might be a bug
reload_from_record!(self.class.find(self.id, :context => context)) if reload
reload_fields(context) if reload
end

def old_wizard_step(wizard_name, step='init', wizard_id=nil, form={}, context={})
Expand Down Expand Up @@ -471,5 +472,11 @@ def get_report_data(report_name, report_type="pdf", context={})
self.class.get_report_data(report_name, [self.id], report_type, context)
end

private

def reload_fields(context)
records = self.class.find(self.id, :context => context, :fields => @attributes.keys)
reload_from_record!(records)
end
end
end

0 comments on commit 7bd6f2f

Please sign in to comment.