浏览代码

sincronización de atributos de productos modificados

robert2206 8 年之前
父节点
当前提交
5153ab3348
共有 2 个文件被更改,包括 31 次插入3 次删除
  1. 2 1
      src/providers/data-provider.ts
  2. 29 2
      src/providers/sync/product-attribute-line-sync-provider.ts

+ 2 - 1
src/providers/data-provider.ts

@@ -15,7 +15,8 @@ export class DataProvider {
         PRODUCT_TEMPLATE: 'product.template',
         PRODUCT_ATTRIBUTE: 'product.attribute',
         PRODUCT_ATTRIBUTE_LINE: 'product.attribute.line',
-        PRODUCT_ATTRIBUTE_VALUE: 'product.attribute.value'
+        PRODUCT_ATTRIBUTE_VALUE: 'product.attribute.value',
+        PRODUCT_PRODUCT: 'product.product'
     };
 
     db: any;

+ 29 - 2
src/providers/sync/product-attribute-line-sync-provider.ts

@@ -15,8 +15,14 @@ export class ProductAttributeLineSyncProvider {
      */
     doSync(): Promise<any> {
         return new Promise((reject, resolve) => {
-            this.odooProvider.get('product_attribute_line').then(lines => {
+
+            this.getUpdatedLines().then(lines => { 
                 return lines;
+            }).then(lines => {
+                return this.odooProvider.post('product_attribute_line', lines);
+            }).then(response => {
+                console.log('product_attribute_line: product attribute lines modified sended');
+                return this.odooProvider.get('product_attribute_line');
             }).then(lines => {
                 return this.storeLines(lines);
             }).then(() => {
@@ -29,7 +35,28 @@ export class ProductAttributeLineSyncProvider {
 
     }
 
-        /**
+     /**
+     *
+     */
+    private getUpdatedLines(): Promise<any> {
+        return new Promise((resolve, reject) => {
+            this.dataProvider.getAll(DataProvider.DOCS.PRODUCT_ATTRIBUTE_LINE).then(lines => {
+                lines = lines.filter(item => {
+                    return item.doc_state === "updated" && item.remote_id;
+                });
+                
+                resolve(lines.map(item => {
+                    delete item.id;
+                    return item;
+                }));
+            }).catch(e => {
+                reject(e);
+            });
+        });
+    }
+
+
+    /**
      *
      */
     private storeLines(lines: Array<any>): Promise<any> {