[IMP] account: added cash_account_code_prefix to allow having a different prefix for cash accounts and bank accounts + renamed field 'bank_account_code_char' into 'bank_account_code_prefix' for being more self-explanatory and meaningful
This commit is contained in:
@@ -314,23 +314,27 @@ class AccountJournal(models.Model):
|
||||
return self.env['ir.sequence'].create(seq)
|
||||
|
||||
@api.model
|
||||
def _prepare_bank_account(self, name, company, currency_id):
|
||||
def _prepare_liquidity_account(self, name, company, currency_id, type):
|
||||
'''
|
||||
This function prepares the value to use for the creation of the default debit and credit accounts of a
|
||||
bank journal (created through the wizard of generating COA from templates for example).
|
||||
liquidity journal (created through the wizard of generating COA from templates for example).
|
||||
|
||||
:param name: name of the bank account
|
||||
:param company: company for which the wizard is running
|
||||
:param currency_id: ID of the currency in wich is the bank account
|
||||
:param type: either 'cash' or 'bank'
|
||||
:return: mapping of field names and values
|
||||
:rtype: dict
|
||||
'''
|
||||
|
||||
# Seek the next available number for the account code
|
||||
code_digits = company.accounts_code_digits or 0
|
||||
bank_account_code_char = company.bank_account_code_char or ''
|
||||
if type == 'bank':
|
||||
account_code_prefix = company.bank_account_code_prefix or ''
|
||||
else:
|
||||
account_code_prefix = company.cash_account_code_prefix or company.bank_account_code_prefix or ''
|
||||
for num in xrange(1, 100):
|
||||
new_code = str(bank_account_code_char.ljust(code_digits - 1, '0')) + str(num)
|
||||
new_code = str(account_code_prefix.ljust(code_digits - 1, '0')) + str(num)
|
||||
rec = self.env['account.account'].search([('code', '=', new_code), ('company_id', '=', company.id)], limit=1)
|
||||
if not rec:
|
||||
break
|
||||
@@ -387,7 +391,7 @@ class AccountJournal(models.Model):
|
||||
default_account = vals.get('default_debit_account_id') or vals.get('default_credit_account_id')
|
||||
if not default_account:
|
||||
company = self.env['res.company'].browse(vals['company_id'])
|
||||
account_vals = self._prepare_bank_account(vals.get('name'), company, vals.get('currency_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
|
||||
|
||||
@@ -69,7 +69,8 @@ class AccountChartTemplate(models.Model):
|
||||
account_ids = fields.One2many('account.account.template', 'chart_template_id', string='Associated Account Templates')
|
||||
tax_template_ids = fields.One2many('account.tax.template', 'chart_template_id', string='Tax Template List',
|
||||
help='List of all the taxes that have to be installed by the wizard')
|
||||
bank_account_code_char = fields.Char(string='Code of the main bank account')
|
||||
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 main cash accounts')
|
||||
transfer_account_id = fields.Many2one('account.account.template', string='Transfer Account', required=True,
|
||||
domain=lambda self: [('reconcile', '=', True), ('user_type_id.id', '=', self.env.ref('account.data_account_type_current_assets').id)],
|
||||
help="Intermediary account used when moving money from a liquidity account to another")
|
||||
@@ -99,7 +100,8 @@ class AccountChartTemplate(models.Model):
|
||||
'code_digits': self.code_digits,
|
||||
'transfer_account_id': self.transfer_account_id.id,
|
||||
'currency_id': self.currency_id.id,
|
||||
'bank_account_code_char': self.bank_account_code_char,
|
||||
'bank_account_code_prefix': self.bank_account_code_prefix,
|
||||
'cash_account_code_prefix': self.cash_account_code_prefix,
|
||||
})
|
||||
wizard.onchange_chart_template_id()
|
||||
wizard.execute()
|
||||
@@ -551,7 +553,8 @@ class WizardMultiChartsAccounts(models.TransientModel):
|
||||
only_one_chart_template = fields.Boolean(string='Only One Chart Template Available')
|
||||
chart_template_id = fields.Many2one('account.chart.template', string='Chart Template', required=True)
|
||||
bank_account_ids = fields.One2many('account.bank.accounts.wizard', 'bank_account_id', string='Cash and Banks', required=True, oldname="bank_accounts_id")
|
||||
bank_account_code_char = fields.Char('Bank Accounts Code')
|
||||
bank_account_code_prefix = fields.Char('Bank Accounts Prefix', oldname="bank_account_code_char")
|
||||
cash_account_code_prefix = fields.Char('Cash Accounts Prefix')
|
||||
code_digits = fields.Integer(string='# of Digits', required=True, help="No. of Digits to use for account code")
|
||||
sale_tax_id = fields.Many2one('account.tax.template', string='Default Sales Tax', oldname="sale_tax")
|
||||
purchase_tax_id = fields.Many2one('account.tax.template', string='Default Purchase Tax', oldname="purchase_tax")
|
||||
@@ -608,8 +611,10 @@ class WizardMultiChartsAccounts(models.TransientModel):
|
||||
self.transfer_account_id = self.chart_template_id.transfer_account_id.id
|
||||
if self.chart_template_id.code_digits:
|
||||
self.code_digits = self.chart_template_id.code_digits
|
||||
if self.chart_template_id.bank_account_code_char:
|
||||
self.bank_account_code_char = self.chart_template_id.bank_account_code_char
|
||||
if self.chart_template_id.bank_account_code_prefix:
|
||||
self.bank_account_code_prefix = self.chart_template_id.bank_account_code_prefix
|
||||
if self.chart_template_id.cash_account_code_prefix:
|
||||
self.cash_account_code_prefix = self.chart_template_id.cash_account_code_prefix
|
||||
return res
|
||||
|
||||
@api.model
|
||||
@@ -714,7 +719,8 @@ class WizardMultiChartsAccounts(models.TransientModel):
|
||||
self.company_id.write({'currency_id': self.currency_id.id,
|
||||
'accounts_code_digits': self.code_digits,
|
||||
'anglo_saxon_accounting': self.use_anglo_saxon,
|
||||
'bank_account_code_char': self.bank_account_code_char,
|
||||
'bank_account_code_prefix': self.bank_account_code_prefix,
|
||||
'cash_account_code_prefix': self.cash_account_code_prefix,
|
||||
'chart_template_id': self.chart_template_id.id})
|
||||
|
||||
# When we install the CoA of first company, set the currency to price types and pricelists
|
||||
@@ -770,10 +776,6 @@ class WizardMultiChartsAccounts(models.TransientModel):
|
||||
'currency_id': acc.currency_id.id,
|
||||
}
|
||||
journal_data.append(vals)
|
||||
ref_acc_bank = self.bank_account_code_char
|
||||
if journal_data and not ref_acc_bank:
|
||||
raise UserError(_('You have to set a code for the bank account defined on the selected chart of accounts.'))
|
||||
company.write({'bank_account_code_char': ref_acc_bank})
|
||||
|
||||
for line in journal_data:
|
||||
if line['account_type'] == 'bank':
|
||||
|
||||
@@ -8,7 +8,6 @@ class ResCompany(models.Model):
|
||||
_inherit = "res.company"
|
||||
|
||||
#TODO check all the options/fields are in the views (settings + company form view)
|
||||
#TODO: add a cash_register_code_char for allowing cash journals' accounts having a different numbering than bank journals' accounts.
|
||||
fiscalyear_last_day = fields.Integer(default=31, required=True)
|
||||
fiscalyear_last_month = fields.Selection([(1, 'January'), (2, 'February'), (3, 'March'), (4, 'April'), (5, 'May'), (6, 'June'), (7, 'July'), (8, 'August'), (9, 'September'), (10, 'October'), (11, 'November'), (12, 'December')], default=12, required=True)
|
||||
period_lock_date = fields.Date(help="Only users with the 'Adviser' role can edit accounts prior to and inclusive of this date")
|
||||
@@ -17,7 +16,8 @@ class ResCompany(models.Model):
|
||||
domain=lambda self: [('reconcile', '=', True), ('user_type_id.id', '=', self.env.ref('account.data_account_type_current_assets').id), ('deprecated', '=', False)], string="Transfer Account", help="Intermediary account used when moving money from a liquidity account to another")
|
||||
expects_chart_of_accounts = fields.Boolean(string='Expects a Chart of Accounts', default=True)
|
||||
chart_template_id = fields.Many2one('account.chart.template', help='The chart template for the company (if any)')
|
||||
bank_account_code_char = fields.Char(string='Code of the main bank account')
|
||||
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')
|
||||
accounts_code_digits = fields.Integer(string='Number of digits in an account code')
|
||||
tax_calculation_rounding_method = fields.Selection([
|
||||
('round_per_line', 'Round per Line'),
|
||||
@@ -53,22 +53,26 @@ class ResCompany(models.Model):
|
||||
date_from = date_from.replace(year=date_from.year - 1)
|
||||
return {'date_from': date_from, 'date_to': date_to}
|
||||
|
||||
def get_new_account_code(self, code, old_prefix, new_prefix, digits):
|
||||
def get_new_account_code(self, current_code, old_prefix, new_prefix, digits):
|
||||
new_prefix_length = len(new_prefix)
|
||||
number = str(int(code[len(old_prefix):]))
|
||||
code = new_prefix + str('0' * (digits - new_prefix_length - len(number))) + number
|
||||
return code
|
||||
number = current_code[len(old_prefix):]
|
||||
return new_prefix + '0' * (digits - new_prefix_length - len(number)) + number
|
||||
|
||||
def reflect_code_prefix_change(self, old_code, new_code, digits):
|
||||
accounts = self.env['account.account'].search([('code', 'like', old_code), ('internal_type', '=', 'liquidity'),
|
||||
('company_id', '=', self.id)], order='code asc')
|
||||
for account in accounts:
|
||||
if account.code.startswith(old_code):
|
||||
account.write({'code': self.get_new_account_code(account.code, old_code, new_code, digits)})
|
||||
|
||||
@api.multi
|
||||
def write(self, values):
|
||||
# Repercute the change on accounts
|
||||
if values.get('bank_account_code_char', False) or values.get('accounts_code_digits', False):
|
||||
bank_code = values.get('bank_account_code_char', False) or self.bank_account_code_char
|
||||
digits = values.get('accounts_code_digits', False) or self.accounts_code_digits
|
||||
|
||||
accounts = self.env['account.account'].search([('code', 'like', self.bank_account_code_char), ('internal_type', '=', 'liquidity'),
|
||||
('company_id', '=', self.id)], order='code asc')
|
||||
for account in accounts:
|
||||
if account.code.startswith(self.bank_account_code_char):
|
||||
account.write({'code': self.get_new_account_code(account.code, self.bank_account_code_char, bank_code, digits)})
|
||||
# Reflect the change on accounts
|
||||
digits = values.get('accounts_code_digits') or self.accounts_code_digits
|
||||
if values.get('bank_account_code_prefix') or values.get('accounts_code_digits'):
|
||||
new_bank_code = values.get('bank_account_code_prefix') or self.bank_account_code_prefix
|
||||
self.reflect_code_prefix_change(self.bank_account_code_prefix, new_bank_code, digits)
|
||||
if values.get('cash_account_code_prefix') or values.get('accounts_code_digits'):
|
||||
new_cash_code = values.get('cash_account_code_prefix') or self.cash_account_code_prefix
|
||||
self.reflect_code_prefix_change(self.cash_account_code_prefix, new_cash_code, digits)
|
||||
return super(ResCompany, self).write(values)
|
||||
|
||||
@@ -52,7 +52,8 @@ class AccountConfigSettings(models.TransientModel):
|
||||
purchase_tax_id = fields.Many2one('account.tax.template', string='Default purchase tax', oldname="purchase_tax")
|
||||
sale_tax_rate = fields.Float(string='Sales tax (%)')
|
||||
purchase_tax_rate = fields.Float(string='Purchase tax (%)')
|
||||
bank_account_code_char = fields.Char(string='Bank Accounts Code', related='company_id.bank_account_code_char', help='Define the code for the bank account')
|
||||
bank_account_code_prefix = fields.Char(string='Bank Accounts Prefix', related='company_id.bank_account_code_prefix', help='Define the code prefix for the bank accounts', oldname'bank_account_code_char')
|
||||
cash_account_code_prefix = fields.Char(string='Cash Accounts Prefix', related='company_id.cash_account_code_prefix', help='Define the code prefix for the cash accounts')
|
||||
template_transfer_account_id = fields.Many2one('account.account.template', help="Intermediary account used when moving money from a liquidity account to another")
|
||||
transfer_account_id = fields.Many2one('account.account',
|
||||
related='company_id.transfer_account_id',
|
||||
@@ -132,7 +133,8 @@ class AccountConfigSettings(models.TransientModel):
|
||||
self.paypal_account = company.paypal_account
|
||||
self.company_footer = company.rml_footer
|
||||
self.tax_calculation_rounding_method = company.tax_calculation_rounding_method
|
||||
self.bank_account_code_char = company.bank_account_code_char
|
||||
self.bank_account_code_prefix = company.bank_account_code_prefix
|
||||
self.cash_account_code_prefix = company.cash_account_code_prefix
|
||||
self.code_digits = company.accounts_code_digits
|
||||
|
||||
# update taxes
|
||||
@@ -166,8 +168,10 @@ class AccountConfigSettings(models.TransientModel):
|
||||
self.code_digits = self.chart_template_id.code_digits
|
||||
if self.chart_template_id.transfer_account_id:
|
||||
self.template_transfer_account_id = self.chart_template_id.transfer_account_id.id
|
||||
if self.chart_template_id.bank_account_code_char:
|
||||
self.bank_account_code_char = self.chart_template_id.bank_account_code_char
|
||||
if self.chart_template_id.bank_account_code_prefix:
|
||||
self.bank_account_code_prefix = self.chart_template_id.bank_account_code_prefix
|
||||
if self.chart_template_id.cash_account_code_prefix:
|
||||
self.cash_account_code_prefix = self.chart_template_id.cash_account_code_prefix
|
||||
return {}
|
||||
|
||||
@api.onchange('sale_tax_rate')
|
||||
@@ -224,7 +228,8 @@ class AccountConfigSettings(models.TransientModel):
|
||||
'purchase_tax_rate': self.purchase_tax_rate,
|
||||
'complete_tax_set': self.complete_tax_set,
|
||||
'currency_id': self.currency_id.id,
|
||||
'bank_account_code_char': self.bank_account_code_char,
|
||||
'bank_account_code_prefix': self.bank_account_code_prefix,
|
||||
'cash_account_code_prefix': self.cash_account_code_prefix,
|
||||
})
|
||||
wizard.execute()
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<!-- This should be loaded for non python tests in other modules that require accounting test data but that don't depend on any localization -->
|
||||
|
||||
<record id="base.main_company" model="res.company">
|
||||
<field name="bank_account_code_char">X1100</field>
|
||||
<field name="bank_account_code_prefix">X1100</field>
|
||||
<field name="accounts_code_digits">7</field>
|
||||
</record>
|
||||
|
||||
|
||||
@@ -1466,7 +1466,8 @@
|
||||
<field name="name"/>
|
||||
<field name="company_id"/>
|
||||
<field name="parent_id" />
|
||||
<field name="bank_account_code_char"/>
|
||||
<field name="bank_account_code_prefix"/>
|
||||
<field name="cash_account_code_prefix"/>
|
||||
<field name="code_digits" />
|
||||
<field name="visible" />
|
||||
<field name="complete_tax_set" />
|
||||
@@ -1492,9 +1493,9 @@
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search Chart of Account Templates">
|
||||
<field name="name" string="Account Template"/>
|
||||
<field name="bank_account_code_char"/>
|
||||
<field name="bank_account_code_prefix"/>
|
||||
<field name="cash_account_code_prefix"/>
|
||||
<group expand="0" string="Group By">
|
||||
<filter string="Bank Account" icon="terp-folder-orange" domain="[]" context="{'group_by':'bank_account_code_char'}"/>
|
||||
<filter string="Receivable Account" icon="terp-sale" domain="[]" context="{'group_by':'property_account_receivable_id'}"/>
|
||||
<filter string="Payable Account" icon="terp-purchase" domain="[]" context="{'group_by':'property_account_payable_id'}"/>
|
||||
<filter string="Income Account" icon="terp-sale" domain="[]" context="{'group_by':'property_account_income_categ_id'}"/>
|
||||
@@ -1510,7 +1511,6 @@
|
||||
<tree string="Chart of Accounts Template">
|
||||
<field name="name"/>
|
||||
<field name="company_id"/>
|
||||
<field name="bank_account_code_char"/>
|
||||
<field name="property_account_receivable_id" invisible="1"/>
|
||||
<field name="property_account_payable_id" invisible="1"/>
|
||||
<field name="property_account_expense_categ_id" invisible="1"/>
|
||||
@@ -1650,7 +1650,8 @@
|
||||
</group>
|
||||
<group groups="account.group_account_user" invisible="1">
|
||||
<field name="code_digits"/>
|
||||
<field name="bank_account_code_char"/>
|
||||
<field name="bank_account_code_prefix"/>
|
||||
<field name="cash_account_code_prefix"/>
|
||||
</group>
|
||||
</group>
|
||||
</group>
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
<field name="anglo_saxon_accounting"/>
|
||||
</field>
|
||||
<xpath expr="//group[@name='account_grp']" position="inside">
|
||||
<field name="bank_account_code_char" groups="base.group_no_one"/>
|
||||
<field name="bank_account_code_prefix" groups="base.group_no_one"/>
|
||||
<field name="cash_account_code_prefix" groups="base.group_no_one"/>
|
||||
<field name="accounts_code_digits" groups="base.group_no_one"/>
|
||||
</xpath>
|
||||
</field>
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
'transfer_account_id': ref("account.transfer_account_id"),
|
||||
'code_digits': 6,
|
||||
'purchase_tax_id': False,
|
||||
'bank_account_code_char': 'COMP_A',
|
||||
'bank_account_code_prefix': 'COMP_A',
|
||||
'sale_tax_id': False})
|
||||
self.execute(cr, uid, [wiz_comp_a])
|
||||
wiz_comp_b = self.create(cr, uid, {
|
||||
@@ -127,7 +127,7 @@
|
||||
'transfer_account_id': ref("account.transfer_account_id"),
|
||||
'code_digits': 6,
|
||||
'purchase_tax_id': False,
|
||||
'bank_account_code_char': 'COMP_B',
|
||||
'bank_account_code_prefix': 'COMP_B',
|
||||
'sale_tax_id': False})
|
||||
self.execute(cr, uid, [wiz_comp_b])
|
||||
-
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<record id="uae_chart_template_standard" model="account.chart.template">
|
||||
<field name="name">U.A.E Chart of Accounts - Standard</field>
|
||||
<field name="code_digits">6</field>
|
||||
<field name="bank_account_code_char">101</field>
|
||||
<field name="bank_account_code_prefix">101</field>
|
||||
<field name="currency_id" ref="base.AED" />
|
||||
<field name="transfer_account_id" ref="transfer_account_id"/>
|
||||
<field name="complete_tax_set" eval="False"/>
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
</record>
|
||||
|
||||
<record id="transfer_account_id" model="account.account.template">
|
||||
<field name="name">cuenta de Transferencia</field>
|
||||
<field name="code">1</field>
|
||||
<field name="name">Cuenta de Transferencia</field>
|
||||
<field name="code">13</field>
|
||||
<field name="reconcile" eval="True"/>
|
||||
<field ref="account.data_account_type_current_assets" name="user_type_id"/>
|
||||
</record>
|
||||
@@ -19,7 +19,8 @@
|
||||
<record id="ar_chart_template" model="account.chart.template">
|
||||
<field name="name">Argentina - Plan de Cuentas</field>
|
||||
<field name="code_digits">6</field>
|
||||
<field name="bank_account_code_char">11</field>
|
||||
<field name="bank_account_code_prefix">11</field>
|
||||
<field name="cash_account_code_prefix">12</field>
|
||||
<field name="currency_id" ref="base.ARS"/>
|
||||
<field name="transfer_account_id" ref="transfer_account_id"/>
|
||||
</record>
|
||||
|
||||
@@ -1153,7 +1153,8 @@
|
||||
|
||||
<record id="l10nbe_chart_template" model="account.chart.template">
|
||||
<field name="name">Belgian PCMN</field>
|
||||
<field name="bank_account_code_char">550</field>
|
||||
<field name="bank_account_code_prefix">550</field>
|
||||
<field name="cash_account_code_prefix">570</field>
|
||||
<field name="code_digits">6</field>
|
||||
<field name="transfer_account_id" ref="trans"/>
|
||||
<field name="property_account_receivable_id" ref="a4000"/>
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
<record id="configurable_chart_template" model="account.chart.template">
|
||||
<field name="name">Configurable Account Chart Template</field>
|
||||
<field name="code_digits">6</field>
|
||||
<field name="bank_account_code_char">1014</field>
|
||||
<field name="bank_account_code_prefix">1014</field>
|
||||
<field name="cash_account_code_prefix">1015</field>
|
||||
<field name="transfer_account_id" ref="transfer_account_id"/>
|
||||
<field name="currency_id" ref="base.USD"/>
|
||||
</record>
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
<openerp>
|
||||
<data noupdate="1">
|
||||
<record id="transfer_account_id" model="account.account.template">
|
||||
<field name="code">550</field>
|
||||
<field name="name">cuenta de Transferencia</field>
|
||||
<field name="code">1.0.03.01</field>
|
||||
<field name="name">Cuenta de Transferencia</field>
|
||||
<field name="reconcile" eval='True'/>
|
||||
<field name="user_type_id" ref="account.data_account_type_current_assets"/>
|
||||
</record>
|
||||
|
||||
<record id="cuentas_plantilla" model="account.chart.template">
|
||||
<field name="name">Plantilla de cuentas de Guatemala (sencilla)</field>
|
||||
<field name="bank_account_code_char">550</field>
|
||||
<field name="bank_account_code_prefix">1.0.01.0</field>
|
||||
<field name="cash_account_code_prefix">1.0.02.0</field>
|
||||
<field name="code_digits">6</field>
|
||||
<field name="currency_id" ref="base.QTQ"/>
|
||||
<field name="transfer_account_id" ref="transfer_account_id"/>
|
||||
@@ -256,4 +257,4 @@
|
||||
</record>
|
||||
</data>
|
||||
|
||||
</openerp>
|
||||
</openerp>
|
||||
|
||||
Reference in New Issue
Block a user