diff --git a/addons/account/__openerp__.py b/addons/account/__openerp__.py
index 0cd5231ef26..850a8f49842 100644
--- a/addons/account/__openerp__.py
+++ b/addons/account/__openerp__.py
@@ -151,7 +151,7 @@ module named account_voucher.
'test/account_fiscalyear_close_state.yml', #last test, as it will definitively close the demo fiscalyear
],
'installable': True,
- 'active': False,
+ 'auto_install': False,
'certificate': '0080331923549',
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/account/account.py b/addons/account/account.py
index 432a90a653e..b97fd870749 100644
--- a/addons/account/account.py
+++ b/addons/account/account.py
@@ -381,8 +381,9 @@ class account_account(osv.osv):
def _get_level(self, cr, uid, ids, field_name, arg, context=None):
res = {}
- accounts = self.browse(cr, uid, ids, context=context)
- for account in accounts:
+ for account in self.browse(cr, uid, ids, context=context):
+ #we may not know the level of the parent at the time of computation, so we
+ # can't simply do res[account.id] = account.parent_id.level + 1
level = 0
parent = account.parent_id
while parent:
@@ -1330,16 +1331,17 @@ class account_move(osv.osv):
def button_validate(self, cursor, user, ids, context=None):
for move in self.browse(cursor, user, ids, context=context):
- top = None
+ # check that all accounts have the same topmost ancestor
+ top_common = None
for line in move.line_id:
account = line.account_id
- while account:
- account2 = account
- account = account.parent_id
- if not top:
- top = account2.id
- elif top<>account2.id:
- raise osv.except_osv(_('Error !'), _('You can not validate a journal entry unless all journal items belongs to the same chart of accounts !'))
+ top_account = account
+ while top_account.parent_id:
+ top_account = top_account.parent_id
+ if not top_common:
+ top_common = top_account
+ elif top_account.id != top_common.id:
+ raise osv.except_osv(_('Error !'), _('You cannot validate a journal entry because account "%s" does not belong to chart of accounts "%s"!' % (account.name, top_common.name)))
return self.post(cursor, user, ids, context=context)
def button_cancel(self, cr, uid, ids, context=None):
@@ -2524,7 +2526,11 @@ class account_account_template(osv.osv):
#deactivate the parent_store functionnality on account_account for rapidity purpose
ctx = context.copy()
ctx.update({'defer_parent_store_computation': True})
- children_acc_template = self.search(cr, uid, ['|', ('chart_template_id','=', chart_template_id),'&',('parent_id','child_of', [template.account_root_id.id]),('chart_template_id','=', False), ('nocreate','!=',True)], order='id')
+ level_ref = {}
+ children_acc_criteria = [('chart_template_id','=', chart_template_id)]
+ if template.account_root_id.id:
+ children_acc_criteria = ['|'] + children_acc_criteria + ['&',('parent_id','child_of', [template.account_root_id.id]),('chart_template_id','=', False)]
+ children_acc_template = self.search(cr, uid, [('nocreate','!=',True)] + children_acc_criteria, order='id')
for account_template in self.browse(cr, uid, children_acc_template, context=context):
# skip the root of COA if it's not the main one
if (template.account_root_id.id == account_template.id) and template.parent_id:
@@ -2537,6 +2543,14 @@ class account_account_template(osv.osv):
code_acc = account_template.code or ''
if code_main > 0 and code_main <= code_digits and account_template.type != 'view':
code_acc = str(code_acc) + (str('0'*(code_digits-code_main)))
+ parent_id = account_template.parent_id and ((account_template.parent_id.id in acc_template_ref) and acc_template_ref[account_template.parent_id.id]) or False
+ #the level as to be given as well at the creation time, because of the defer_parent_store_computation in
+ #context. Indeed because of this, the parent_left and parent_right are not computed and thus the child_of
+ #operator does not return the expected values, with result of having the level field not computed at all.
+ if parent_id:
+ level = parent_id in level_ref and level_ref[parent_id] + 1 or obj_acc._get_level(cr, uid, [parent_id], 'level', None, context=context)[parent_id] + 1
+ else:
+ level = 0
vals={
'name': (template.account_root_id.id == account_template.id) and company_name or account_template.name,
'currency_id': account_template.currency_id and account_template.currency_id.id or False,
@@ -2547,12 +2561,14 @@ class account_account_template(osv.osv):
'shortcut': account_template.shortcut,
'note': account_template.note,
'financial_report_ids': account_template.financial_report_ids and [(6,0,[x.id for x in account_template.financial_report_ids])] or False,
- 'parent_id': account_template.parent_id and ((account_template.parent_id.id in acc_template_ref) and acc_template_ref[account_template.parent_id.id]) or False,
+ 'parent_id': parent_id,
'tax_ids': [(6,0,tax_ids)],
'company_id': company_id,
+ 'level': level,
}
new_account = obj_acc.create(cr, uid, vals, context=ctx)
acc_template_ref[account_template.id] = new_account
+ level_ref[new_account] = level
#reactivate the parent_store functionnality on account_account
obj_acc._parent_store_compute(cr)
@@ -2982,7 +2998,7 @@ class wizard_multi_charts_accounts(osv.osv_memory):
tax_templ_obj = self.pool.get('account.tax.template')
if 'bank_accounts_id' in fields:
- res.update({'bank_accounts_id': [{'acc_name': _('Cash'), 'account_type': 'cash'}]})
+ res.update({'bank_accounts_id': [{'acc_name': _('Cash'), 'account_type': 'cash'},{'acc_name': _('Bank'), 'account_type': 'bank'}]})
if 'company_id' in fields:
res.update({'company_id': self.pool.get('res.users').browse(cr, uid, [uid], context=context)[0].company_id.id})
if 'seq_journal' in fields:
diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py
index bd31b01a41d..9cfda051ec1 100644
--- a/addons/account/account_bank_statement.py
+++ b/addons/account/account_bank_statement.py
@@ -52,8 +52,9 @@ class account_bank_statement(osv.osv):
journal_pool = self.pool.get('account.journal')
journal_type = context.get('journal_type', False)
journal_id = False
+ company_id = self.pool.get('res.company')._company_default_get(cr, uid, 'account.bank.statement',context=context)
if journal_type:
- ids = journal_pool.search(cr, uid, [('type', '=', journal_type)])
+ ids = journal_pool.search(cr, uid, [('type', '=', journal_type),('company_id','=',company_id)])
if ids:
journal_id = ids[0]
return journal_id
@@ -169,30 +170,31 @@ class account_bank_statement(osv.osv):
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.bank.statement',context=c),
}
- def onchange_date(self, cr, user, ids, date, context=None):
+ def _check_company_id(self, cr, uid, ids, context=None):
+ for statement in self.browse(cr, uid, ids, context=context):
+ if statement.company_id.id != statement.period_id.company_id.id:
+ return False
+ return True
+
+ _constraints = [
+ (_check_company_id, 'The journal and period chosen have to belong to the same company.', ['journal_id','period_id']),
+ ]
+
+ def onchange_date(self, cr, uid, ids, date, company_id, context=None):
"""
- Returns a dict that contains new values and context
- @param cr: A database cursor
- @param user: ID of the user currently logged in
- @param date: latest value from user input for field date
- @param args: other arguments
- @param context: context arguments, like lang, time zone
- @return: Returns a dict which contains new values, and context
+ Find the correct period to use for the given date and company_id, return it and set it in the context
"""
res = {}
period_pool = self.pool.get('account.period')
if context is None:
context = {}
-
- pids = period_pool.search(cr, user, [('date_start','<=',date), ('date_stop','>=',date)])
+ ctx = context.copy()
+ ctx.update({'company_id': company_id})
+ pids = period_pool.find(cr, uid, dt=date, context=ctx)
if pids:
- res.update({
- 'period_id':pids[0]
- })
- context.update({
- 'period_id':pids[0]
- })
+ res.update({'period_id': pids[0]})
+ context.update({'period_id': pids[0]})
return {
'value':res,
@@ -385,8 +387,10 @@ class account_bank_statement(osv.osv):
ORDER BY date DESC,id DESC LIMIT 1', (journal_id, 'draft'))
res = cr.fetchone()
balance_start = res and res[0] or 0.0
- account_id = self.pool.get('account.journal').read(cr, uid, journal_id, ['default_debit_account_id'], context=context)['default_debit_account_id']
- return {'value': {'balance_start': balance_start, 'account_id': account_id}}
+ journal_data = self.pool.get('account.journal').read(cr, uid, journal_id, ['default_debit_account_id', 'company_id'], context=context)
+ account_id = journal_data['default_debit_account_id']
+ company_id = journal_data['company_id']
+ return {'value': {'balance_start': balance_start, 'account_id': account_id, 'company_id': company_id}}
def unlink(self, cr, uid, ids, context=None):
stat = self.read(cr, uid, ids, ['state'], context=context)
diff --git a/addons/account/account_financial_report.py b/addons/account/account_financial_report.py
index 4ee8ac3d74b..0688d6f12b1 100644
--- a/addons/account/account_financial_report.py
+++ b/addons/account/account_financial_report.py
@@ -104,20 +104,30 @@ class account_financial_report(osv.osv):
('account_report','Report Value'),
],'Type'),
'account_ids': fields.many2many('account.account', 'account_account_financial_report', 'report_line_id', 'account_id', 'Accounts'),
+ 'account_report_id': fields.many2one('account.financial.report', 'Report Value'),
+ 'account_type_ids': fields.many2many('account.account.type', 'account_account_financial_report_type', 'report_id', 'account_type_id', 'Account Types'),
+ 'sign': fields.selection([(-1, 'Reverse balance sign'), (1, 'Preserve balance sign')], 'Sign on Reports', required=True, help='For accounts that are typically more debited than credited and that you would like to print as negative amounts in your reports, you should reverse the sign of the balance; e.g.: Expense account. The same applies for accounts that are typically more credited than debited and that you would like to print as positive amounts in your reports; e.g.: Income account.'),
'display_detail': fields.selection([
('no_detail','No detail'),
('detail_flat','Display children flat'),
('detail_with_hierarchy','Display children with hierarchy')
], 'Display details'),
- 'account_report_id': fields.many2one('account.financial.report', 'Report Value'),
- 'account_type_ids': fields.many2many('account.account.type', 'account_account_financial_report_type', 'report_id', 'account_type_id', 'Account Types'),
- 'sign': fields.selection([(-1, 'Reverse balance sign'), (1, 'Preserve balance sign')], 'Sign on Reports', required=True, help='For accounts that are typically more debited than credited and that you would like to print as negative amounts in your reports, you should reverse the sign of the balance; e.g.: Expense account. The same applies for accounts that are typically more credited than debited and that you would like to print as positive amounts in your reports; e.g.: Income account.'),
+ 'style_overwrite': fields.selection([
+ (0, 'Automatic formatting'),
+ (1,'Main Title 1 (bold, underlined)'),
+ (2,'Title 2 (bold)'),
+ (3,'Title 3 (bold, smaller)'),
+ (4,'Normal Text'),
+ (5,'Italic Text (smaller)'),
+ (6,'Smallest Text'),
+ ],'Financial Report Style', help="You can set up here the format you want this record to be displayed. If you leave the automatic formatting, it will be computed based on the financial reports hierarchy (auto-computed field 'level')."),
}
_defaults = {
'type': 'sum',
'display_detail': 'detail_flat',
'sign': 1,
+ 'style_overwrite': 0,
}
account_financial_report()
diff --git a/addons/account/account_financial_report_data.xml b/addons/account/account_financial_report_data.xml
index 18624f94749..6410a5e887c 100644
--- a/addons/account/account_financial_report_data.xml
+++ b/addons/account/account_financial_report_data.xml
@@ -4,23 +4,6 @@
-