{
    "fields": {
        "name": {
            "type": "varchar",
            "required": true,
            "trim": true
        },
        "amount": {
            "type": "currency",
            "required": true,
            "audited": true
        },
        "amountConverted": {
            "type": "currencyConverted",
            "readOnly": true
        },
        "amountWeightedConverted": {
            "type": "float",
            "readOnly": true,
            "notStorable": true,
            "select": "opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100",
            "where": {
                "=": "(opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100) = {value}",
                "<": "(opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100) < {value}",
                ">": "(opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100) > {value}",
                "<=": "(opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100) <= {value}",
                ">=": "(opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100) >= {value}",
                "<>": "(opportunity.amount * amount_currency_alias.rate * opportunity.probability / 100) <> {value}"
            },
            "orderBy": "amountWeightedConverted {direction}",
            "view": "views/fields/currency-converted"
        },
        "account": {
            "type": "link"
        },
        "contacts": {
            "type": "linkMultiple",
            "view": "crm:views/opportunity/fields/contacts",
            "columns": {
                "role": "opportunityRole"
            }
        },
        "stage": {
            "type": "enum",
            "options": ["Prospecting", "Qualification", "Needs Analysis", "Value Proposition", "Id. Decision Makers", "Perception Analysis", "Proposal/Price Quote", "Negotiation/Review", "Closed Won", "Closed Lost"],
            "view": "crm:views/opportunity/fields/stage",
            "default": "Prospecting",
            "audited": true
        },
        "probability": {
            "type": "int",
            "required": true,
            "min": 0,
            "max": 100
        },
        "leadSource": {
            "type": "enum",
            "view": "crm:views/opportunity/fields/lead-source",
            "customizationOptionsDisabled": true,
            "default": ""
        },
        "closeDate": {
            "type": "date",
            "required": true,
            "audited": true
        },
        "description": {
            "type": "text"
        },
        "campaign": {
            "type": "link"
        },
        "originalLead": {
            "type": "link",
            "layoutMassUpdateDisabled": true,
            "layoutListDisabled": true,
            "readOnly": true,
            "view": "views/fields/link-one"
        },
        "createdAt": {
            "type": "datetime",
            "readOnly": true
        },
        "modifiedAt": {
            "type": "datetime",
            "readOnly": true
        },
        "createdBy": {
            "type": "link",
            "readOnly": true,
            "view": "views/fields/user"
        },
        "modifiedBy": {
            "type": "link",
            "readOnly": true,
            "view": "views/fields/user"
        },
        "assignedUser": {
            "type": "link",
            "required": false,
            "view": "views/fields/assigned-user"
        },
        "teams": {
            "type": "linkMultiple",
            "view": "views/fields/teams"
        }
    },
    "links": {
        "createdBy": {
            "type": "belongsTo",
            "entity": "User"
        },
        "modifiedBy": {
            "type": "belongsTo",
            "entity": "User"
        },
        "assignedUser": {
            "type": "belongsTo",
            "entity": "User"
        },
        "teams": {
            "type": "hasMany",
            "entity": "Team",
            "relationName": "entityTeam",
            "layoutRelationshipsDisabled": true
        },
        "account": {
            "type": "belongsTo",
            "entity": "Account",
            "foreign": "opportunities"
        },
        "contacts": {
            "type": "hasMany",
            "entity": "Contact",
            "foreign": "opportunities",
            "additionalColumns": {
                "role": {
                    "type": "varchar",
                    "len": 50
                }
            }
        },
        "meetings": {
            "type": "hasChildren",
            "entity": "Meeting",
            "foreign": "parent",
            "layoutRelationshipsDisabled": true,
            "audited": true
        },
        "calls": {
            "type": "hasChildren",
            "entity": "Call",
            "foreign": "parent",
            "layoutRelationshipsDisabled": true,
            "audited": true
        },
        "tasks": {
            "type": "hasChildren",
            "entity": "Task",
            "foreign": "parent",
            "layoutRelationshipsDisabled": true,
            "audited": true
        },
        "emails": {
            "type": "hasChildren",
            "entity": "Email",
            "foreign": "parent",
            "layoutRelationshipsDisabled": true
        },
        "documents": {
            "type": "hasMany",
            "entity": "Document",
            "foreign": "opportunities",
            "audited": true
        },
        "campaign": {
            "type": "belongsTo",
            "entity": "Campaign",
            "foreign": "opportunities",
            "noJoin": true
        },
        "originalLead": {
            "type": "hasOne",
            "entity": "Lead",
            "foreign": "createdOpportunity"
        }
    },
    "collection": {
        "sortBy": "createdAt",
        "asc": false
    },
    "probabilityMap": {
        "Prospecting": 10,
        "Qualification": 10,
        "Needs Analysis": 20,
        "Value Proposition": 50,
        "Id. Decision Makers": 60,
        "Perception Analysis": 70,
        "Proposal/Price Quote": 75,
        "Negotiation/Review": 90,
        "Closed Won": 100,
        "Closed Lost": 0
    },
    "indexes": {
        "stage": {
            "columns": ["stage", "deleted"]
        },
        "assignedUser": {
            "columns": ["assignedUserId", "deleted"]
        },
        "createdAt": {
            "columns": ["createdAt", "deleted"]
        },
        "createdAtStage": {
            "columns": ["createdAt", "stage"]
        },
        "assignedUserStage": {
            "columns": ["assignedUserId", "stage"]
        }
    }
}
