chicks / sugarcrm

A ruby based REST Client for SugarCRM
MIT License
90 stars 64 forks source link

Copy Functionality #47

Closed frugardc closed 13 years ago

frugardc commented 13 years ago

Is there a module object "copy" or "clone" functionality?

Something like...

opp = SugarCRM::Opportunity.first

opp2 = opp.clone

davidsulc commented 13 years ago

What are you trying to do?

frugardc commented 13 years ago

For historical forecasting, once an opportunity gets cancelled, we want to create a copy of that opp with a negative revenue to cancel out the positive. Not my rules, just a requirement I have to fill. So I basically just want to clone an opp, switch the revenue to negative, and save it.

On Fri, Apr 22, 2011 at 10:53 AM, davidsulc < reply@reply.github.com>wrote:

What are you trying to do?

Reply to this email directly or view it on GitHub: https://github.com/chicks/sugarcrm/issues/47#comment_1044109

davidsulc commented 13 years ago

You should be able to achieve that this way

opp = SugarCRM::Opportunity.first
opp2 = SugarCRM::Opportunity.new(opp.attributes)
# manipulate opp2
opp2.save!

It is to be noted that when you call new with an attributes array, the 'id' value is automatically stripped if it is present. Depending on your particular case, there may be other attributes you want to remove...

If you're doing this a lot, you might also want to put the code to do it in an extension.

Let me know if you run into issues.

frugardc commented 13 years ago

perfect. Thanks!

On Fri, Apr 22, 2011 at 11:01 AM, davidsulc < reply@reply.github.com>wrote:

You should be able to achieve that this way

opp = SugarCRM::Opportunity.first opp2 = SugarCRM::Opportunity.new(opp.attributes)

manipulate opp2

opp2.save!

It is to be noted that when you call new with an attributes array, the 'id' value is automatically stripped if it is present. Depending on your particular case, there may be other attributes you want to remove...

Let me know if you run into issues.

Reply to this email directly or view it on GitHub: https://github.com/chicks/sugarcrm/issues/47#comment_1044132

davidsulc commented 13 years ago

No problem.