diff --git a/CHANGELOG.md b/CHANGELOG.md index 1277f0bd6..3bb6ad7ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog Fab-manager +- [TODO DEPLOY] `rails fablab:maintenance:build_accounting_lines` + - Add reservation deadline parameter (#414) - Fix a bug: unable to run test in negavtive timezones (#425) diff --git a/app/frontend/src/javascript/components/accounting/accounting-codes-settings.tsx b/app/frontend/src/javascript/components/accounting/accounting-codes-settings.tsx index cc77f891c..fe345394c 100644 --- a/app/frontend/src/javascript/components/accounting/accounting-codes-settings.tsx +++ b/app/frontend/src/javascript/components/accounting/accounting-codes-settings.tsx @@ -115,7 +115,9 @@ export const AccountingCodesSettings: React.FC = (

{t('app.admin.accounting_codes_settings.error')}

- +

{t('app.admin.accounting_codes_settings.advanced_accounting')}

({ register, curr }} formState={formState} label={t('app.shared.password_input.new_password')} + tooltip={t('app.shared.password_input.help')} type="password" /> ?', last_period.end_at).order(:id).each(&:chain_record) - else - puts '(Re)generating all footprint...' - Invoice.order(:id).all.each(&:chain_record) - end - end end end diff --git a/lib/tasks/fablab/maintenance.rake b/lib/tasks/fablab/maintenance.rake index 6c08b2193..e6475db73 100644 --- a/lib/tasks/fablab/maintenance.rake +++ b/lib/tasks/fablab/maintenance.rake @@ -5,10 +5,7 @@ namespace :fablab do namespace :maintenance do desc 'Regenerate the invoices (invoices & avoirs) PDF' task :regenerate_invoices, %i[year month] => :environment do |_task, args| - year = args.year || Time.current.year - month = args.month || Time.current.month - start_date = Time.zone.local(year.to_i, month.to_i, 1) - end_date = start_date.next_month + start_date, end_date = dates_from_args(args) puts "-> Start regenerate the invoices PDF between #{I18n.l start_date, format: :long} and " \ "#{I18n.l end_date - 1.minute, format: :long}" invoices = Invoice.where('created_at >= :start_date AND created_at < :end_date', start_date: start_date, end_date: end_date) @@ -18,10 +15,7 @@ namespace :fablab do end task :regenerate_schedules, %i[year month] => :environment do |_task, args| - year = args.year || Time.current.year - month = args.month || Time.current.month - start_date = Time.zone.local(year.to_i, month.to_i, 1) - end_date = start_date.next_month + start_date, end_date = dates_from_args(args) puts "-> Start regenerate the payment schedules PDF between #{I18n.l start_date, format: :long} and " \ "#{I18n.l end_date - 1.minute, format: :long}" schedules = PaymentSchedule.where('created_at >= :start_date AND created_at < :end_date', start_date: start_date, end_date: end_date) @@ -126,10 +120,7 @@ namespace :fablab do desc 'Regenerate the invoices (invoices & avoirs) reference' task :regenerate_invoices_reference, %i[year month] => :environment do |_task, args| - year = args.year || Time.current.year - month = args.month || Time.current.month - start_date = Time.zone.local(year.to_i, month.to_i, 1) - end_date = start_date.next_month + start_date, end_date = dates_from_args(args) puts "-> Start regenerate the invoices reference between #{I18n.l start_date, format: :long} and " \ "#{I18n.l end_date - 1.minute, format: :long}" invoices = Invoice.where('created_at >= :start_date AND created_at < :end_date', start_date: start_date, end_date: end_date) @@ -137,5 +128,22 @@ namespace :fablab do invoices.each(&:update_reference) puts '-> Done' end + + desc 'Regenerate accounting lines' + task :regenerate_accounting_lines, %i[year month] => :environment do |_task, args| + start_date, end_date = dates_from_args(args) + puts "-> Start regenerate the accounting lines between #{I18n.l start_date, format: :long} and " \ + "#{I18n.l end_date - 1.minute, format: :long}" + AccountingLine.where(date: start_date..end_date).destroy_all + Accounting::AccountingService.new.build(start_date.beginning_of_day, end_date.end_of_day) + puts '-> Done' + end + + def dates_from_args(args) + year = args.year || Time.current.year + month = args.month || Time.current.month + start_date = Time.zone.local(year.to_i, month.to_i, 1) + [start_date, start_date.next_month] + end end end diff --git a/lib/tasks/fablab/setup.rake b/lib/tasks/fablab/setup.rake index ef5ae460c..360f9f76d 100644 --- a/lib/tasks/fablab/setup.rake +++ b/lib/tasks/fablab/setup.rake @@ -127,6 +127,15 @@ namespace :fablab do print "\e[32m✅\e[0m \e[1mDone\e[0m\n" end + desc 'generate acconting lines' + task build_accounting_lines: :environment do + start_date = Invoice.order(created_at: :asc).first&.created_at + end_date = DateTime.current + AccountingLine.where(date: start_date..end_date).destroy_all + Accounting::AccountingService.new.build(start_date&.beginning_of_day, end_date.end_of_day) + puts '-> Done' + end + def select_group(groups) groups.each do |g| print "#{g.id}) #{g.name}\n"