Browse Source

manager can create products (auto assigned to pointsale) and categories

jose miguel 7 years ago
parent
commit
3ec6c02a2c

+ 7 - 1
app/controllers/products_controller.rb

@@ -89,6 +89,7 @@ class ProductsController < ApplicationController
 
   # POST /products
   # POST /products.json
+  # rubocop:disable Metrics/BlockLength
   def create
     @with_presentation = true
     @product = Product.new(product_params)
@@ -99,7 +100,7 @@ class ProductsController < ApplicationController
     @product.audit_comment = message
     respond_to do |format|
       if @product.save
-        @product.save_variants
+        @product.save_variants(current_user)
         ##--- Para cuando se agrega un producto desde purchase
         if params[:remoto] == "true"
           ##--- Guardar pre_purchase
@@ -118,6 +119,10 @@ class ProductsController < ApplicationController
           format.json { head :no_content }
           format.js
         else
+          # crear available product para el p.v, cuando es sin variantes
+          if current_user.usertype == 'G' && !@product.presentation && !@product.is_parent
+            AvailableProduct.create(product_id: @product.id, pointsale_id: current_user.pointsale_id, stock: 0)
+          end
           format.html { redirect_to products_url, success: message }
           format.json { render :show, status: :created, location: @product }
         end
@@ -127,6 +132,7 @@ class ProductsController < ApplicationController
       end
     end
   end
+  # rubocop:enable Metrics/BlockLength
 
   # PATCH/PUT /products/1
   # PATCH/PUT /products/1.json

+ 2 - 2
app/models/ability.rb

@@ -40,9 +40,9 @@ class Ability
 
     elsif user.usertype == "G"
       # Cajas registradoras
-      can :manage, [CashRegister, Purchase, Product, PrePurchase, Seller, Sale, Expense, ProductWaste, Transfer, OpenCashRegister, CashOut, Supplier, Customer, Credit, CreditPayment, Commission, Sellerscommission, ProductsReturn]
+      can :manage, [CashRegister, Purchase, Product, PrePurchase, Seller, Sale, Expense, ProductWaste, Transfer, OpenCashRegister, CashOut, Supplier, Customer, Credit, CreditPayment, Commission, Sellerscommission, ProductsReturn, Category]
       # Categorias
-      can :read, [Category, SpecialPrice, Expensesconcept, Credit, CreditPayment, Unit]
+      can :read, [SpecialPrice, Expensesconcept, Credit, CreditPayment, Unit]
       # Clientes
       can :cru, [Customer, BillingInformation, Pointsale, User, Warehouse, Credit, CreditPayment, Commission, Sellerscommission]
 

+ 6 - 1
app/models/product.rb

@@ -163,7 +163,8 @@ class Product < ActiveRecord::Base
     end
   end
 
-  def save_variants
+  # rubocop:disable Metrics/BlockLength
+  def save_variants(current_user)
     Thread.new do
       combinations = Array.new
       attributes = Array.new
@@ -190,10 +191,14 @@ class Product < ActiveRecord::Base
 
           @products_variant.attributes_json = attributes_json.to_json
           @products_variant.save
+          if current_user.usertype == 'G'
+            AvailableProduct.create(product_id: @products_variant.id, pointsale_id: current_user.pointsale_id, stock: 0)
+          end
         end
       end
     end
   end
+  # rubocop:enable Metrics/BlockLength
 
   def assign_attributes_to_variant(attri, parent_id, attributes_json)
     attri_id = ActsAsTaggableOn::Tag.where("lower(name) = lower(?)", attri).select(:id).first

+ 1 - 1
app/views/products/index.html.erb

@@ -44,7 +44,7 @@
 												<span class="caption-subject bold uppercase">Lista de productos</span>
 											</div>
 											<div class="actions">
-												<% if current_user.usertype == 'A' %>
+												<% if current_user.usertype == 'A' || current_user.usertype == 'G' %>
 													<%= link_to new_product_path(:filter => @filter, :current_page => @current_page), {:class=>"btn bold green pull-right filtros"} do %>
 														Nuevo Producto <i class="fa fa-plus"></i>
 													<% end %>

+ 7 - 1
config/navigation.rb

@@ -21,6 +21,8 @@ module SimpleNavigationn
             else
               list << content_tag(:li, item.name[:text], class: 'active ') if item.selected?
             end
+          else
+            next
           end
           # rubocop:enable Style/IfInsideElse
         end
@@ -139,7 +141,11 @@ SimpleNavigation::Configuration.run do |navigation|
       primary.item :products, { icon: "fa fa-fw fa-cubes", text: "Productos" }, products_path, class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
         sub_nav.dom_attributes = { class: 'dropdown-menu pull-left' }
         sub_nav.item :units, 'Unidades de medida', units_path
-        sub_nav.item :list_categories, 'Lista de líneas de productos', categories_path
+        sub_nav.item :divider_before_categories, '#', divider: true
+        sub_nav.item :new_category, 'Nueva línea de producto', new_category_path
+        sub_nav.item :list_categories, 'Lista de líneas de producto', categories_path
+        sub_nav.item :divider_before_products, '#', divider: true
+        sub_nav.item :new_product, 'Nuevo Producto', new_product_path
         sub_nav.item :list_products, 'Lista de productos', products_path
         sub_nav.item :divider_after_list_products, '#', divider: true
         sub_nav.item :stock_by_pointsale, 'Existencias', stock_by_pointsale_path