Browse Source

move transform cart in odoo compatible model method in cart model

robert2206 8 years ago
parent
commit
de9ffd6070
4 changed files with 45 additions and 7 deletions
  1. 2 0
      package.json
  2. 0 2
      src/base/base-view.ts
  3. 38 1
      src/pages/order/models/cart.ts
  4. 5 4
      src/pages/order/order.ts

+ 2 - 0
package.json

@@ -27,9 +27,11 @@
     "font-awesome": "^4.7.0",
     "ionic-angular": "2.3.0",
     "ionicons": "3.0.0",
+    "moment": "^2.18.1",
     "pouchdb": "^6.1.2",
     "pouchdb-find": "^0.10.5",
     "rxjs": "5.0.1",
+    "slugid": "^1.1.0",
     "sw-toolbox": "3.4.0",
     "zone.js": "0.7.2"
   },

+ 0 - 2
src/base/base-view.ts

@@ -28,8 +28,6 @@ export abstract class BaseView<T> {
         this.fields = getMetadataStorage().fields.filterByTarget(this.type.constructor).items;
         this.injector = ReflectiveInjector.resolveAndCreate(injectables);
         this.title = "Sin título";
-
-        console.log(this.getFieldsRelated());
     }
 
     // ------------------------------------------------------------

+ 38 - 1
src/pages/order/models/cart.ts

@@ -1,6 +1,12 @@
 import { Partner } from "../../../odoo/models/res.partner";
 import { ProductProduct } from "../../../odoo/models/product.product";
-import { CartItem } from "./cart-item"
+import { CartItem } from "./cart-item";
+
+import { SaleOrder } from "../../../odoo/models/sale.order";
+import { SaleOrderLine } from "../../../odoo/models/sale.order.line";
+
+import * as Moment from "moment";
+import * as SlugId from "slugid";
 
 export class Cart {
 
@@ -78,6 +84,37 @@ export class Cart {
         return this.getItems().length;
     }
 
+    /**
+     * 
+     */
+    toOdoo(): any {
+        let order = new SaleOrder();
+        order.name = "MO/" + SlugId.v4();
+        order.order_line = [];
+        order.cart_quantity = this.size();
+        order.amount_total = this.getTotal();
+        order.date_order = Moment(new Date()).format("YYYY-MM-DD HH:mm:ss");
+
+        let orderLine: SaleOrderLine = null;
+        let item: CartItem = null;
+
+        for (let i = 0; i < this.size(); i++) {
+            item = this.getItem(i);
+
+            orderLine = new SaleOrderLine();
+            orderLine.product_id = item.getProduct().odoo_id;
+            orderLine.price_unit = item.getPrice();
+            orderLine.product_uom_qty = item.getQuantity();
+            orderLine.product_uos_qty = item.getQuantity();
+            orderLine.price_subtotal = item.getSubtotal();
+
+            order.order_line.push(orderLine);
+        }
+
+        console.log(order);
+        
+    }
+
     /**
      * 
      * @param item 

+ 5 - 4
src/pages/order/order.ts

@@ -1,4 +1,4 @@
-import {  Component } from '@angular/core';
+import { Component } from '@angular/core';
 import { NavController, NavParams, ActionSheetController, AlertController } from 'ionic-angular';
 
 import { SaleOrder } from "../../odoo/models/sale.order";
@@ -14,6 +14,8 @@ import { CartItem } from "./models/cart-item"
 
 import { EventsManager } from "../../base/events/event-manager";
 
+import * as Moment from "moment";
+
 @Component({
     selector: 'page-order',
     templateUrl: 'order.html'
@@ -26,7 +28,7 @@ export class OrderPage extends BaseDetailsView<SaleOrder> {
         public navCtrl: NavController,
         public navParams: NavParams,
         public actionSheetCtrl: ActionSheetController,
-        public alertCtrl: AlertController,
+        public alertCtrl: AlertController
     ) { 
         super(SaleOrder, navParams.data.item, navParams.data.kind);
 
@@ -288,7 +290,6 @@ export class OrderPage extends BaseDetailsView<SaleOrder> {
      * @param data 
      */
     submit() { 
-        console.log(this.getCart());
-        
+        this.getCart().toOdoo();
     }
 }