Prechádzať zdrojové kódy

opportunity bugs fixed

robert 8 rokov pred
rodič
commit
85abf54a3a

+ 5 - 14
www/css/app.css

@@ -1,4 +1,8 @@
 /* Empty. Add your own CSS if you like */
+.background {
+    background-color:  #387ef5;
+}
+
 .profile {
     width: 150px;
     height: 150px;
@@ -63,17 +67,4 @@
     height: 32px;
     stroke: #387ef5;
     fill: #387ef5;
-}
-
-.popover {
-    height: auto !important;
-}
-.popover ion-header-bar {
-    position: relative;
-}
-.popover ion-content {
-    top: 0;
-    position: relative;
-}
-
-
+}

BIN
www/img/footer.png


+ 0 - 1
www/js/controllers/lead.controller.js

@@ -143,7 +143,6 @@ angular.module('odoo')
          */
         $scope.save = function () {
             leadsStorageFactory.save($scope.lead, function (leadId) {
-
                 if (!$scope.lead.id) {
                     $scope.lead.id = leadId;
                     $scope.leads.push($scope.lead);

+ 134 - 38
www/js/controllers/opportunity.controller.js

@@ -6,6 +6,7 @@ angular.module('odoo')
     .controller('OpportunitiesController', function (
         $scope,
         $ionicPopup,
+        $ionicModal,
         $ionicFilterBar,
         $ionicActionSheet,
         deviceFactory,
@@ -13,10 +14,13 @@ angular.module('odoo')
         opportunitiesDataFactory
     ) {
 
+        // =======================================================================================================
         $scope.loading = false;
         $scope.selectedIndex = -1;
         $scope.search = null;
         $scope.stages = [];
+        $scope.stagesToMove = [];
+        $scope.opportunity = {};
         $scope.opportunities = [];
         $scope.groupedOpportunities = [];
         $scope.stage = {
@@ -24,26 +28,35 @@ angular.module('odoo')
             current: null,
             next: null
         };
-        $scope.stageToMove = {};
+        // =======================================================================================================
 
         /**
          *
          */
-        $scope.$on("$ionicSlides.sliderInitialized", function (event, data) {
+        $ionicModal.fromTemplateUrl('templates/sales/opportunity.html', {
+            scope: $scope
+        }).then(function (modal) {
+            $scope.modal = modal;
+        });
+
+        /**
+         *
+         */
+        $scope.$on('$ionicSlides.sliderInitialized', function (event, data) {
             $scope.slider = data.slider;
         });
 
         /**
          * 
          */
-        $scope.$on("$ionicSlides.slideChangeStart", function (event, data) {
+        $scope.$on('$ionicSlides.slideChangeStart', function (event, data) {
             $scope.loading = true;
         });
 
         /**
          *
          */
-        $scope.$on("$ionicSlides.slideChangeEnd", function (event, data) {
+        $scope.$on('$ionicSlides.slideChangeEnd', function (event, data) {
             $scope.loading = false;
             $scope.stageChanged(data.slider.activeIndex);
         });
@@ -51,10 +64,17 @@ angular.module('odoo')
         /**
          *
          */
-        $scope.$on("$ionicView.enter", function () {
+        $scope.$on('$ionicView.enter', function () {
             $scope.initialize();
         });
 
+        /**
+         *
+         */
+        $scope.$on('$destroy', function () {
+            $scope.modal.remove();
+        });
+
         /**
          *
          */
@@ -129,6 +149,26 @@ angular.module('odoo')
             });
         }
 
+        /**
+         *
+         */
+        $scope.filterStages = function () {
+            $scope.stagesToMove = $scope.stages.filter(function (item) {
+                return item.id != $scope.stage.current.id;
+            });
+        }
+
+        /**
+         *
+         */
+        $scope.toogleNew = function () {
+            if ($scope.stages.length > 0) {
+                $scope.opportunity.stage_id = $scope.stages[0].remote_id;
+            }
+
+            $scope.modal.show();
+        }
+
         /**
         *
         */
@@ -141,6 +181,58 @@ angular.module('odoo')
             });
         }
 
+        /**
+         *
+         */
+        $scope.save = function () {
+            opportunitiesDataFactory.save($scope.opportunity, function (opportunityId) {
+                $scope.modal.hide();
+
+                console.log($scope.opportunity);
+
+                if (!$scope.opportunity.id) {
+                    console.log('Entra aqui');
+                    $scope.opportunity.id = opportunityId;
+                    $scope.opportunities.push($scope.opportunity);
+                }
+
+                $scope.groupOpportunities();
+                $scope.opportunity = {};
+
+                $scope.$apply();
+
+                deviceFactory.toast('Nueva opportunidad creada');
+            }, function (err) { 
+                console.log(err);
+                deviceFactory.toast('No se ha podido guardar la opportunidad');
+            });
+        }
+
+        /**
+         *
+         */
+        $scope.delete = function () {
+            deviceFactory.confirm('Estás seguro que quieres eliminar ésta oportunidad?', 'Confirmar', function (index) { 
+
+                if (index == 1) {
+                    opportunitiesDataFactory.remove($scope.opportunity, function (affected) {
+                        if (affected != 0) {
+                            var index = $scope.opportunities.indexOf($scope.opportunity);
+                            $scope.opportunities.splice(index, 1);
+                            $scope.opportunity = {};
+
+                            $scope.groupOpportunities();
+                            $scope.$apply();
+                        }
+
+                    }, function (err) {
+                        console.log(err);
+                        deviceFactory.toast('No se ha podido eliminar la oportunidad');
+                    });
+                }
+            });
+        }
+
         /**
          * Change the state
          */
@@ -181,43 +273,41 @@ angular.module('odoo')
          * Show availables stages to move
          */
         $scope.showStagesToMove = function () {
-            $ionicPopup.show({
+            $scope.filterStages();
+
+            $scope.selectStage = $ionicPopup.show({
                 scope: $scope,
                 title: 'Mover a',
                 templateUrl: 'templates/sales/crm-stages.html',
-                buttons: [
-                    {
-                        text: 'Mover',
-                        type: 'button-positive',
-                        onTap: function (e) {
-                            // console.log(e);
-                            $scope.moveOpportunity();
-                        }
-                    },
-                    {
-                        text: 'Cancelar',
-                        type: 'button-default',
-                        onTap: function (e) {
-                            // e.preventDefault();
-                        }
-                    }
-                ]
             });
         }
 
-        /**
-         *
-         */
-        $scope.selectStageToMove = function (index) {
-            $scope.stageToMove = $scope.stages[index];
-        }
-
         /**
          * Move opportunity to stage
          */
-        $scope.moveOpportunity = function () {
-            console.log($scope.stageToMove);
-            deviceFactory.toast('Se movió la oportunidad a ' + $scope.stageToMove.name);
+        $scope.moveToStage = function (index) {
+            $scope.selectStage.close();
+
+            var opportunityToMove = $scope.groupedOpportunities[$scope.selectedIndex];
+            var indexToUpdate = $scope.opportunities.indexOf(opportunityToMove);
+            var stageToMove = $scope.stagesToMove[index];
+
+            $scope.selectedIndex = -1;
+            $scope.loading = true;
+
+            opportunitiesDataFactory.changeStage(opportunityToMove, stageToMove.remote_id, function (opportunityId) {
+                $scope.opportunities[indexToUpdate] = opportunityToMove;
+                $scope.groupOpportunities();
+
+                $scope.$apply();
+                $scope.loading = false;
+                
+                deviceFactory.toast('Se movió la oportunidad a ' + $scope.stagesToMove[index].name);
+            }, function (err) {
+
+                $scope.loading = false;
+                deviceFactory.toast('No se ha podido mover la oportunidad');
+            });
         }
 
         /**
@@ -227,7 +317,14 @@ angular.module('odoo')
             deviceFactory.vibrate();
 
             $scope.selectedIndex = index;
-            console.log($scope.opportunities[index]);
+
+            if (index == -1) {
+                $scope.opportunity = {};
+            } else {
+                $scope.opportunity = $scope.groupedOpportunities[index];
+            }
+
+            console.log($scope.opportunity);
 
             $ionicActionSheet.show({
                 titleText: 'Acciones',
@@ -245,17 +342,16 @@ angular.module('odoo')
                     $scope.selectedIndex = -1;
                 },
                 buttonClicked: function (index) {
-                    $scope.selectedIndex = -1;
+                   
 
                     switch (index) {
                         case 0:
-                            $scope.show();
+                            $scope.selectedIndex = -1;
+                            $scope.toogleNew();
                             break;
                         case 1:
                             $scope.showStagesToMove();
                             break;
-                        default:
-                            $scope.show();
                     }
                     return true;
                 },

+ 2 - 2
www/js/factories/sales/lead.storage.factory.js

@@ -29,7 +29,7 @@ angular.module('odoo')
                     .set('priority', data.priority ? data.priority : 2)
                     .set('probability', data.probability ? data.probability : 10)
                     .set('type', data.type ? data.type : 'lead')
-                    .set('stage_id', angular.isArray(data.stage_id) ? data.stage_id[0] : 1)
+                    .set('stage_id', angular.isArray(data.stage_id) ? data.stage_id[0] : (data.stage_id ? data.stage_id : 1))
                     .set('partner_id', data.partner_id ? data.partner_id : 0)
                     .where('id = ?', data.id)
                     .toParam();
@@ -56,7 +56,7 @@ angular.module('odoo')
                     .set('company_currency', angular.isArray(data.company_currency) ? data.company_currency[0] : 0)
                     .set('company_id', angular.isArray(data.company_id) ? data.company_id[0] : configuration.company_id)
                     .set('create_uid', angular.isArray(data.create_uid) ? data.create_uid[0] : configuration.id)
-                    .set('stage_id', angular.isArray(data.stage_id) ? data.stage_id[0] : 1)
+                    .set('stage_id', angular.isArray(data.stage_id) ? data.stage_id[0] : (data.stage_id ? data.stage_id : 1))
                     .set('user_id', angular.isArray(data.user_id) ? data.user_id[0] : configuration.id)
                     .set('user_login', data.user_login ? data.user_login : configuration.user)
                     .set('partner_id', data.partner_id ? data.partner_id : 0)

+ 1 - 1
www/js/factories/sales/opportunity.storage.factory.js

@@ -34,7 +34,7 @@ angular.module('odoo')
                     toParam();
             } else {
                 query = squel.delete()
-                    .from('lead')
+                    .from('crm_lead')
                     .where('id = ?', data.id)
                     .toParam();
             }

+ 37 - 3
www/js/factories/sales/opportunity.sync.factory.js

@@ -57,6 +57,29 @@ angular.module('odoo')
             });
         }
 
+        /**
+         *
+         */
+        var changeStage = function (opportunity, stageId, success, error) {
+            opportunity.stage_id = stageId;
+
+            opportunitiesStorageFactory.save(opportunity, function (opportunityId) {
+                success(opportunityId);
+            }, function (err) { 
+                error(err);
+            });
+        }
+
+        /**
+         *
+         */
+        var save = function (opportunity, success, error) {
+            opportunitiesStorageFactory.save(opportunity, function (opportunityId) {
+                success(opportunityId);
+            }, function (err) { 
+                error(err);
+            });
+        }
         /**
          *
          */
@@ -85,6 +108,17 @@ angular.module('odoo')
             });
         }
 
+        /**
+         *
+         */
+        var remove = function (opportunity, success, error) {
+            opportunitiesStorageFactory.remove(opportunity, function (affected) {
+                success(affected);
+            }, function (err) { 
+                error(err);
+            });
+        }
+
         /**
          *
          */
@@ -116,8 +150,6 @@ angular.module('odoo')
                 asyncLoopFactory(updatedOpportunities.length, function (loop) {
                     var data = updatedOpportunities.item(loop.iteration());
 
-                    console.log(data);
-
                     push(data.remote_id, data, function (response) {
                         loop.next();
                     }, function (pushErr) {
@@ -222,8 +254,10 @@ angular.module('odoo')
             pull: pull,
             push: push,
             destroy: destroy,
+            save: save,
+            changeStage: changeStage,
             getAll: getAll,
+            remove: remove,
             sync: sync
-
         }
     });

+ 1 - 1
www/templates/sales/crm-stages.html

@@ -1 +1 @@
-<ion-radio icon="ion-checkmark-round" ng-repeat="s in stages" ng-click="selectStageToMove($index)">{{ s.name | translate }}</ion-radio>
+<ion-radio icon="ion-checkmark-round" ng-repeat="s in stagesToMove" ng-click="moveToStage($index)">{{ s.name | translate }}</ion-radio>

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 0 - 3
www/templates/sales/customers.html


+ 54 - 0
www/templates/sales/opportunity.html

@@ -0,0 +1,54 @@
+<ion-modal-view>
+    <ion-header-bar class="bar bar-positive">
+        <h1 class="title">Oportunidad</h1>
+        <div class="buttons">
+            <button class="button button-clear ion-checkmark-round" style="font-size:22px !important; padding-left: 5px;" type="submit" form="opportunity-form" ng-disabled="!opportunity.name"></button>
+        </div>
+   </ion-header-bar>
+    <ion-content>
+        <form id="opportunity-form" ng-submit="save()">
+            <div class="list">
+                <label class="item item-input item-select">
+                    <div class="input-label">
+                        Estado
+                    </div>
+                    <select ng-model="opportunity.stage_id">
+                        <option ng-repeat="s in stages" ng-selected="{{ opportunity.stage_id == s.remote_id}}" value="{{ s.remote_id }}">{{ s.name | translate }}</option>
+                    </select>
+                </label>
+                <label class="item item-input item-stacked-label">
+                    <span class="input-label">Asunto</span>
+                    <input type="text" name="name" autofocus="autofocus" ng-model="opportunity.name">
+                </label>
+                <label class="item item-input item-stacked-label">
+                    <span class="input-label">Contacto</span>
+                    <input type="text" ng-model="opportunity.contact_name">
+                </label>
+                <label class="item item-input item-stacked-label">
+                    <span class="input-label">Dirección</span>
+                    <input type="text" ng-model="opportunity.street">
+                </label>
+                <label class="item item-input item-stacked-label">
+                    <span class="input-label">Dirección</span>
+                    <input type="text" ng-model="opportunity.street2">
+                </label>
+                <label class="item item-input item-stacked-label">
+                    <span class="input-label">Teléfono</span>
+                    <input type="tel" ng-model="opportunity.phone">
+                </label>
+                <label class="item item-input item-stacked-label">
+                    <span class="input-label">Celular</span>
+                    <input type="tel" ng-model="opportunity.mobile">
+                </label>
+                <label class="item item-input item-stacked-label">
+                    <span class="input-label">Fax</span>
+                    <input type="tel" ng-model="opportunity.fax">
+                </label>
+                <label class="item item-input item-stacked-label">
+                    <span class="input-label">Nota</span>
+                    <textarea rows="8" cols="40" ng-model="opportunity.description"></textarea>
+                </label>
+            </div>
+        </form>
+    </ion-content>
+</ion-modal-view>

Niektoré súbory nie sú zobrazené, pretože je v týchto rozdielových dátach zmenené mnoho súborov