diff --git a/plugins/orders/features/purchases.feature b/plugins/orders/features/purchases.feature new file mode 100644 index 0000000..475ce6f --- /dev/null +++ b/plugins/orders/features/purchases.feature @@ -0,0 +1,113 @@ +Feature: purchases + As an enterprise's client + I want to view my purchases + In order to manage the products I bought + + Background: + Given "ShoppingCart" plugin is enabled + And "Orders" plugin is enabled + And the following users + | login | name | email | + | moe | Moe | moe@springfield.com | + | homer | Homer | homer@springfield.com | + And the following enterprise + | identifier | name | owner | + | moes-tavern | Moes Tavern | moe | + And the shopping basket is enabled on "Moes Tavern" + And the following product_categories + | name | + | Beer | + | Snacks | + And the following products + | owner | category | name | price | + | moes-tavern | beer | Duff | 3.00 | + | moes-tavern | snacks | French fries | 7.00 | + And feature "products_for_enterprises" is enabled on environment + And I am logged in as "homer" + And I am on homer's control panel + + @selenium + Scenario: view orders + Given the following purchase from "homer" on "moes-tavern" that is "ordered" + | product | quantity | price | + | Duff | 3 | 3.50 | + | French fries | 1 | 7.00 | + When I follow "Purchases made" + Then I should see "Moes Tavern" within any ".actor-name" + And I should see "17.50" within any ".total" + And I should see "Ordered" within any ".situation" + + @selenium + Scenario: view orders with different status + Given the following purchase from "homer" on "moes-tavern" that is "accepted" + | product | quantity | price | + | Duff | 2 | 3.50 | + And the following purchase from "homer" on "moes-tavern" that is "delivered" + | product | quantity | price | + | French fries | 1 | 7.00 | + When I follow "Purchases made" + Then I should see "Accepted" within any ".situation" + And I should see "Delivered" within any ".situation" + + @selenium + Scenario: filter orders by situation + Given the following purchase from "homer" on "moes-tavern" that is "accepted" + | product | quantity | price | + | Duff | 2 | 3.50 | + And the following purchase from "homer" on "moes-tavern" that is "delivered" + | product | quantity | price | + | French fries | 1 | 7.00 | + And I follow "Purchases made" + And I should see "Accepted" within any ".situation" + And I should see "Delivered" within any ".situation" + And I select "Delivered" from "Status" + When I press "Filter" + Then I should not see "Accepted" within any ".situation" + And I should see "Delivered" within any ".situation" + + + @selenium + Scenario: filter orders by code + Given the following purchase from "homer" on "moes-tavern" that is "ordered" + | product | quantity | price | + | Duff | 2 | 3.50 | + And the following purchase from "homer" on "moes-tavern" that is "ordered" + | product | quantity | price | + | French fries | 1 | 7.00 | + And I follow "Purchases made" + And I should see "1" within any ".code" + And I should see "2" within any ".code" + And I fill in "Code" with "2" + When I press "Filter" + Then I should not see "1" within any ".code" + Then I should see "2" within any ".code" + + + @selenium + Scenario: filter orders by supplier + Given the following users + | login | name | email | + | lovejoy | Reverend Lovejoy | lovejoy@springfield.com | + And the following enterprise + | identifier | name | owner | + | first-church-of-springfield | First Church of Springfield | lovejoy | + And the shopping basket is enabled on "First Church of Springfield" + And the following product_categories + | name | + | Holy | + And the following products + | owner | category | name | price | + | first-church-of-springfield | holy | Wine | 5.00 | + And the following purchase from "homer" on "moes-tavern" that is "ordered" + | product | quantity | price | + | French fries | 1 | 7.00 | + And the following purchase from "homer" on "first-church-of-springfield" that is "ordered" + | product | quantity | price | + | Wine | 5 | 10.50 | + And I follow "Purchases made" + And I should see "Moes Tavern" within any ".actor-name" + And I should see "First Church of Springfield" within any ".actor-name" + And I select "Moes Tavern" from "Supplier" + When I press "Filter" + Then I should see "Moes Tavern" within any ".actor-name" + And I should not see "First Church of Springfield" within any ".actor-name" diff --git a/plugins/orders/features/sales.feature b/plugins/orders/features/sales.feature new file mode 100644 index 0000000..e5803fd --- /dev/null +++ b/plugins/orders/features/sales.feature @@ -0,0 +1,104 @@ +Feature: sales + As an enterprise's administrator + I want to view my sales + In order to manage the products I sold + + Background: + Given "ShoppingCart" plugin is enabled + And "Orders" plugin is enabled + And the following users + | login | name | email | + | moe | Moe | moe@springfield.com | + | homer | Homer | homer@springfield.com | + And the following enterprise + | identifier | name | owner | + | moes-tavern | Moes Tavern | moe | + And "Moe" is admin of "Moes Tavern" + And the shopping basket is enabled on "Moes Tavern" + And the following product_categories + | name | + | Beer | + | Snacks | + And the following products + | owner | category | name | price | + | moes-tavern | beer | Duff | 3.00 | + | moes-tavern | snacks | French fries | 7.00 | + And feature "products_for_enterprises" is enabled on environment + And I am logged in as "moe" + And I am on moes-tavern's control panel + + @selenium + Scenario: view orders + Given the following purchase from "homer" on "moes-tavern" that is "ordered" + | product | quantity | price | + | Duff | 3 | 3.50 | + | French fries | 1 | 7.00 | + When I follow "Purchases and Sales" + Then I should see "Homer" within any ".actor-name" + And I should see "17.50" within any ".total" + And I should see "Ordered" within any ".situation" + + @selenium + Scenario: view orders with different status + Given the following purchase from "homer" on "moes-tavern" that is "accepted" + | product | quantity | price | + | Duff | 2 | 3.50 | + And the following purchase from "homer" on "moes-tavern" that is "delivered" + | product | quantity | price | + | French fries | 1 | 7.00 | + When I follow "Purchases and Sales" + Then I should see "Accepted" within any ".situation" + And I should see "Delivered" within any ".situation" + + @selenium + Scenario: filter orders by situation + Given the following purchase from "homer" on "moes-tavern" that is "accepted" + | product | quantity | price | + | Duff | 2 | 3.50 | + And the following purchase from "homer" on "moes-tavern" that is "delivered" + | product | quantity | price | + | French fries | 1 | 7.00 | + And I follow "Purchases and Sales" + And I should see "Accepted" within any ".situation" + And I should see "Delivered" within any ".situation" + And I select "Delivered" from "Status" + When I press "Filter" + Then I should not see "Accepted" within any ".situation" + And I should see "Delivered" within any ".situation" + + + @selenium + Scenario: filter orders by code + Given the following purchase from "homer" on "moes-tavern" that is "ordered" + | product | quantity | price | + | Duff | 2 | 3.50 | + And the following purchase from "homer" on "moes-tavern" that is "ordered" + | product | quantity | price | + | French fries | 1 | 7.00 | + And I follow "Purchases and Sales" + And I should see "1" within any ".code" + And I should see "2" within any ".code" + And I fill in "Code" with "2" + When I press "Filter" + Then I should not see "1" within any ".code" + Then I should see "2" within any ".code" + + + @selenium + Scenario: filter orders by consumer + Given the following users + | login | name | email | + | lovejoy | Reverend Lovejoy | lovejoy@springfield.com | + And the following purchase from "homer" on "moes-tavern" that is "ordered" + | product | quantity | price | + | Duff | 5 | 10.50 | + And the following purchase from "lovejoy" on "moes-tavern" that is "ordered" + | product | quantity | price | + | French fries | 1 | 7.00 | + And I follow "Purchases and Sales" + And I should see "Homer" within any ".actor-name" + And I should see "Reverend Lovejoy" within any ".actor-name" + And I select "Homer" from "Consumer" + When I press "Filter" + Then I should see "Homer" within any ".actor-name" + And I should not see "Reverend Lovejoy" within any ".actor-name" diff --git a/plugins/orders/features/step_definitions/orders_steps.rb b/plugins/orders/features/step_definitions/orders_steps.rb new file mode 100644 index 0000000..44f8fea --- /dev/null +++ b/plugins/orders/features/step_definitions/orders_steps.rb @@ -0,0 +1,20 @@ +Given /^the shopping basket is (enabled|disabled) on "([^""]*)"$/ do |status, name| + status = status == 'enabled' + enterprise = Enterprise.find_by_name(name) || Enterprise[name] + settings = enterprise.shopping_cart_settings({:enabled => status}) + settings.save! +end + +Given /^the following purchase from "([^""]*)" on "([^""]*)" that is "([^""]*)"$/ do |consumer_identifier, enterprise_identifier, status, table| + consumer = Person.find_by_name(consumer_identifier) || Person[consumer_identifier] + enterprise = Enterprise.find_by_name(enterprise_identifier) || Enterprise[enterprise_identifier] + order = OrdersPlugin::Purchase.new(:profile => enterprise, :consumer => consumer, :status => status) + + table.hashes.map{|item| item.dup}.each do |item| + product = enterprise.products.find_by_name item[:product] + item = order.items.build({:product => product, :name => item[:product], :quantity_consumer_ordered => item[:quantity], :price => item[:price]}) + item.order = order + end + + order.save! +end diff --git a/plugins/orders/lib/ext/profile.rb b/plugins/orders/lib/ext/profile.rb index 4e3bfe1..e78a842 100644 --- a/plugins/orders/lib/ext/profile.rb +++ b/plugins/orders/lib/ext/profile.rb @@ -20,21 +20,21 @@ class Profile has_many :ordered_items, through: :orders, source: :items, order: 'name ASC' has_many :sales_consumers, through: :sales, source: :consumer - has_many :purchases_consumers, through: :sales, source: :consumer + has_many :purchases_consumers, through: :purchases, source: :consumer has_many :sales_profiles, through: :sales, source: :profile - has_many :purchases_profiles, through: :sales, source: :profile + has_many :purchases_profiles, through: :purchases, source: :profile def sales_all_consumers consumers = self.sales_consumers.order 'name ASC' - consumers.concat self.suppliers.except_self.order('name ASC') if self.respond_to? :suppliers - consumers.uniq - end - def purchases_all_consumers - consumers = self.purchases_consumers.order 'name ASC' consumers.concat self.consumers.except_self.order('name ASC') if self.respond_to? :consumers consumers.uniq end + def purchases_all_suppliers + suppliers = self.purchases_profiles.order 'name ASC' + suppliers.concat self.suppliers.except_self.order('name ASC') if self.respond_to? :suppliers + suppliers.uniq + end def self.create_orders_manager_role env_id env = Environment.find env_id diff --git a/plugins/orders/views/orders_plugin_admin/_filter_fields.html.slim b/plugins/orders/views/orders_plugin_admin/_filter_fields.html.slim index 6750f0d..0407471 100644 --- a/plugins/orders/views/orders_plugin_admin/_filter_fields.html.slim +++ b/plugins/orders/views/orders_plugin_admin/_filter_fields.html.slim @@ -3,21 +3,21 @@ div= render 'orders_plugin/shared/daterangepicker/init' .field.state - label= t'views.filter.status' + label for="status" = t'views.filter.status' div= select_tag :status, options_for_select([[t('views.filter.all'), ""]] + OrdersPlugin::Order::StatusText.map{ |id, name| [t(name), id] }, params[:status]) .field.code - label= t'views.filter.code' + label for="code" = t'views.filter.code' div= text_field_tag :code, params[:code] div class="field #{actor_name}" - label= t"terms.#{actor_name}.singular", transformation: :capitalize + label for="#{actor_name}_id" = t"terms.#{actor_name}.singular", transformation: :capitalize div= select_tag "#{actor_name}_id", options_for_select([[t('views.filter.all'), ""]] + actors.map{ |a| [a.name, a.id] }, params["#{actor_name}_id"]) .field.delivery - label= t'views.filter.delivery' + label for="delivery_method_id" = t'views.filter.delivery' div= select_tag :delivery_method_id, options_for_select([[t('views.filter.all'), ""]] + orders_owner.delivery_methods.map{ |dm| [dm.name, dm.id] }, params[:delivery_method_id]) diff --git a/plugins/orders/views/orders_plugin_admin/_index.html.erb b/plugins/orders/views/orders_plugin_admin/_index.html.erb index 12ca3ce..5ac36b3 100644 --- a/plugins/orders/views/orders_plugin_admin/_index.html.erb +++ b/plugins/orders/views/orders_plugin_admin/_index.html.erb @@ -12,14 +12,14 @@ <% if @purchases.present? %>
- <%= render 'orders_plugin_admin/purchases', actors: profile.sales_all_consumers, + <%= render 'orders_plugin_admin/purchases', actors: profile.purchases_all_suppliers, orders_owner: profile, orders: @purchases, month: @purchases_month, year: @purchases_year, wireframe_size: false %>
<% end %> <% if @sales.present? %>
- <%= render 'orders_plugin_admin/sales', actors: profile.purchases_all_consumers, + <%= render 'orders_plugin_admin/sales', actors: profile.sales_all_consumers, orders_owner: profile, orders: @sales, month: @sales_month, year: @purchases_year, wireframe_size: false %>
<% end %> -- libgit2 0.21.2