[FIX] typo on statement name
[odoo/odoo.git] / addons / account / account.py
index d32fb58..280d413 100644 (file)
@@ -150,7 +150,6 @@ class account_account_type(osv.osv):
         return res
 
     def _save_report_type(self, cr, uid, account_type_id, field_name, field_value, arg, context=None):
-        import pdb;pdb.set_trace()
         obj_data = self.pool.get('ir.model.data')
         obj_financial_report = self.pool.get('account.financial.report') 
         #unlink if it exists somewhere in the financial reports related to BS or PL
@@ -191,16 +190,6 @@ class account_account_type(osv.osv):
     }
     _order = "code"
 
-    def write(self, cr, uid, ids, vals, context=None):
-        report_obj = self.pool.get('account.financial.report')
-        if vals.get('report_type'):
-            type_ids = self.search(cr, uid, [('code','=',vals['report_type'])], context=context)
-            report_ids = report_obj.search(cr, uid, [('account_type_ids','in',ids)])
-            for report in report_obj.browse(cr, uid, report_ids, context=context):
-                type_ids += [x.id for x in report.account_type_ids if x.id not in type_ids]
-                report_obj.write(cr, uid, [report.id], {'account_type_ids': [(6,0,type_ids)]}, context=context)
-        return super(account_account_type, self).write(cr, uid, ids, vals, context)
-
 account_account_type()
 
 def _code_get(self, cr, uid, context=None):
@@ -467,6 +456,7 @@ class account_account(osv.osv):
         'user_type': fields.many2one('account.account.type', 'Account Type', required=True,
             help="Account Type is used for information purpose, to generate "
               "country-specific legal reports, and set the rules to close a fiscal year and generate opening entries."),
+        'financial_report_ids': fields.many2many('account.financial.report', 'account_account_financial_report', 'account_id', 'report_line_id', 'Financial Reports'),
         'parent_id': fields.many2one('account.account', 'Parent', ondelete='cascade', domain=[('type','=','view')]),
         'child_parent_ids': fields.one2many('account.account','parent_id','Children'),
         'child_consol_ids': fields.many2many('account.account', 'account_account_consol_rel', 'child_id', 'parent_id', 'Consolidated Children'),
@@ -816,7 +806,9 @@ class account_journal(osv.osv):
 
     def create(self, cr, uid, vals, context=None):
         if not 'sequence_id' in vals or not vals['sequence_id']:
-            vals.update({'sequence_id': self.create_sequence(cr, uid, vals, context)})
+            # if we have the right to create a journal, we should be able to
+            # create it's sequence.
+            vals.update({'sequence_id': self.create_sequence(cr, 1, vals, context)})
         return super(account_journal, self).create(cr, uid, vals, context)
 
     def name_get(self, cr, user, ids, context=None):
@@ -2467,6 +2459,7 @@ class account_account_template(osv.osv):
         'user_type': fields.many2one('account.account.type', 'Account Type', required=True,
             help="These types are defined according to your country. The type contains more information "\
             "about the account and its specificities."),
+        'financial_report_ids': fields.many2many('account.financial.report', 'account_template_financial_report', 'account_template_id', 'report_line_id', 'Financial Reports'),
         'reconcile': fields.boolean('Allow Reconciliation', help="Check this option if you want the user to reconcile entries in this account."),
         'shortcut': fields.char('Shortcut', size=12),
         'note': fields.text('Note'),
@@ -2553,6 +2546,7 @@ class account_account_template(osv.osv):
                 'reconcile': account_template.reconcile,
                 '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,
                 'tax_ids': [(6,0,tax_ids)],
                 'company_id': company_id,
@@ -2955,6 +2949,7 @@ class account_financial_report(osv.osv):
         return res
 
     def _get_balance(self, cr, uid, ids, name, args, context=None):
+        account_obj = self.pool.get('account.account')
         res = {}
         res_all = {}
         for report in self.browse(cr, uid, ids, context=context):
@@ -2965,6 +2960,12 @@ class account_financial_report(osv.osv):
                 # it's the sum of balance of the linked accounts
                 for a in report.account_ids:
                     balance += a.balance
+            elif report.type == 'account_type':
+                # it's the sum of balance of the leaf accounts with such an account type
+                report_types = [x.id for x in report.account_type_ids]
+                account_ids = account_obj.search(cr, uid, [('user_type','in', report_types), ('type','!=','view')], context=context)
+                for a in account_obj.browse(cr, uid, account_ids, context=context):
+                    balance += a.balance
             elif report.type == 'account_report' and report.account_report_id:
                 # it's the amount of the linked report
                 res2 = self._get_balance(cr, uid, [report.account_report_id.id], 'balance', False, context=context)
@@ -2998,7 +2999,7 @@ class account_financial_report(osv.osv):
         'account_ids': fields.many2many('account.account', 'account_account_financial_report', 'report_line_id', 'account_id', 'Accounts'),
         'display_detail': fields.selection([
             ('no_detail','No detail'),
-            ('only_detail','Display children flat'),
+            ('detail_flat','Display children flat'),
             ('detail_with_hierarchy','Display children with hierarchy')
             ], 'Display details'),
         'account_report_id':  fields.many2one('account.financial.report', 'Report Value'),
@@ -3008,7 +3009,7 @@ class account_financial_report(osv.osv):
 
     _defaults = {
         'type': 'sum',
-        'display_detail': 'only_detail',
+        'display_detail': 'detail_flat',
         'sign': 1,
     }