|
@@ -1,9 +1,7 @@
|
|
|
angular.module(
|
|
|
'odoo.customer.controller',
|
|
|
[
|
|
|
- 'odoo.interoperability.factory',
|
|
|
- 'odoo.storage.factory',
|
|
|
- 'ngCordova'
|
|
|
+ 'odoo.sync.factory'
|
|
|
]
|
|
|
)
|
|
|
|
|
@@ -14,11 +12,11 @@ angular.module(
|
|
|
$ionicModal,
|
|
|
$ionicActionSheet,
|
|
|
$ionicPopup,
|
|
|
- $cordovaContacts,
|
|
|
- $cordovaCamera,
|
|
|
sync,
|
|
|
odoo,
|
|
|
- storage
|
|
|
+ storage,
|
|
|
+ camera,
|
|
|
+ contact
|
|
|
) {
|
|
|
|
|
|
// Objects
|
|
@@ -44,7 +42,7 @@ angular.module(
|
|
|
$scope.customer = {};
|
|
|
});
|
|
|
|
|
|
- // Fill view list
|
|
|
+ // Fill view list from data readed from local database
|
|
|
$scope.fill = function () {
|
|
|
$ionicLoading.show();
|
|
|
|
|
@@ -69,6 +67,7 @@ angular.module(
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ // Get filtered customers for correct data visualization
|
|
|
$scope.getCustomers = function (success, error) {
|
|
|
storage.getByConstraint('partner', 'customer = 1', function (customers) {
|
|
|
console.log(customers);
|
|
@@ -85,6 +84,7 @@ angular.module(
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ // Show action sheet for customer options
|
|
|
$scope.openOptions = function(index) {
|
|
|
if (index == -1) {
|
|
|
$scope.customer = {};
|
|
@@ -130,6 +130,7 @@ angular.module(
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ // Save a customer data on local database
|
|
|
$scope.save = function() {
|
|
|
storage.saveCustomer($scope.customer, function (customerId) {
|
|
|
if (!$scope.customer.id) {
|
|
@@ -146,28 +147,7 @@ angular.module(
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- $scope.takePicture = function () {
|
|
|
- var options = {
|
|
|
- quality: 75,
|
|
|
- destinationType: Camera.DestinationType.DATA_URL,
|
|
|
- sourceType: Camera.PictureSourceType.CAMERA,
|
|
|
- allowEdit: true,
|
|
|
- encodingType: Camera.EncodingType.JPEG,
|
|
|
- targetWidth: 300,
|
|
|
- targetHeight: 300,
|
|
|
- popoverOptions: CameraPopoverOptions,
|
|
|
- saveToPhotoAlbum: false,
|
|
|
- correctOrientation:true
|
|
|
- };
|
|
|
-
|
|
|
- $cordovaCamera.getPicture(options).then(function(imageData) {
|
|
|
- $scope.customer.image_small = imageData;
|
|
|
- $scope.customer.image_medium = imageData;
|
|
|
- }, function(err) {
|
|
|
- $log.error(JSON.stringify(err));
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
+ // Delete a customer from local database
|
|
|
$scope.delete = function () {
|
|
|
$ionicPopup.confirm({
|
|
|
title: 'Confirmar',
|
|
@@ -190,64 +170,27 @@ angular.module(
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ // Show customer data in modal
|
|
|
$scope.show = function () {
|
|
|
$scope.customerModal.show();
|
|
|
}
|
|
|
|
|
|
- $scope.addContact = function () {
|
|
|
- if(!$scope.customer.mobile && !$scope.customer.phone && !$scope.customer.email) {
|
|
|
- $ionicPopup.alert({ title: 'No se puede guardar el contacto', template: 'El cliente no tiene registrado un teléfono, celular y email'});
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- var contact = {
|
|
|
- name: {
|
|
|
- givenName: $scope.customer.name,
|
|
|
- familyName: '',
|
|
|
- formatted: ''
|
|
|
- },
|
|
|
- nickname: '',
|
|
|
- phoneNumbers: [
|
|
|
- {
|
|
|
- value: $scope.customer.phone,
|
|
|
- type: 'phone'
|
|
|
- },
|
|
|
- {
|
|
|
- value: $scope.customer.mobile,
|
|
|
- type: 'mobile'
|
|
|
- }
|
|
|
- ],
|
|
|
- emails: [
|
|
|
- {
|
|
|
- value: $scope.customer.email,
|
|
|
- type: 'home'
|
|
|
- }
|
|
|
- ],
|
|
|
- addresses: [
|
|
|
- {
|
|
|
- type: 'home',
|
|
|
- formatted: '',
|
|
|
- streetAddress: $scope.customer.street,
|
|
|
- locality: $scope.customer.city,
|
|
|
- region: '',
|
|
|
- postalCode: '',
|
|
|
- country: 'Paraguay'
|
|
|
- }
|
|
|
- ],
|
|
|
- ims: null,
|
|
|
- organizations: null,
|
|
|
- birthday: null,
|
|
|
- note: null,
|
|
|
- photos: null,
|
|
|
- categories: null,
|
|
|
- urls: null
|
|
|
- };
|
|
|
-
|
|
|
- $cordovaContacts.save(contact).then(function (result) {
|
|
|
- $ionicPopup.alert({ title: 'Contacto creado con éxito' });
|
|
|
- }, function (err) {
|
|
|
- $ionicPopup.alert({ title: 'No se puedo eliminar el cliente', template: JSON.stringify(error) });
|
|
|
- $log.error(JSON.stringify(err));
|
|
|
+ // Take a picture from camera for customer profile
|
|
|
+ $scope.takePicture = function () {
|
|
|
+ camera.takePicture(function (imageData) {
|
|
|
+ $scope.customer.image_small = imageData;
|
|
|
+ $scope.customer.image_medium = imageData;
|
|
|
+ }, function (error) {
|
|
|
+ console.log(error);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ // Add customer data contact to device mobile contacts
|
|
|
+ $scope.addContact = function () {
|
|
|
+ contact.save($scope.customer, function (result) {
|
|
|
+ $ionicPopup.alert({ title: 'Contacto guardado' });
|
|
|
+ }, function (error) {
|
|
|
+ console.log(error);
|
|
|
+ })
|
|
|
+ }
|
|
|
});
|