1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-21 15:54:22 +01:00

[bug] after disabling a group, its associated plans are hidden from the interface

+ validate server-side that there's no more user in the group to disable
This commit is contained in:
Sylvain 2019-09-19 15:34:21 +02:00
parent 668eb43959
commit de1cc2013a
4 changed files with 20 additions and 5 deletions

View File

@ -3,6 +3,7 @@
- Ability to configure and export the accounting data to the ACD accounting software - Ability to configure and export the accounting data to the ACD accounting software
- Compute the VAT per item in each invoices, instead of globally - Compute the VAT per item in each invoices, instead of globally
- Fix a bug: invoices with total = 0, are marked as paid on site even if paid by card - Fix a bug: invoices with total = 0, are marked as paid on site even if paid by card
- Fix a bug: after disabling a group, its associated plans are hidden from the interface
- Fix a bug: in case of unexpected server error during stripe payment process, the confirm button is not unlocked - Fix a bug: in case of unexpected server error during stripe payment process, the confirm button is not unlocked
- [TODO DEPLOY] `rake db:migrate` - [TODO DEPLOY] `rake db:migrate`

View File

@ -36,8 +36,7 @@
<tbody> <tbody>
<tr ng-repeat="plan in plans | filterDisabled:planFiltering | orderBy:orderPlans" <tr ng-repeat="plan in plans | filterDisabled:planFiltering | orderBy:orderPlans"
ng-class="{'disabled-line' : plan.disabled && planFiltering === 'all'}" ng-class="{'disabled-line' : plan.disabled && planFiltering === 'all'}"
ng-init="group = getGroupFromId(groups, plan.group_id)" ng-init="group = getGroupFromId(groups, plan.group_id)">
ng-hide="group.disabled">
<td>{{getPlanType(plan.type)}}</td> <td>{{getPlanType(plan.type)}}</td>
<td>{{plan.base_name}}</td> <td>{{plan.base_name}}</td>
<td>{{ plan.interval | planIntervalFilter:plan.interval_count }}</td> <td>{{ plan.interval | planIntervalFilter:plan.interval_count }}</td>
@ -47,4 +46,4 @@
<td><button type="button" class="btn btn-default" ui-sref="app.admin.plans.edit({id:plan.id})"><i class="fa fa-pencil-square-o"></i></button> <button type="button" class="btn btn-danger" ng-click="deletePlan(plans, plan.id)"><i class="fa fa-trash"></i></button></td> <td><button type="button" class="btn btn-default" ui-sref="app.admin.plans.edit({id:plan.id})"><i class="fa fa-pencil-square-o"></i></button> <button type="button" class="btn btn-danger" ng-click="deletePlan(plans, plan.id)"><i class="fa fa-trash"></i></button></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -1,3 +1,6 @@
# frozen_string_literal: true
# Group is way to bind users with prices. Different prices can be defined for each plan/reservable, for each group
class Group < ActiveRecord::Base class Group < ActiveRecord::Base
has_many :plans has_many :plans
has_many :users has_many :users
@ -12,15 +15,21 @@ class Group < ActiveRecord::Base
friendly_id :name, use: :slugged friendly_id :name, use: :slugged
validates :name, :slug, presence: true validates :name, :slug, presence: true
validates :disabled, inclusion: { in: [false] }, if: :group_has_users?
after_create :create_prices after_create :create_prices
after_create :create_statistic_subtype after_create :create_statistic_subtype
after_update :update_statistic_subtype, if: :name_changed? after_update :update_statistic_subtype, if: :name_changed?
after_update :disable_plans, if: :disabled_changed?
def destroyable? def destroyable?
users.empty? and plans.empty? users.empty? and plans.empty?
end end
def group_has_users?
users.count.positive?
end
private private
def create_prices def create_prices
@ -60,4 +69,10 @@ class Group < ActiveRecord::Base
subtype.label = name subtype.label = name
subtype.save! subtype.save!
end end
def disable_plans
plans.each do |plan|
plan.update_attributes(disabled: disabled)
end
end
end end

View File

@ -53,13 +53,13 @@ class Plan < ActiveRecord::Base
def create_machines_prices def create_machines_prices
Machine.all.each do |machine| Machine.all.each do |machine|
Price.create(priceable: machine, plan: self, group_id: self.group_id, amount: 0) Price.create(priceable: machine, plan: self, group_id: group_id, amount: 0)
end end
end end
def create_spaces_prices def create_spaces_prices
Space.all.each do |space| Space.all.each do |space|
Price.create(priceable: space, plan: self, group_id: self.group_id, amount: 0) Price.create(priceable: space, plan: self, group_id: group_id, amount: 0)
end end
end end