Explorar el Código

[ADD] create supplier and product on the fly

Gogs hace 7 años
padre
commit
7535b80abb

+ 42 - 2
controllers/main.py

@@ -208,7 +208,24 @@ class Purchases(http.Controller):
     @http.route('/eiru_purchases/create_supplier', type='json', auth='user', methods=['POST'], cors='*')
     def create_supplier(self, **kw):
         self.make_info_log('Creating supplier')
-        print(kw)
+
+        supplier = request.env['res.partner'].create({
+            'name': kw.get('name'),
+            'ruc': kw.get('ruc'),
+            'phone': kw.get('phone'),
+            'supplier': True,
+            'customer': False
+        })
+
+        return {
+            'id': supplier.id,
+            'name': supplier.name,
+            'displayName': supplier.display_name,
+            'imageMedium': supplier.image_medium,
+            'phone': supplier.phone,
+            'mobile': supplier.mobile,
+            'email': supplier.email
+        }
 
     '''
         Create product and return data
@@ -216,7 +233,30 @@ class Purchases(http.Controller):
     @http.route('/eiru_purchases/create_product', type='json', auth='user', methods=['POST'], cors='*')
     def create_product(self, **kw):
         self.make_info_log('Creating product')
-        print(kw)
+
+        product = request.env['product.template'].create({
+            'name': kw.get('name'),
+            'standard_price': float(kw.get('price')),
+            'ean13': kw.get('ean13')
+        })
+
+        return {
+            'id': product.id,
+            'name': product.name,
+            'displayName': product.display_name,
+            'ean13': product.ean13,
+            'imageMedium': product.image_medium,
+            'listPrice': product.list_price,
+            'variantCount': product.product_variant_count,
+            'variants': [{
+                'id': variant.id,
+                'name': variant.name,
+                'displayName': variant.display_name,
+                'ean13': variant.ean13,
+                'imageMedium': variant.image_medium,
+                'listPrice': variant.list_price
+            } for variant in product.product_variant_ids if variant.active]
+        }
 
     '''
         Create purchase resource route

+ 1 - 1
src/components/product/ProductsStep.vue

@@ -2,7 +2,7 @@
     .purchase-step
         .products-selector
             searcher(:items='products' :keys="['name', 'displayName']" @onSearch='filterProducts')
-            card-grid(:items='visibleProducts' @onAdd='showProductForm' @onSelect='selectProduct')
+            card-grid(:items='visibleProducts' canAdd @onAdd='showProductForm' @onSelect='selectProduct')
             product-form
         cart
 </template>

+ 1 - 1
src/components/supplier/SupplierStep.vue

@@ -3,7 +3,7 @@
         .supplier-selection-step
             .supplier-selector
                 searcher(:items='suppliers' :keys="['name', 'displayName']" @onSearch='filterSuppliers')
-                card-grid(:items='visibleSuppliers' @onAdd='showSupplierForm' @onSelect='selectSupplier')
+                card-grid(:items='visibleSuppliers' canAdd @onAdd='showSupplierForm' @onSelect='selectSupplier')
                 supplier-form
             transition(name='slide-fade')
                 supplier-details(v-if='!!supplierSelected')

+ 7 - 6
src/store/actions.js

@@ -43,11 +43,11 @@ const actions = {
      * @param {*} payload 
      */
     createSupplier({ commit }, payload) {
-        let data = {
+        const data = {
             jsonrpc: '2.0',
             method: 'call',
             params: {
-                payload
+                ...payload
             }
         }
 
@@ -70,11 +70,11 @@ const actions = {
      * @param {*} payload 
      */
     createProduct({ commit }, payload) {
-        let data = {
+        const data = {
             jsonrpc: '2.0',
             method: 'call',
             params: {
-                payload
+                ...payload
             }
         }
 
@@ -96,7 +96,7 @@ const actions = {
      * @param {*} param0 
      */
     createPurchase({ getters, dispatch }) {
-        let data = {
+        const data = {
             jsonrpc: '2.0',
             method: 'call',
             params: {
@@ -105,7 +105,8 @@ const actions = {
         }
 
         return axios.post(createUrl, data).then(response => {
-            dispatch('resetPurchase')
+            console.log(response)
+            // dispatch('resetPurchase')
         }).catch(error => {
             console.log(error)
         })

+ 0 - 4
src/store/modules/supplier.js

@@ -11,10 +11,6 @@ const state = {
         default: null,
         value: null
     },
-    addSupplier: {
-        default: false,
-        value: false
-    },
     showSupplierForm: {
         default: false,
         value: false