From d786cb13f65cd323f59ff7ee9f62c3861c810955 Mon Sep 17 00:00:00 2001 From: Pierre Masereel Date: Mon, 20 May 2019 12:45:21 +0000 Subject: [PATCH] [IMP] account: default cash difference account When a cash journal is used in POS, we need to have accounts to post the difference between what it's supposed to be in the cash journal and what we really have in the cashbox. To help the user to configure his cash journal, we've added default accounts for cash difference in the localisation. Those default values are stored on the company and are use for the creation of cash journals if no values are provided. TASK-ID: 1934784 --- addons/account/models/account.py | 12 +++++++++--- addons/account/models/chart_template.py | 8 ++++++++ addons/account/models/company.py | 2 ++ .../data/account.account.template.csv | 2 ++ .../data/l10n_generic_coa_chart_post_data.xml | 2 ++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/addons/account/models/account.py b/addons/account/models/account.py index d99559672c3..bf8dafbbb58 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -583,8 +583,8 @@ class AccountJournal(models.Model): "SEPA Credit Transfer: Pay bill from a SEPA Credit Transfer file you submit to your bank. Enable this option from the settings.") at_least_one_inbound = fields.Boolean(compute='_methods_compute', store=True) at_least_one_outbound = fields.Boolean(compute='_methods_compute', store=True) - profit_account_id = fields.Many2one('account.account', string='Profit Account', domain=[('deprecated', '=', False)], help="Used to register a profit when the ending balance of a cash register differs from what the system computes") - loss_account_id = fields.Many2one('account.account', string='Loss Account', domain=[('deprecated', '=', False)], help="Used to register a loss when the ending balance of a cash register differs from what the system computes") + profit_account_id = fields.Many2one('account.account', string='Profit Account', help="Used to register a profit when the ending balance of a cash register differs from what the system computes") + loss_account_id = fields.Many2one('account.account', string='Loss Account', help="Used to register a loss when the ending balance of a cash register differs from what the system computes") belongs_to_company = fields.Boolean('Belong to the user\'s current company', compute="_belong_to_company", search="_search_company_journals",) @@ -874,12 +874,18 @@ class AccountJournal(models.Model): # Create a default debit/credit account if not given default_account = vals.get('default_debit_account_id') or vals.get('default_credit_account_id') + company = self.env['res.company'].browse(company_id) if not default_account: - company = self.env['res.company'].browse(company_id) account_vals = self._prepare_liquidity_account(vals.get('name'), company, vals.get('currency_id'), vals.get('type')) default_account = self.env['account.account'].create(account_vals) vals['default_debit_account_id'] = default_account.id vals['default_credit_account_id'] = default_account.id + if vals['type'] == 'cash': + if not vals.get('profit_account_id'): + vals['profit_account_id'] = company.default_cash_difference_income_account_id.id + if not vals.get('loss_account_id'): + vals['loss_account_id'] = company.default_cash_difference_expense_account_id.id + # We just need to create the relevant sequences according to the chosen options if not vals.get('sequence_id'): diff --git a/addons/account/models/chart_template.py b/addons/account/models/chart_template.py index 8265620ef47..025394dbe69 100644 --- a/addons/account/models/chart_template.py +++ b/addons/account/models/chart_template.py @@ -114,6 +114,8 @@ class AccountChartTemplate(models.Model): string="Gain Exchange Rate Account", domain=[('internal_type', '=', 'other'), ('deprecated', '=', False)]) expense_currency_exchange_account_id = fields.Many2one('account.account.template', string="Loss Exchange Rate Account", domain=[('internal_type', '=', 'other'), ('deprecated', '=', False)]) + default_cash_difference_income_account_id = fields.Many2one('account.account.template', string="Cash Difference Income Account") + default_cash_difference_expense_account_id = fields.Many2one('account.account.template', string="Cash Difference Expense Account") property_account_receivable_id = fields.Many2one('account.account.template', string='Receivable Account', oldname="property_account_receivable") property_account_payable_id = fields.Many2one('account.account.template', string='Payable Account', oldname="property_account_payable") property_account_expense_categ_id = fields.Many2one('account.account.template', string='Category of Expense Account', oldname="property_account_expense_categ") @@ -242,6 +244,12 @@ class AccountChartTemplate(models.Model): # Install all the templates objects and generate the real objects acc_template_ref, taxes_ref = self._install_template(company, code_digits=self.code_digits) + # Set default cash difference account on company + company.write({ + 'default_cash_difference_income_account_id': acc_template_ref.get(self.default_cash_difference_income_account_id.id, False), + 'default_cash_difference_expense_account_id': acc_template_ref.get(self.default_cash_difference_expense_account_id.id, False), + }) + # Set the transfer account on the company company.transfer_account_id = self.env['account.account'].search([('code', '=like', self.transfer_account_code_prefix + '%')])[0] diff --git a/addons/account/models/company.py b/addons/account/models/company.py index bd0b1dbdd7f..ed1a8fdacbc 100644 --- a/addons/account/models/company.py +++ b/addons/account/models/company.py @@ -43,6 +43,8 @@ class ResCompany(models.Model): chart_template_id = fields.Many2one('account.chart.template', help='The chart template for the company (if any)') bank_account_code_prefix = fields.Char(string='Prefix of the bank accounts', oldname="bank_account_code_char") cash_account_code_prefix = fields.Char(string='Prefix of the cash accounts') + default_cash_difference_income_account_id = fields.Many2one('account.account', string="Cash Difference Income Account") + default_cash_difference_expense_account_id = fields.Many2one('account.account', string="Cash Difference Expense Account") transfer_account_code_prefix = fields.Char(string='Prefix of the transfer accounts') account_sale_tax_id = fields.Many2one('account.tax', string="Default Sale Tax") account_purchase_tax_id = fields.Many2one('account.tax', string="Default Purchase Tax") diff --git a/addons/l10n_generic_coa/data/account.account.template.csv b/addons/l10n_generic_coa/data/account.account.template.csv index 1fe1e23b8ca..2c5c82a6cc9 100644 --- a/addons/l10n_generic_coa/data/account.account.template.csv +++ b/addons/l10n_generic_coa/data/account.account.template.csv @@ -16,8 +16,10 @@ "cas","Non-current Liabilities","1120","account.data_account_type_non_current_liabilities","l10n_generic_coa.configurable_chart_template","","False" "conf_a_sale","Product Sales","200","account.data_account_type_revenue","l10n_generic_coa.configurable_chart_template","account.account_tag_operating","False" "exchange_fx_income","Foreign Exchange Gain","2010","account.data_account_type_revenue","l10n_generic_coa.configurable_chart_template","account.account_tag_financing","False" +"cash_diff_income","Cash Difference Gain","2020","account.data_account_type_revenue","l10n_generic_coa.configurable_chart_template","account.account_tag_investing","False" "conf_cog","Cost of Goods Sold","210","account.data_account_type_direct_costs","l10n_generic_coa.configurable_chart_template","account.account_tag_operating","False" "exchange_fx_expense","Foreign Exchange Loss","2110","account.data_account_type_expenses","l10n_generic_coa.configurable_chart_template","account.account_tag_financing","False" +"cash_diff_expense","Cash Difference Loss","2120","account.data_account_type_expenses","l10n_generic_coa.configurable_chart_template","account.account_tag_investing","False" "a_salary_expense","Salary Expenses","2121","account.data_account_type_expenses","l10n_generic_coa.configurable_chart_template","account.account_tag_operating","False" "a_expense_invest","Purchase of Equipments","2122","account.data_account_type_expenses","l10n_generic_coa.configurable_chart_template","account.account_tag_investing","False" "a_expense_finance","Bank Fees","2123","account.data_account_type_expenses","l10n_generic_coa.configurable_chart_template","account.account_tag_financing","False" diff --git a/addons/l10n_generic_coa/data/l10n_generic_coa_chart_post_data.xml b/addons/l10n_generic_coa/data/l10n_generic_coa_chart_post_data.xml index 83696d77f65..872c609690e 100644 --- a/addons/l10n_generic_coa/data/l10n_generic_coa_chart_post_data.xml +++ b/addons/l10n_generic_coa/data/l10n_generic_coa_chart_post_data.xml @@ -12,5 +12,7 @@ + +