|
@@ -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
|