From 4d7e09c98d0f6ca03d5c1381e6b8be14aa88da0c Mon Sep 17 00:00:00 2001 From: Sylvain Date: Fri, 9 Dec 2022 16:06:51 +0100 Subject: [PATCH] (feat) multiple accounting journals --- .../accounting/accounting-codes-settings.tsx | 31 +- app/frontend/src/javascript/models/setting.ts | 7 +- .../accounting/accounting-codes-settings.scss | 5 +- app/models/setting.rb | 10 +- .../accounting/accounting_journal_service.rb | 37 ++ app/services/accounting/accounting_service.rb | 20 +- config/locales/app.admin.en.yml | 1 + config/locales/en.yml | 11 +- ...21208123822_rename_journal_code_setting.rb | 12 + db/schema.rb | 2 +- lib/tasks/fablab/maintenance.rake | 13 +- test/fixtures/accounting_lines.yml | 361 ++++++++++-------- test/fixtures/history_values.yml | 51 ++- test/fixtures/settings.yml | 32 +- test/frontend/__fixtures__/settings.ts | 76 ++-- .../exports/accounting_export_test.rb | 13 +- test/services/accounting_service_test.rb | 5 + 17 files changed, 459 insertions(+), 228 deletions(-) create mode 100644 app/services/accounting/accounting_journal_service.rb create mode 100644 db/migrate/20221208123822_rename_journal_code_setting.rb 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 3549a7f79..eb7a4ad77 100644 --- a/app/frontend/src/javascript/components/accounting/accounting-codes-settings.tsx +++ b/app/frontend/src/javascript/components/accounting/accounting-codes-settings.tsx @@ -56,25 +56,28 @@ export const AccountingCodesSettings: React.FC = ( tooltip={t('app.admin.accounting_codes_settings.enable_advanced_help')} /> -

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

-

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

{t('app.admin.accounting_codes_settings.card')}
+
{t('app.admin.accounting_codes_settings.wallet_debit')}
+
{t('app.admin.accounting_codes_settings.other')}
+

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

+
{t('app.admin.accounting_codes_settings.sales_journal')}
+
{t('app.admin.accounting_codes_settings.subscriptions')}
@@ -110,23 +113,25 @@ export const AccountingCodesSettings: React.FC = (
-

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

-
- - -
-

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

-
- - -
-

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

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

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

+
+ + + +
+

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

+
+ + + +
diff --git a/app/frontend/src/javascript/models/setting.ts b/app/frontend/src/javascript/models/setting.ts index ff3f7821d..419d69298 100644 --- a/app/frontend/src/javascript/models/setting.ts +++ b/app/frontend/src/javascript/models/setting.ts @@ -96,17 +96,22 @@ export const titleSettings = [ ] as const; export const accountingSettings = [ - 'accounting_journal_code', + 'accounting_sales_journal_code', 'accounting_card_client_code', 'accounting_card_client_label', + 'accounting_card_client_journal_code', 'accounting_wallet_client_code', 'accounting_wallet_client_label', + 'accounting_wallet_client_journal_code', 'accounting_other_client_code', 'accounting_other_client_label', + 'accounting_other_client_journal_code', 'accounting_wallet_code', 'accounting_wallet_label', + 'accounting_wallet_journal_code', 'accounting_VAT_code', 'accounting_VAT_label', + 'accounting_VAT_journal_code', 'accounting_subscription_code', 'accounting_subscription_label', 'accounting_Machine_code', diff --git a/app/frontend/src/stylesheets/modules/accounting/accounting-codes-settings.scss b/app/frontend/src/stylesheets/modules/accounting/accounting-codes-settings.scss index 616b5eee8..a205c3b23 100644 --- a/app/frontend/src/stylesheets/modules/accounting/accounting-codes-settings.scss +++ b/app/frontend/src/stylesheets/modules/accounting/accounting-codes-settings.scss @@ -4,9 +4,12 @@ display: flex; flex-direction: row; - .form-item:first-child { + .form-item { margin-right: 32px; } + .form-item:last-child { + margin-right: 0; + } } .actions { background-color: transparent; diff --git a/app/models/setting.rb b/app/models/setting.rb index 312ae1cee..b69441f9a 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -56,17 +56,22 @@ class Setting < ApplicationRecord reservation_deadline display_name_enable machines_sort_by - accounting_journal_code + accounting_sales_journal_code accounting_card_client_code accounting_card_client_label + accounting_card_client_journal_code accounting_wallet_client_code accounting_wallet_client_label + accounting_wallet_client_journal_code accounting_other_client_code accounting_other_client_label + accounting_other_client_journal_code accounting_wallet_code accounting_wallet_label + accounting_wallet_journal_code accounting_VAT_code accounting_VAT_label + accounting_VAT_journal_code accounting_subscription_code accounting_subscription_label accounting_Machine_code @@ -164,6 +169,9 @@ class Setting < ApplicationRecord # - app/frontend/src/javascript/models/setting.ts#SettingName # - db/seeds.rb (to set the default value) # - app/policies/setting_policy.rb#public_whitelist (if the setting can be read by anyone) + # - test/fixtures/settings.yml (for backend testing) + # - test/fixtures/history_values.yml (example value for backend testing) + # - test/frontend/__fixtures__/settings.ts (example value for frontend testing) def value last_value = history_values.order(HistoryValue.arel_table['created_at'].desc).limit(1).first diff --git a/app/services/accounting/accounting_journal_service.rb b/app/services/accounting/accounting_journal_service.rb new file mode 100644 index 000000000..151e11dd9 --- /dev/null +++ b/app/services/accounting/accounting_journal_service.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: false + +# module definition +module Accounting; end + +# fetch the journal code matching the given resource +class Accounting::AccountingJournalService + def initialize + @journal_codes = { + sales: Setting.get('accounting_sales_journal_code') || '', + wallet: Setting.get('accounting_wallet_journal_code') || '', + vat: Setting.get('accounting_VAT_journal_code') || '', + client: { + card: Setting.get('accounting_card_client_journal_code') || '', + wallet: Setting.get('accounting_wallet_client_journal_code') || '', + other: Setting.get('accounting_other_client_journal_code') || '' + } + } + end + + def client_journal(payment_mean) + @journal_codes[:client][payment_mean] + end + + def vat_journal + @journal_codes[:vat] + end + + def sales_journal(object_type) + case object_type + when 'WalletTransaction' + @journal_codes[:wallet] + else + @journal_codes[:sales] + end + end +end diff --git a/app/services/accounting/accounting_service.rb b/app/services/accounting/accounting_service.rb index 8ca29fa7b..e33b52422 100644 --- a/app/services/accounting/accounting_service.rb +++ b/app/services/accounting/accounting_service.rb @@ -5,11 +5,9 @@ module Accounting; end # Provides the routine to build the accounting data and save them in DB class Accounting::AccountingService - attr_reader :currency, :journal_code - def initialize @currency = ENV.fetch('INTL_CURRENCY') { '' } - @journal_code = Setting.get('accounting_journal_code') || '' + @journal_service = Accounting::AccountingJournalService.new end # build accounting lines for invoices between the provided dates @@ -58,9 +56,10 @@ class Accounting::AccountingService lines << line( invoice, 'item', + @journal_service.sales_journal(object_type), Accounting::AccountingCodeService.sales_account(item), - Accounting::AccountingCodeService.sales_account(item, type: :label), item.net_amount, + account_label: Accounting::AccountingCodeService.sales_account(item, type: :label), analytical_code: Accounting::AccountingCodeService.sales_account(item, section: :analytical_section) ) end @@ -75,9 +74,10 @@ class Accounting::AccountingService lines << line( invoice, 'client', + @journal_service.client_journal(details[:means]), Accounting::AccountingCodeService.client_account(details[:means]), - Accounting::AccountingCodeService.client_account(details[:means], type: :label), details[:amount], + account_label: Accounting::AccountingCodeService.client_account(details[:means], type: :label), debit_method: :debit_client, credit_method: :credit_client ) @@ -95,14 +95,16 @@ class Accounting::AccountingService line( invoice, 'vat', + @journal_service.vat_journal, Accounting::AccountingCodeService.vat_account, - Accounting::AccountingCodeService.vat_account(type: :label), - total_vat + total_vat, + account_label: Accounting::AccountingCodeService.vat_account(type: :label) ) end # Generate a row of the export, filling the configured columns with the provided values - def line(invoice, line_type, account_code, account_label, amount, analytical_code: '', debit_method: :debit, credit_method: :credit) + def line(invoice, line_type, journal_code, account_code, amount, + account_label: '', analytical_code: '', debit_method: :debit, credit_method: :credit) { line_type: line_type, journal_code: journal_code, @@ -114,7 +116,7 @@ class Accounting::AccountingService invoicing_profile_id: invoice.invoicing_profile_id, debit: method(debit_method).call(invoice, amount), credit: method(credit_method).call(invoice, amount), - currency: currency, + currency: @currency, summary: summary(invoice) } end diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml index 894b3eb3b..d40e9262c 100644 --- a/config/locales/app.admin.en.yml +++ b/config/locales/app.admin.en.yml @@ -145,6 +145,7 @@ en: code: "Accounting code" label: "Account label" journal_code: "Journal code" + sales_journal: "Sales journal" payment_means: "Payment means" card: "Card clients" wallet_debit: "Virtual wallet clients" diff --git a/config/locales/en.yml b/config/locales/en.yml index bed2d5e0b..367c11bf3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -528,17 +528,22 @@ en: reservation_deadline: "Prevent reservation before it starts" display_name_enable: "Display names in the calendar" machines_sort_by: "Machines display order" - accounting_journal_code: "Journal code" + accounting_sales_journal_code: "Sales journal code" accounting_card_client_code: "Card clients code" accounting_card_client_label: "Card clients label" + accounting_card_client_journal_code: "Card clients journal code" accounting_wallet_client_code: "Wallet clients code" accounting_wallet_client_label: "Wallet clients label" + accounting_wallet_client_journal_code: "Wallet clients journal code" accounting_other_client_code: "Other means client code" accounting_other_client_label: "Other means client label" + accounting_other_client_journal_code: "Other means client journal code" accounting_wallet_code: "Wallet code" accounting_wallet_label: "Wallet label" + accounting_wallet_journal_code: "Wallet journal code" accounting_VAT_code: "VAT code" accounting_VAT_label: "VAT label" + accounting_VAT_journal_code: "VAT journal code" accounting_subscription_code: "Subscriptions code" accounting_subscription_label: "Subscriptions label" accounting_Machine_code: "Machines code" @@ -549,6 +554,10 @@ en: accounting_Event_label: "Events label" accounting_Space_code: "Spaces code" accounting_Space_label: "Spaces label" + accounting_Pack_code: "Prepaid-hours pack code" + accounting_Pack_label: "Prepaid-hours pack label" + accounting_Product_code: "Store products code" + accounting_Product_label: "Store products label" hub_last_version: "Last Fab-manager's version" hub_public_key: "Instance public key" fab_analytics: "Fab Analytics" diff --git a/db/migrate/20221208123822_rename_journal_code_setting.rb b/db/migrate/20221208123822_rename_journal_code_setting.rb new file mode 100644 index 000000000..f44f3056d --- /dev/null +++ b/db/migrate/20221208123822_rename_journal_code_setting.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +# From this migration the setting "accounting_journal_code" will be renamed to "accounting_sales_journal_code" +class RenameJournalCodeSetting < ActiveRecord::Migration[5.2] + def up + Setting.find_by(name: 'accounting_journal_code')&.update(name: 'accounting_sales_journal_code') + end + + def down + Setting.find_by(name: 'accounting_sales_journal_code')&.update(name: 'accounting_journal_code') + end +end diff --git a/db/schema.rb b/db/schema.rb index 8311e496b..f051bb0a0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_12_06_100225) do +ActiveRecord::Schema.define(version: 2022_12_08_123822) do # These are extensions that must be enabled in order to support this database enable_extension "fuzzystrmatch" diff --git a/lib/tasks/fablab/maintenance.rake b/lib/tasks/fablab/maintenance.rake index e6475db73..d589f8a72 100644 --- a/lib/tasks/fablab/maintenance.rake +++ b/lib/tasks/fablab/maintenance.rake @@ -4,7 +4,7 @@ namespace :fablab do namespace :maintenance do desc 'Regenerate the invoices (invoices & avoirs) PDF' - task :regenerate_invoices, %i[year month] => :environment do |_task, args| + task :regenerate_invoices, %i[year month end] => :environment do |_task, args| 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}" @@ -14,7 +14,7 @@ namespace :fablab do puts '-> Done' end - task :regenerate_schedules, %i[year month] => :environment do |_task, args| + task :regenerate_schedules, %i[year month end] => :environment do |_task, args| 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}" @@ -119,7 +119,7 @@ namespace :fablab do end desc 'Regenerate the invoices (invoices & avoirs) reference' - task :regenerate_invoices_reference, %i[year month] => :environment do |_task, args| + task :regenerate_invoices_reference, %i[year month end] => :environment do |_task, args| 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}" @@ -130,11 +130,11 @@ namespace :fablab do end desc 'Regenerate accounting lines' - task :regenerate_accounting_lines, %i[year month] => :environment do |_task, args| + task :regenerate_accounting_lines, %i[year month end] => :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 + AccountingLine.where(date: start_date.beginning_of_day..end_date.end_of_day).delete_all Accounting::AccountingService.new.build(start_date.beginning_of_day, end_date.end_of_day) puts '-> Done' end @@ -143,7 +143,8 @@ namespace :fablab do 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_date = args.end == 'today' ? Time.current.end_of_day : start_date.next_month + [start_date, end_date] end end end diff --git a/test/fixtures/accounting_lines.yml b/test/fixtures/accounting_lines.yml index 823e2d00d..2ee1b5368 100644 --- a/test/fixtures/accounting_lines.yml +++ b/test/fixtures/accounting_lines.yml @@ -1,7 +1,7 @@ -accounting_line_1: - id: 1 +accounting_line_43: + id: 43 line_type: client - journal_code: '530' + journal_code: CB01 date: '2012-03-12 11:03:31.651441' account_code: '5801' account_label: Client card @@ -12,10 +12,11 @@ accounting_line_1: credit: 0 currency: EUR summary: 1604001/VL, subscr. - created_at: '2022-11-18 15:04:08.437029' - updated_at: '2022-11-18 15:04:08.437029' -accounting_line_2: - id: 2 + created_at: '2022-12-09 14:47:11.004319' + updated_at: '2022-12-09 14:47:11.004319' + +accounting_line_44: + id: 44 line_type: item journal_code: '530' date: '2012-03-12 11:03:31.651441' @@ -28,12 +29,13 @@ accounting_line_2: credit: 10000 currency: EUR summary: 1604001/VL, subscr. - created_at: '2022-11-18 15:04:08.455753' - updated_at: '2022-11-18 15:04:08.455753' -accounting_line_3: - id: 3 + created_at: '2022-12-09 14:47:11.018100' + updated_at: '2022-12-09 14:47:11.018100' + +accounting_line_45: + id: 45 line_type: client - journal_code: '530' + journal_code: CA01 date: '2012-03-12 13:40:22.342717' account_code: '5803' account_label: Client other @@ -44,10 +46,11 @@ accounting_line_3: credit: 0 currency: EUR summary: 1604002, subscr. - created_at: '2022-11-18 15:04:08.463802' - updated_at: '2022-11-18 15:04:08.463802' -accounting_line_4: - id: 4 + created_at: '2022-12-09 14:47:11.026505' + updated_at: '2022-12-09 14:47:11.026505' + +accounting_line_46: + id: 46 line_type: item journal_code: '530' date: '2012-03-12 13:40:22.342717' @@ -60,12 +63,13 @@ accounting_line_4: credit: 2000 currency: EUR summary: 1604002, subscr. - created_at: '2022-11-18 15:04:08.471904' - updated_at: '2022-11-18 15:04:08.471904' -accounting_line_5: - id: 5 + created_at: '2022-12-09 14:47:11.051484' + updated_at: '2022-12-09 14:47:11.051484' + +accounting_line_47: + id: 47 line_type: client - journal_code: '530' + journal_code: CA01 date: '2015-06-10 11:20:01.341130' account_code: '5803' account_label: Client other @@ -76,10 +80,11 @@ accounting_line_5: credit: 0 currency: EUR summary: 1203001, subscr. - created_at: '2022-11-18 15:04:08.480362' - updated_at: '2022-11-18 15:04:08.480362' -accounting_line_6: - id: 6 + created_at: '2022-12-09 14:47:11.059774' + updated_at: '2022-12-09 14:47:11.059774' + +accounting_line_48: + id: 48 line_type: item journal_code: '530' date: '2015-06-10 11:20:01.341130' @@ -92,12 +97,13 @@ accounting_line_6: credit: 3000 currency: EUR summary: 1203001, subscr. - created_at: '2022-11-18 15:04:08.488755' - updated_at: '2022-11-18 15:04:08.488755' -accounting_line_7: - id: 7 + created_at: '2022-12-09 14:47:11.068258' + updated_at: '2022-12-09 14:47:11.068258' + +accounting_line_49: + id: 49 line_type: client - journal_code: '530' + journal_code: CA01 date: '2016-04-05 08:35:52.931187' account_code: '5803' account_label: Client other @@ -108,10 +114,11 @@ accounting_line_7: credit: 0 currency: EUR summary: 1203002, training reserv. - created_at: '2022-11-18 15:04:08.497148' - updated_at: '2022-11-18 15:04:08.497148' -accounting_line_8: - id: 8 + created_at: '2022-12-09 14:47:11.076845' + updated_at: '2022-12-09 14:47:11.076845' + +accounting_line_50: + id: 50 line_type: item journal_code: '530' date: '2016-04-05 08:35:52.931187' @@ -124,12 +131,13 @@ accounting_line_8: credit: 0 currency: EUR summary: 1203002, training reserv. - created_at: '2022-11-18 15:04:08.505540' - updated_at: '2022-11-18 15:04:08.505540' -accounting_line_9: - id: 9 + created_at: '2022-12-09 14:47:11.085317' + updated_at: '2022-12-09 14:47:11.085317' + +accounting_line_51: + id: 51 line_type: client - journal_code: '530' + journal_code: CA01 date: '2016-04-05 08:36:46.853368' account_code: '5803' account_label: Client other @@ -140,10 +148,11 @@ accounting_line_9: credit: 0 currency: EUR summary: 1506031, machine reserv. - created_at: '2022-11-18 15:04:08.513708' - updated_at: '2022-11-18 15:04:08.513708' -accounting_line_10: - id: 10 + created_at: '2022-12-09 14:47:11.093737' + updated_at: '2022-12-09 14:47:11.093737' + +accounting_line_52: + id: 52 line_type: item journal_code: '530' date: '2016-04-05 08:36:46.853368' @@ -156,12 +165,13 @@ accounting_line_10: credit: 1500 currency: EUR summary: 1506031, machine reserv. - created_at: '2022-11-18 15:04:08.522222' - updated_at: '2022-11-18 15:04:08.522222' -accounting_line_11: - id: 11 + created_at: '2022-12-09 14:47:11.102073' + updated_at: '2022-12-09 14:47:11.102073' + +accounting_line_53: + id: 53 line_type: client - journal_code: '530' + journal_code: CA01 date: '2021-01-04 14:51:21.616153' account_code: '5803' account_label: Client other @@ -172,10 +182,11 @@ accounting_line_11: credit: 0 currency: EUR summary: 2101041, subscr. - created_at: '2022-11-18 15:04:08.530494' - updated_at: '2022-11-18 15:04:08.530494' -accounting_line_12: - id: 12 + created_at: '2022-12-09 14:47:11.110627' + updated_at: '2022-12-09 14:47:11.110627' + +accounting_line_54: + id: 54 line_type: item journal_code: '530' date: '2021-01-04 14:51:21.616153' @@ -188,12 +199,13 @@ accounting_line_12: credit: 3000 currency: EUR summary: 2101041, subscr. - created_at: '2022-11-18 15:04:08.538721' - updated_at: '2022-11-18 15:04:08.538721' -accounting_line_13: - id: 13 + created_at: '2022-12-09 14:47:11.118764' + updated_at: '2022-12-09 14:47:11.118764' + +accounting_line_55: + id: 55 line_type: client - journal_code: '530' + journal_code: CA01 date: '2022-09-20 15:14:22.873707' account_code: '5803' account_label: Client other @@ -204,14 +216,15 @@ accounting_line_13: credit: 0 currency: EUR summary: 2209002, shop order - created_at: '2022-11-18 15:04:08.547966' - updated_at: '2022-11-18 15:04:08.547966' -accounting_line_14: - id: 14 + created_at: '2022-12-09 14:47:11.126381' + updated_at: '2022-12-09 14:47:11.126381' + +accounting_line_56: + id: 56 line_type: item journal_code: '530' date: '2022-09-20 15:14:22.873707' - account_code: '7067' + account_code: '7071' account_label: Shop order analytical_code: invoice_id: 5811 @@ -220,14 +233,15 @@ accounting_line_14: credit: 4000 currency: EUR summary: 2209002, shop order - created_at: '2022-11-18 15:04:08.556504' - updated_at: '2022-11-18 15:04:08.556504' -accounting_line_15: - id: 15 + created_at: '2022-12-09 14:47:11.134781' + updated_at: '2022-12-09 14:47:11.134781' + +accounting_line_57: + id: 57 line_type: item journal_code: '530' date: '2022-09-20 15:14:22.873707' - account_code: '7067' + account_code: '7071' account_label: Shop order analytical_code: invoice_id: 5811 @@ -236,12 +250,13 @@ accounting_line_15: credit: 500 currency: EUR summary: 2209002, shop order - created_at: '2022-11-18 15:04:08.563733' - updated_at: '2022-11-18 15:04:08.563733' -accounting_line_16: - id: 16 + created_at: '2022-12-09 14:47:11.144686' + updated_at: '2022-12-09 14:47:11.144686' + +accounting_line_58: + id: 58 line_type: client - journal_code: '530' + journal_code: CA01 date: '2022-09-20 15:14:48.345927' account_code: '5803' account_label: Client other @@ -252,14 +267,15 @@ accounting_line_16: credit: 0 currency: EUR summary: 2209004, shop order - created_at: '2022-11-18 15:04:08.571992' - updated_at: '2022-11-18 15:04:08.571992' -accounting_line_17: - id: 17 + created_at: '2022-12-09 14:47:11.151435' + updated_at: '2022-12-09 14:47:11.151435' + +accounting_line_59: + id: 59 line_type: item journal_code: '530' date: '2022-09-20 15:14:48.345927' - account_code: '7067' + account_code: '7071' account_label: Shop order analytical_code: invoice_id: 5812 @@ -268,12 +284,13 @@ accounting_line_17: credit: 6000 currency: EUR summary: 2209004, shop order - created_at: '2022-11-18 15:04:08.580452' - updated_at: '2022-11-18 15:04:08.580452' -accounting_line_18: - id: 18 + created_at: '2022-12-09 14:47:11.161817' + updated_at: '2022-12-09 14:47:11.161817' + +accounting_line_60: + id: 60 line_type: client - journal_code: '530' + journal_code: CB01 date: '2022-10-04 12:36:03.060832' account_code: '5801' account_label: Client card @@ -284,14 +301,15 @@ accounting_line_18: credit: 0 currency: EUR summary: 2210002/VL, shop order - created_at: '2022-11-18 15:04:08.589664' - updated_at: '2022-11-18 15:04:08.589664' -accounting_line_19: - id: 19 + created_at: '2022-12-09 14:47:11.186575' + updated_at: '2022-12-09 14:47:11.186575' + +accounting_line_61: + id: 61 line_type: item journal_code: '530' date: '2022-10-04 12:36:03.060832' - account_code: '7067' + account_code: '7071' account_label: Shop order analytical_code: invoice_id: 5816 @@ -300,14 +318,15 @@ accounting_line_19: credit: 119 currency: EUR summary: 2210002/VL, shop order - created_at: '2022-11-18 15:04:08.598371' - updated_at: '2022-11-18 15:04:08.598371' -accounting_line_20: - id: 20 + created_at: '2022-12-09 14:47:11.203226' + updated_at: '2022-12-09 14:47:11.203226' + +accounting_line_62: + id: 62 line_type: item journal_code: '530' date: '2022-10-04 12:36:03.060832' - account_code: '7067' + account_code: '7071' account_label: Shop order analytical_code: invoice_id: 5816 @@ -316,12 +335,13 @@ accounting_line_20: credit: 200 currency: EUR summary: 2210002/VL, shop order - created_at: '2022-11-18 15:04:08.613961' - updated_at: '2022-11-18 15:04:08.613961' -accounting_line_21: - id: 21 + created_at: '2022-12-09 14:47:11.219605' + updated_at: '2022-12-09 14:47:11.219605' + +accounting_line_63: + id: 63 line_type: client - journal_code: '530' + journal_code: CB01 date: '2022-10-04 13:54:42.975196' account_code: '5801' account_label: Client card @@ -332,14 +352,15 @@ accounting_line_21: credit: 0 currency: EUR summary: 2210004/VL, shop order - created_at: '2022-11-18 15:04:08.622056' - updated_at: '2022-11-18 15:04:08.622056' -accounting_line_22: - id: 22 + created_at: '2022-12-09 14:47:11.234721' + updated_at: '2022-12-09 14:47:11.234721' + +accounting_line_64: + id: 64 line_type: item journal_code: '530' date: '2022-10-04 13:54:42.975196' - account_code: '7067' + account_code: '7071' account_label: Shop order analytical_code: invoice_id: 5817 @@ -348,14 +369,15 @@ accounting_line_22: credit: 95 currency: EUR summary: 2210004/VL, shop order - created_at: '2022-11-18 15:04:08.630519' - updated_at: '2022-11-18 15:04:08.630519' -accounting_line_23: - id: 23 + created_at: '2022-12-09 14:47:11.243121' + updated_at: '2022-12-09 14:47:11.243121' + +accounting_line_65: + id: 65 line_type: item journal_code: '530' date: '2022-10-04 13:54:42.975196' - account_code: '7067' + account_code: '7071' account_label: Shop order analytical_code: invoice_id: 5817 @@ -364,12 +386,13 @@ accounting_line_23: credit: 1200 currency: EUR summary: 2210004/VL, shop order - created_at: '2022-11-18 15:04:08.640333' - updated_at: '2022-11-18 15:04:08.640333' -accounting_line_24: - id: 24 + created_at: '2022-12-09 14:47:11.253093' + updated_at: '2022-12-09 14:47:11.253093' + +accounting_line_66: + id: 66 line_type: client - journal_code: '530' + journal_code: CB01 date: '2022-10-04 14:04:12.742685' account_code: '5801' account_label: Client card @@ -380,14 +403,15 @@ accounting_line_24: credit: 0 currency: EUR summary: 2210006/VL, shop order - created_at: '2022-11-18 15:04:08.656104' - updated_at: '2022-11-18 15:04:08.656104' -accounting_line_25: - id: 25 + created_at: '2022-12-09 14:47:11.268142' + updated_at: '2022-12-09 14:47:11.268142' + +accounting_line_67: + id: 67 line_type: item journal_code: '530' date: '2022-10-04 14:04:12.742685' - account_code: '7067' + account_code: '7071' account_label: Shop order analytical_code: invoice_id: 5818 @@ -396,12 +420,13 @@ accounting_line_25: credit: 1000 currency: EUR summary: 2210006/VL, shop order - created_at: '2022-11-18 15:04:08.663862' - updated_at: '2022-11-18 15:04:08.663862' -accounting_line_26: - id: 26 + created_at: '2022-12-09 14:47:11.278069' + updated_at: '2022-12-09 14:47:11.278069' + +accounting_line_68: + id: 68 line_type: client - journal_code: '530' + journal_code: CB01 date: '2022-10-04 14:17:52.854636' account_code: '5801' account_label: Client card @@ -412,14 +437,15 @@ accounting_line_26: credit: 0 currency: EUR summary: 2210008/VL, shop order - created_at: '2022-11-18 15:04:08.672150' - updated_at: '2022-11-18 15:04:08.672150' -accounting_line_27: - id: 27 + created_at: '2022-12-09 14:47:11.294694' + updated_at: '2022-12-09 14:47:11.294694' + +accounting_line_69: + id: 69 line_type: item journal_code: '530' date: '2022-10-04 14:17:52.854636' - account_code: '7067' + account_code: '7071' account_label: Shop order analytical_code: invoice_id: 5819 @@ -428,14 +454,15 @@ accounting_line_27: credit: 2 currency: EUR summary: 2210008/VL, shop order - created_at: '2022-11-18 15:04:08.680577' - updated_at: '2022-11-18 15:04:08.680577' -accounting_line_28: - id: 28 + created_at: '2022-12-09 14:47:11.311492' + updated_at: '2022-12-09 14:47:11.311492' + +accounting_line_70: + id: 70 line_type: item journal_code: '530' date: '2022-10-04 14:17:52.854636' - account_code: '7067' + account_code: '7071' account_label: Shop order analytical_code: invoice_id: 5819 @@ -444,12 +471,13 @@ accounting_line_28: credit: 4000 currency: EUR summary: 2210008/VL, shop order - created_at: '2022-11-18 15:04:08.688864' - updated_at: '2022-11-18 15:04:08.688864' -accounting_line_29: - id: 29 + created_at: '2022-12-09 14:47:11.318065' + updated_at: '2022-12-09 14:47:11.318065' + +accounting_line_71: + id: 71 line_type: client - journal_code: '530' + journal_code: CA01 date: '2022-10-04 14:25:37.291945' account_code: '5803' account_label: Client other @@ -460,14 +488,15 @@ accounting_line_29: credit: 0 currency: EUR summary: 2210010, shop order - created_at: '2022-11-18 15:04:08.697635' - updated_at: '2022-11-18 15:04:08.697635' -accounting_line_30: - id: 30 + created_at: '2022-12-09 14:47:11.326477' + updated_at: '2022-12-09 14:47:11.326477' + +accounting_line_72: + id: 72 line_type: item journal_code: '530' date: '2022-10-04 14:25:37.291945' - account_code: '7067' + account_code: '7071' account_label: Shop order analytical_code: invoice_id: 5820 @@ -476,12 +505,13 @@ accounting_line_30: credit: 12000 currency: EUR summary: 2210010, shop order - created_at: '2022-11-18 15:04:08.705822' - updated_at: '2022-11-18 15:04:08.705822' -accounting_line_31: - id: 31 + created_at: '2022-12-09 14:47:11.336473' + updated_at: '2022-12-09 14:47:11.336473' + +accounting_line_73: + id: 73 line_type: client - journal_code: '530' + journal_code: CA01 date: '2022-10-04 14:32:28.204985' account_code: '5803' account_label: Client other @@ -492,14 +522,15 @@ accounting_line_31: credit: 0 currency: EUR summary: 2210012, shop order - created_at: '2022-11-18 15:04:08.713849' - updated_at: '2022-11-18 15:04:08.713849' -accounting_line_32: - id: 32 + created_at: '2022-12-09 14:47:11.353361' + updated_at: '2022-12-09 14:47:11.353361' + +accounting_line_74: + id: 74 line_type: item journal_code: '530' date: '2022-10-04 14:32:28.204985' - account_code: '7067' + account_code: '7071' account_label: Shop order analytical_code: invoice_id: 5821 @@ -508,12 +539,13 @@ accounting_line_32: credit: 12000 currency: EUR summary: 2210012, shop order - created_at: '2022-11-18 15:04:08.722579' - updated_at: '2022-11-18 15:04:08.722579' -accounting_line_33: - id: 33 + created_at: '2022-12-09 14:47:11.368203' + updated_at: '2022-12-09 14:47:11.368203' + +accounting_line_75: + id: 75 line_type: client - journal_code: '530' + journal_code: CA01 date: '2022-10-04 14:35:40.584472' account_code: '5803' account_label: Client other @@ -524,14 +556,15 @@ accounting_line_33: credit: 0 currency: EUR summary: 2210014, shop order - created_at: '2022-11-18 15:04:08.731248' - updated_at: '2022-11-18 15:04:08.731248' -accounting_line_34: - id: 34 + created_at: '2022-12-09 14:47:11.378107' + updated_at: '2022-12-09 14:47:11.378107' + +accounting_line_76: + id: 76 line_type: item journal_code: '530' date: '2022-10-04 14:35:40.584472' - account_code: '7067' + account_code: '7071' account_label: Shop order analytical_code: invoice_id: 5822 @@ -540,5 +573,5 @@ accounting_line_34: credit: 3000 currency: EUR summary: 2210014, shop order - created_at: '2022-11-18 15:04:08.739474' - updated_at: '2022-11-18 15:04:08.739474' + created_at: '2022-12-09 14:47:11.394849' + updated_at: '2022-12-09 14:47:11.394849' diff --git a/test/fixtures/history_values.yml b/test/fixtures/history_values.yml index b1913dafd..b6792f2d5 100644 --- a/test/fixtures/history_values.yml +++ b/test/fixtures/history_values.yml @@ -440,7 +440,7 @@ history_value_45: history_value_46: id: 46 setting_id: 46 - value: '4091' + value: '419100' created_at: '2019-09-20 11:02:32.125400' updated_at: '2021-05-31 15:00:36.672119' footprint: 160a865d5709e9b365b1e18fa930e9069cab3b4e3c23e7d79cd0fdeee758539b @@ -458,7 +458,7 @@ history_value_47: history_value_48: id: 48 setting_id: 48 - value: '445' + value: '4457' created_at: '2019-09-20 11:02:32.125400' updated_at: '2021-05-31 15:00:36.710257' footprint: f585a1b670e6cb1632398360513793ce1f459f49884f971ca7f36594bb67fa70 @@ -855,8 +855,53 @@ history_value_89: history_value_90: id: 90 setting_id: 89 - value: '7067' + value: '7071' created_at: '2022-10-26 12:46:16.125400000 Z' updated_at: '2022-10-26 12:46:16.125400000 Z' footprint: invoicing_profile_id: 1 + +history_value_91: + id: 91 + setting_id: 90 + value: 'CB01' + created_at: 2022-12-09 14:00:14.512000000 Z + updated_at: 2022-12-09 14:00:14.512000000 Z + footprint: + invoicing_profile_id: 1 + +history_value_92: + id: 92 + setting_id: 91 + value: 'W001' + created_at: 2022-12-09 14:00:14.512000000 Z + updated_at: 2022-12-09 14:00:14.512000000 Z + footprint: + invoicing_profile_id: 1 + +history_value_93: + id: 93 + setting_id: 92 + value: 'CA01' + created_at: 2022-12-09 14:00:14.512000000 Z + updated_at: 2022-12-09 14:00:14.512000000 Z + footprint: + invoicing_profile_id: 1 + +history_value_94: + id: 94 + setting_id: 93 + value: 'W002' + created_at: 2022-12-09 14:00:14.512000000 Z + updated_at: 2022-12-09 14:00:14.512000000 Z + footprint: + invoicing_profile_id: 1 + +history_value_95: + id: 95 + setting_id: 94 + value: 'TVA1' + created_at: 2022-12-09 14:00:14.512000000 Z + updated_at: 2022-12-09 14:00:14.512000000 Z + footprint: + invoicing_profile_id: 1 diff --git a/test/fixtures/settings.yml b/test/fixtures/settings.yml index 9ee963d75..30b122c85 100644 --- a/test/fixtures/settings.yml +++ b/test/fixtures/settings.yml @@ -223,7 +223,7 @@ setting_38: setting_39: id: 39 - name: accounting_journal_code + name: accounting_sales_journal_code created_at: 2019-09-20 11:02:32.125400000 Z updated_at: 2019-09-20 11:02:32.125400000 Z @@ -526,3 +526,33 @@ setting_89: name: accounting_Product_code created_at: 2022-10-26 12:46:16.125400000 Z updated_at: 2022-10-26 12:46:16.125400000 Z + +setting_90: + id: 90 + name: accounting_card_client_journal_code + created_at: 2022-12-09 14:00:14.512000000 Z + updated_at: 2022-12-09 14:00:14.512000000 Z + +setting_91: + id: 91 + name: accounting_wallet_client_journal_code + created_at: 2022-12-09 14:00:14.512000000 Z + updated_at: 2022-12-09 14:00:14.512000000 Z + +setting_92: + id: 92 + name: accounting_other_client_journal_code + created_at: 2022-12-09 14:00:14.512000000 Z + updated_at: 2022-12-09 14:00:14.512000000 Z + +setting_93: + id: 93 + name: accounting_wallet_journal_code + created_at: 2022-12-09 14:00:14.512000000 Z + updated_at: 2022-12-09 14:00:14.512000000 Z + +setting_94: + id: 94 + name: accounting_VAT_journal_code + created_at: 2022-12-09 14:00:14.512000000 Z + updated_at: 2022-12-09 14:00:14.512000000 Z diff --git a/test/frontend/__fixtures__/settings.ts b/test/frontend/__fixtures__/settings.ts index 2d32a4270..58d4a2a12 100644 --- a/test/frontend/__fixtures__/settings.ts +++ b/test/frontend/__fixtures__/settings.ts @@ -536,10 +536,10 @@ export const settings: Array = [ localized: 'Code TVA' }, { - name: 'accounting_journal_code', + name: 'accounting_sales_journal_code', value: '22A', last_update: '2022-11-22T17:27:19+0100', - localized: 'Code journal' + localized: 'Code journal des ventes' }, { name: 'accounting_card_client_code', @@ -579,105 +579,105 @@ export const settings: Array = [ }, { name: 'accounting_wallet_code', - value: '', + value: '419100', last_update: '2022-11-22T17:27:19+0100', localized: 'Code porte-monnaie' }, { name: 'accounting_wallet_label', - value: '', + value: 'Wallet credit', last_update: '2022-11-22T17:27:19+0100', localized: 'Libellé porte-monnaie' }, { name: 'accounting_VAT_label', - value: '', + value: 'VAT', last_update: '2022-11-22T17:27:19+0100', localized: 'Libellé TVA' }, { name: 'accounting_subscription_code', - value: '', + value: '7061', last_update: '2022-11-22T17:27:19+0100', localized: 'Code abonnements' }, { name: 'accounting_subscription_label', - value: '', + value: 'Subscriptions', last_update: '2022-11-22T17:27:19+0100', localized: 'Libellé abonnements' }, { name: 'accounting_Machine_code', - value: '', + value: '7065', last_update: '2022-11-22T17:27:19+0100', localized: 'Code machines' }, { name: 'accounting_Machine_label', - value: '', + value: 'Machine reservation', last_update: '2022-11-22T17:27:19+0100', localized: 'Libellé machines' }, { name: 'accounting_Training_code', - value: '', + value: '7062', last_update: '2022-11-22T17:27:19+0100', localized: 'Code formations' }, { name: 'accounting_Training_label', - value: '', + value: 'Training reservation', last_update: '2022-11-22T17:27:19+0100', localized: 'Libellé formations' }, { name: 'accounting_Event_code', - value: '', + value: '7063', last_update: '2022-11-22T17:27:19+0100', localized: 'Code évènements' }, { name: 'accounting_Event_label', - value: '', + value: 'Event reservation', last_update: '2022-11-22T17:27:19+0100', localized: 'Libellé évènements' }, { name: 'accounting_Space_code', - value: '', + value: '7064', last_update: '2022-11-22T17:27:19+0100', localized: 'Code espaces' }, { name: 'accounting_Space_label', - value: '', + value: 'Space reservation', last_update: '2022-11-22T17:27:19+0100', localized: 'Libellé espaces' }, { name: 'accounting_Pack_code', - value: '', + value: '7066', last_update: '2022-11-22T17:27:19+0100', - localized: 'translation missing: fr.settings.accounting_Pack_code' + localized: "Code packs d'heures prépayées" }, { name: 'accounting_Pack_label', - value: '', + value: 'Prepaid pack', last_update: '2022-11-22T17:27:20+0100', - localized: 'translation missing: fr.settings.accounting_Pack_label' + localized: "Libellé packs d'heures prépayées" }, { name: 'accounting_Product_code', - value: '', + value: '7071', last_update: '2022-11-22T17:27:20+0100', - localized: 'translation missing: fr.settings.accounting_Product_code' + localized: 'Code des produits de la boutique' }, { name: 'accounting_Product_label', - value: '', + value: 'Shop order', last_update: '2022-11-22T17:27:20+0100', - localized: 'translation missing: fr.settings.accounting_Product_label' + localized: 'Libellé des produits de la boutique' }, { name: 'accounting_Error_code', @@ -690,5 +690,35 @@ export const settings: Array = [ value: '', last_update: '2022-11-22T17:27:20+0100', localized: 'Libellé erreurs' + }, + { + name: 'accounting_card_client_journal_code', + value: 'CB01', + last_update: '2022-11-22T17:27:20+0100', + localized: 'Libellé erreurs' + }, + { + name: 'accounting_wallet_client_journal_code', + value: 'W001', + last_update: '2022-11-22T17:27:20+0100', + localized: 'Libellé erreurs' + }, + { + name: 'accounting_other_client_journal_code', + value: 'CA01', + last_update: '2022-11-22T17:27:20+0100', + localized: 'Libellé erreurs' + }, + { + name: 'accounting_wallet_journal_code', + value: 'W002', + last_update: '2022-11-22T17:27:20+0100', + localized: 'Libellé erreurs' + }, + { + name: 'accounting_VAT_journal_code', + value: 'TVA1', + last_update: '2022-11-22T17:27:20+0100', + localized: 'Libellé erreurs' } ]; diff --git a/test/integration/exports/accounting_export_test.rb b/test/integration/exports/accounting_export_test.rb index 076a199bc..463ba5d8a 100644 --- a/test/integration/exports/accounting_export_test.rb +++ b/test/integration/exports/accounting_export_test.rb @@ -80,7 +80,6 @@ class Exports::AccountingExportTest < ActionDispatch::IntegrationTest end def check_client_line(invoice, client_line) - check_journal_code(client_line) check_entry_date(invoice, client_line) check_client_accounts(invoice, client_line) check_entry_label(invoice, client_line) @@ -99,7 +98,7 @@ class Exports::AccountingExportTest < ActionDispatch::IntegrationTest end def check_item_line(invoice, invoice_item, item_line) - check_journal_code(item_line) + check_sales_journal_code(item_line) check_entry_date(invoice, item_line) check_subscription_accounts(invoice, item_line) @@ -115,8 +114,8 @@ class Exports::AccountingExportTest < ActionDispatch::IntegrationTest assert_equal 0, item_line[I18n.t('accounting_export.debit_euro')].to_f, 'Debit euro amount does not match' end - def check_journal_code(line) - journal_code = Setting.get('accounting_journal_code') + def check_sales_journal_code(line) + journal_code = Setting.get('accounting_sales_journal_code') assert_equal journal_code, line[I18n.t('accounting_export.journal_code')], 'Wrong journal code' end @@ -132,6 +131,9 @@ class Exports::AccountingExportTest < ActionDispatch::IntegrationTest wallet_client_label = Setting.get('accounting_wallet_client_label') assert_equal wallet_client_label, client_line[I18n.t('accounting_export.account_label')], 'Account label for wallet client is wrong' + + wallet_client_journal = Setting.get('accounting_wallet_client_journal_code') + assert_equal wallet_client_journal, client_line[I18n.t('accounting_export.journal_code')], 'Journal code for wallet client is wrong' end mean = invoice.paid_by_card? ? 'card' : 'other' @@ -140,6 +142,9 @@ class Exports::AccountingExportTest < ActionDispatch::IntegrationTest client_label = Setting.get("accounting_#{mean}_client_label") assert_equal client_label, client_line[I18n.t('accounting_export.account_label')], 'Account label for client is wrong' + + client_journal = Setting.get("accounting_#{mean}_client_journal_code") + assert_equal client_journal, client_line[I18n.t('accounting_export.journal_code')], 'Journal code for client is wrong' end def check_subscription_accounts(invoice, item_line) diff --git a/test/services/accounting_service_test.rb b/test/services/accounting_service_test.rb index e4932a257..d836fdcbc 100644 --- a/test/services/accounting_service_test.rb +++ b/test/services/accounting_service_test.rb @@ -60,20 +60,24 @@ class AccountingServiceTest < ActionDispatch::IntegrationTest client_wallet = lines.find { |l| l.account_code == Setting.get('accounting_wallet_client_code') } assert_not_nil client_wallet assert_equal 1000, client_wallet&.debit + assert_equal Setting.get('accounting_wallet_client_journal_code'), client_wallet&.journal_code # Check the local payment line client_other = lines.find { |l| l.account_code == Setting.get('accounting_other_client_code') } assert_not_nil client_other assert_equal invoice.total - 1000, client_other&.debit + assert_equal Setting.get('accounting_other_client_journal_code'), client_other&.journal_code # Check the machine reservation line assert 2, lines.filter { |l| l.line_type == 'item' }.count item_machine = lines.find { |l| l.account_code == Setting.get('accounting_Machine_code') } assert_not_nil item_machine assert_equal invoice.main_item.net_amount, item_machine&.credit + assert_equal Setting.get('accounting_sales_journal_code'), item_machine&.journal_code # Check the subscription line item_suscription = lines.find { |l| l.account_code == Setting.get('accounting_subscription_code') } assert_not_nil item_suscription assert_equal invoice.other_items.last.net_amount, item_suscription&.credit + assert_equal Setting.get('accounting_sales_journal_code'), item_suscription&.journal_code # Check the VAT line vat_service = VatHistoryService.new @@ -82,5 +86,6 @@ class AccountingServiceTest < ActionDispatch::IntegrationTest vat_line = lines.find { |l| l.account_code == Setting.get('accounting_VAT_code') } assert_not_nil vat_line assert_equal vat_rate_groups.values.pluck(:total_vat).sum, vat_line&.credit + assert_equal Setting.get('accounting_VAT_journal_code'), vat_line&.journal_code end end