SugarCRM relating fields - binding

Is it possible to bind fields in SugarCRM CE version?
For example I have a customized Redemption module with an 'Points' Field and another 'Points Redemption' field at Customer module, is it possible by using studio that when I create a new redemption for a particular customer it will be updated at Customer module on that customer's profile?

Yes, and I can think of two good ways of doing so. The first, easier way, is to use Sugar Logic. For paid editions of SugarCRM, Sugar Logic offers a Javascript-esque style formula builder which allows simple summations and math functions and the ability to pull in related information.
More on Sugar Logic here: http://support.sugarcrm.com/02_Documentation/04_Sugar_Developer/Sugar_Developer_Guide_6.5/03_Module_Framework/Sugar_Logic and here: http://developer.sugarcrm.com/category/sugar-logic/
The second method will be more code-centric. You could place a series of logic hooks on the Customer and Redemption modules such that saving or adjusting the relationships will adjust a field on the Customer module.

Related

Versioning domain instances for approval in Grails

I’m looking for the best approach to extend the Grails CRUD generation functionality. It should be a Grails plugin which provides additional generators for following functionality:
Any changes on extended domain instance should be saved (as a version
of it) for history
Only one version of an instance can be active
User should be able to activate a version of the instance (the
currently active instance should be deactivated) which is not created
by him (4 eyes principle)
A diff view is nice to have
The intervention into Grails out of the box scripts should be as small as possible.
I identified so far 3 design strategies for implementation:
Mirror table with the same schema, which contains versions (doubles
the count of domains/tables). The activated version will be copied
to the native domain and vice versa.
Using discriminator in the domain class. Some new columns will be added to the domain (like state [active,notActive], lastUpdatedBy,
lastUpdatedDate…)
(De-)Serializing instances to a special domain with BLOB (e.g domain.properties as JSON)
Any of the solutions has pros and cons. What is the best approach to implement it? Perhaps there is a more simple way.
I've been developing a system in Grails that makes intense use of the version concept (as you related above). My approach was the 2nd one listed in your question.
I've created two fields: internalVersion e disabled. Every class that needs to be Versionable, must implement an interface called Versionable.
I'll try explain here one of the scenarios which it's necessary to use the version functionality (forgive my english).
The system that uses this concept is a Commercial System where there is a class called Quote.
Every Quote can has one or more versions where only the last version is valid. Every Quote and its versions are generated based in negotiations with an specific client. This way, a client asks us a Quote and if for some reason he doesn't like the prices (for instance), we can generate a new version with some discount. Every Quote has a unique code following by the current version, example: QT-000022/0 (first version), QT-000022/1 (second version).
To generate a new Version I use a method that clones the current object (using a kind of complete and deep Save As). I copy everything (properties and collections) to a new object.
The clone method identifies that the class implements the Versionable interface and does the following:
oldQuote.disabled = true
newQuote.internalVersion = oldQuote.internalVersion + 1
This way it's possible assure that only one version will be enabled.
I hope you understand my approach.

Ruby on Rails: Scope vs Helper Method

I'm pretty new to Rails and wanted to do something along the lines of choosing a subset of objects in my Model. For example, I have a Project model and wanted to select some subset of projects based on some join table with another model, Organizations.
My initial thought was to create some helper method in projects_helper.rb that would perform the appropriate lookup on to determine which projects to return.
Another thought was to utilize scoping as described here (http://apidock.com/rails/ActiveRecord/Scoping/Named/ClassMethods/scope).
Both seem to functionally complete the objective, but what would be the best practice way of accomplishing this? Is there a key difference as to what can access each of these approaches?
Thanks!
Depends on the point of view of the question being "asked" by the query.
If you are asking for an Organization's projects, you might choose the Org first, then display organization.projects. Nothing fancy going on there beyond linking the models appropriately (organization has_many projects, project belongs_to organization) and having the organization_id as a foreign key in the projects table.
I'm not sure if a named scope would be appropriate if the Organizations in your system are a dynamic quantity. You don't want to have a named scope for each if the list of organizations changes all that often.

Which programming pattern is an elegant solution for handling a MailChimp mailing list?

I implemented some list managment methods to keep the user-data of my Rails app synchronized with the subscriber data of the according MailChimp list.
(EDIT) Under the hood I am already using the mailchimp gem. I am simply abstracting one level higher to represent one specific list.
For now all the logic is in a controller, but I'd rather have a more generic und thus reusable approach (maybe even convert it into a gem someday).
So my first thought is to represent the list as a table-less model, offering the necessary methods to handle it.
class MailChimpList
def add_subscriber
# ...
end
# ...
end
... but I am curious which other approaches exist and which would reflect the idea even better?
You could use the gem gibbon https://github.com/amro/gibbon to interact with mailchimp. You can fetch lists, campaigns, emails subscribed to lists etc.
For a more general approach to handling API interactions (not just MailChimp), Temboo offers a Ruby SDK that normalizes access to 100s of APIs. For example, adding a MailChimp subscriber looks like this:
listSubscribe = MailChimp::ListSubscribe.new(temboo_session)
listSubscribeInputs = listSubscribeChoreo.new_input_set()
listSubscribeInputs.set_credential("myMailchimpAccount")
listSubscribeInputs.set_ListId("myMailingList")
listSubscribeInputs.set_EmailAddress("foo#example.com")
listSubscribeResults = listSubscribe.execute(listSubscribeInputs)
Check it out if you think you'll be re-using MailChimp for other projects, or trying to integrate other APIs in a similar fashion.
You can find MailChimp methods & docs, customizable code snippets, and live examples here: https://www.temboo.com/library/Library/MailChimp/
(Full disclosure: I work for Temboo. :)

Can Spree allow me to have 'Vendors' in my e-commerce app?

Rather than the typical one store app, where I (as a user) go and add products that one seller (the owner of the Spree app) is selling, what I want to do is to create an ecommerce site that has multiple vendors.
So you could see an overview of all vendors, and then you can buy multiple products from multiple vendors.
Does Spree allow me to customize it to that extent?
If so, are there any docs for that?
Thanks.
One approach (the one I used), is to add a 'vendor' Property to each item. Note - this approach assumes that each item is only sold by a single vendor. If you actually have a marketplace with various vendors competing to sell the same item, you'll need to do a similar thing by adding a 'vendor' OptionType, that is defined for each product Variant.
Each vendor (new model) is assigned a code that can be used when setting up your items (as either a property value, or multiple variant option values). When an order is placed, you can use a new OrderFulfillment model to track the various shipments that the various vendors will use to fulfill that order (one OrderFulfillment record per vendor in the order).
That's basically all the model changes you'll need. In the controller area, you'll need to modify the 'shopping cart' event machine sequence to handle the different vendor's shipping methods. And in the case of multiple vendors, you'll also need to present the user with a choice of vendor (think amazon marketplace).
How you handle your payments to various vendors was not part of my project, but shouldn't be too complex to add if needed.
Regarding links: You should be familiar with the basic Spree concepts which are discussed in the guide in general, and more specifically here. You will also need to make some internal modifications (new associations, modified controller behavior) which you can read about here.
I think you have a few options available for that.
Essentially, you want an e commerce app where users can sign up and list their own products, and then have a user profile page where someone can look and see just that user's products, right? Some people call this multi-tenancy, and if you do a google search you will soon find this spree extension: multi-tenant
I am looking to do the same thing as you, and I'm a bit wary of multi tenant because I would have to roll back to Spree 2-2 stable (I'm currently on 2-3).
The previous answer here suggests that you should create a new model called Vendor. I would say why not just update your already existing user model to become a vendor?
What I'm suggesting is simply creating an association between the User model and the Spree::Products model. This way you can scope products to individual users and create profile pages without the complexity of adding new, foreign models and/or different admins for each user. All of the spree methods are already attached to your User class, so I would think a simple belongs_to/has_many association would work. Haven't tested this at all, but that's what my thinking is.

Modeling data for complex applications: inheritance? modules?

I'm developing a prototype for a Rails application that has a somewhat complex model. I'm having a hard time figuring out how the model should be designed.
Here's the basic idea:
Say the app is for a small coop, and should allow users to file "applications" (as in a apply for a loan, accounts, etc) online.
Technically, all of them are "applications" and my client would like a dashboard presenting all pending evaluations for a given group (ie: the auto loans group). So, I'm thinking of having an application model. I could subclass ApplicationModel for loans, accounts, etc., but I'm thinking Rails will use a Loans table, an Accounts table, and so, and so for each type of model. There are different kinds of loans too: Mortgage, Auto, Personal, etc. All require different data. A manager for the whole Loans division, should be able to see all pending loan approvals from his dashboard (all classes of loans).
If I were to do something like Loans.find() would I get all Loan subtypes with it? Or only what's stored in the loans table?
Is inheritance the way to go? Should I be looking at something else? Is rails even adequate for this kind of application?
I saw the legacy application built on Java that they were using (but hated with a passion). The previous developer had an ST_APPLICATIONS table which store all applications. In that table he stores all the application data in a blob containing a bunch of XML. Would such an approach be recommended with Rails?

Resources