diff --git a/addons/account/account.py b/addons/account/account.py
index 969f843bec9..5181028c17b 100644
--- a/addons/account/account.py
+++ b/addons/account/account.py
@@ -122,6 +122,16 @@ class account_account_type(osv.osv):
'partner_account': fields.boolean('Partner account'),
'close_method': fields.selection([('none', 'None'), ('balance', 'Balance'), ('detail', 'Detail'), ('unreconciled', 'Unreconciled')], 'Deferral Method', required=True),
'sign': fields.selection([(-1, 'Negative'), (1, 'Positive')], 'Sign on Reports', required=True, help='Allows you to change the sign of the balance amount displayed in the reports, so that you can see positive figures instead of negative ones in expenses accounts.'),
+ 'report_type':fields.selection([
+ ('none','/'),
+ ('income','Profilt & Loss (Income Accounts)'),
+ ('expanse','Profilt & Loss (Expanse Accounts)'),
+ ('asset','Balance Sheet (Assets Accounts)'),
+ ('liabilities','Balance Sheet (Liabilities Accounts)')
+ ],'Type Heads', select=True, readonly=False, help="According value related accounts will be display on respective reports (Balance Sheet Profit & Loss Account)"),
+ 'parent_id':fields.many2one('account.account.type', 'Parent Type', required=False),
+ 'child_ids':fields.one2many('account.account.type', 'parent_id', 'Child Types', required=False),
+ 'note': fields.text('Description'),
}
_defaults = {
'close_method': lambda *a: 'none',
@@ -129,6 +139,15 @@ class account_account_type(osv.osv):
'sign': lambda *a: 1,
}
_order = "sequence"
+
+ def _check_recursion(self, cr, uid, ids):
+ #TODO: Need to check for recusrion
+ return True
+
+ _constraints = [
+ (_check_recursion, 'Error ! You can not create recursive types.', ['parent_id'])
+ ]
+
account_account_type()
def _code_get(self, cr, uid, context={}):
@@ -212,9 +231,9 @@ class account_account(osv.osv):
aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
wheres = [""]
- if query:
+ if query.strip():
wheres.append(query.strip())
- if aml_query:
+ if aml_query.strip():
wheres.append(aml_query.strip())
query = " AND ".join(wheres)
@@ -232,6 +251,7 @@ class account_account(osv.osv):
# consolidate accounts with direct children
+ ids2.reverse()
brs = list(self.browse(cr, uid, ids2, context=context))
sums = {}
while brs:
@@ -251,8 +271,9 @@ class account_account(osv.osv):
if current.child_id:
sums[current.id][fn] += sum(sums[child.id][fn] for child in current.child_id)
res = {}
+ null_result = dict((fn, 0.0) for fn in field_names)
for id in ids:
- res[id] = sums[id]
+ res[id] = sums.get(id, null_result)
return res
def _get_company_currency(self, cr, uid, ids, field_name, arg, context={}):
@@ -294,7 +315,7 @@ class account_account(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."),
- 'parent_id': fields.many2one('account.account', 'Parent', ondelete='cascade'),
+ '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'),
'child_id': fields.function(_get_child_ids, method=True, type='many2many', relation="account.account", string="Child Accounts"),
@@ -431,18 +452,42 @@ class account_account(osv.osv):
def _check_moves(self, cr, uid, ids, method, context):
line_obj = self.pool.get('account.move.line')
account_ids = self.search(cr, uid, [('id', 'child_of', ids)])
+
if line_obj.search(cr, uid, [('account_id', 'in', account_ids)]):
if method == 'write':
raise osv.except_osv(_('Error !'), _('You cannot deactivate an account that contains account moves.'))
elif method == 'unlink':
raise osv.except_osv(_('Error !'), _('You cannot remove an account which has account entries!. '))
+ #Checking whether the account is set as a property to any Partner or not
+ value = 'account.account,' + str(ids[0])
+ partner_prop_acc = self.pool.get('ir.property').search(cr, uid, [('value_reference','=',value)], context=context)
+ if partner_prop_acc:
+ raise osv.except_osv(_('Warning !'), _('You cannot remove/deactivate an account which is set as a property to any Partner.'))
+ return True
+
+ def _check_allow_type_change(self, cr, uid, ids, new_type, context):
+ group1 = ['payable', 'receivable', 'other']
+ group2 = ['consolidation','view']
+ line_obj = self.pool.get('account.move.line')
+ for account in self.browse(cr, uid, ids, context=context):
+ old_type = account.type
+ account_ids = self.search(cr, uid, [('id', 'child_of', [account.id])])
+ if line_obj.search(cr, uid, [('account_id', 'in', account_ids)]):
+ #Check for 'Closed' type
+ if old_type == 'closed' and new_type !='closed':
+ raise osv.except_osv(_('Warning !'), _("You cannot change the type of account from 'Closed' to any other type which contains account entries!"))
+ #Check for change From group1 to group2 and vice versa
+ if (old_type in group1 and new_type in group2) or (old_type in group2 and new_type in group1):
+ raise osv.except_osv(_('Warning !'), _("You cannot change the type of account from '%s' to '%s' type as it contains account entries!") % (old_type,new_type,))
return True
def write(self, cr, uid, ids, vals, context=None):
- if not context:
+ if context is None:
context = {}
if 'active' in vals and not vals['active']:
self._check_moves(cr, uid, ids, "write", context)
+ if 'type' in vals.keys():
+ self._check_allow_type_change(cr, uid, ids, vals['type'], context=context)
return super(account_account, self).write(cr, uid, ids, vals, context=context)
def unlink(self, cr, uid, ids, context={}):
@@ -515,6 +560,7 @@ class account_journal(osv.osv):
'company_id': fields.many2one('res.company', 'Company', required=True,select=1),
'invoice_sequence_id': fields.many2one('ir.sequence', 'Invoice Sequence', \
help="The sequence used for invoice numbers in this journal."),
+ 'allow_date':fields.boolean('Check Date not in the Period', help= 'If set to True then do not accept the entry if the entry date is not into the period dates'),
}
_defaults = {
@@ -537,15 +583,16 @@ class account_journal(osv.osv):
def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=100):
if not args:
- args=[]
- if not context:
- context={}
+ args = []
+ if context is None:
+ context = {}
ids = []
if name:
- ids = self.search(cr, user, [('code','ilike',name)]+ args, limit=limit)
+ ids = self.search(cr, user, [('code','ilike',name)]+ args, limit=limit, context=context)
if not ids:
- ids = self.search(cr, user, [('name',operator,name)]+ args, limit=limit)
+ ids = self.search(cr, user, [('name',operator,name)]+ args, limit=limit, context=context)
return self.name_get(cr, user, ids, context=context)
+
account_journal()
class account_fiscalyear(osv.osv):
@@ -611,6 +658,19 @@ class account_fiscalyear(osv.osv):
else:
return False
return ids[0]
+
+ def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=80):
+ if args is None:
+ args = []
+ if context is None:
+ context = {}
+ ids = []
+ if name:
+ ids = self.search(cr, user, [('code','ilike',name)]+ args, limit=limit)
+ if not ids:
+ ids = self.search(cr, user, [('name',operator,name)]+ args, limit=limit)
+ return self.name_get(cr, user, ids, context=context)
+
account_fiscalyear()
class account_period(osv.osv):
@@ -686,12 +746,24 @@ class account_period(osv.osv):
cr.execute('update account_journal_period set state=%s where period_id=%s', (mode, id))
cr.execute('update account_period set state=%s where id=%s', (mode, id))
return True
+
+ def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=80):
+ if args is None:
+ args = []
+ if context is None:
+ context = {}
+ ids = []
+ if name:
+ ids = self.search(cr, user, [('code','ilike',name)]+ args, limit=limit)
+ if not ids:
+ ids = self.search(cr, user, [('name',operator,name)]+ args, limit=limit)
+ return self.name_get(cr, user, ids, context=context)
account_period()
class account_journal_period(osv.osv):
_name = "account.journal.period"
- _description = "Journal - Period"
+ _description = "Journal Period"
def _icon_get(self, cr, uid, ids, field_name, arg=None, context={}):
result = {}.fromkeys(ids, 'STOCK_NEW')
@@ -930,7 +1002,6 @@ class account_move(osv.osv):
l[2]['period_id'] = default_period
context['period_id'] = default_period
- accnt_journal = self.pool.get('account.journal').browse(cr, uid, vals['journal_id'])
if 'line_id' in vals:
c = context.copy()
c['novalidate'] = True
@@ -1228,7 +1299,7 @@ class account_tax_code(osv.osv):
_description = 'Tax Code'
_rec_name = 'code'
_columns = {
- 'name': fields.char('Tax Case Name', size=64, required=True),
+ 'name': fields.char('Tax Case Name', size=64, required=True, translate=True),
'code': fields.char('Case Code', size=64),
'info': fields.text('Description'),
'sum': fields.function(_sum_year, method=True, string="Year Sum"),
@@ -1242,6 +1313,15 @@ class account_tax_code(osv.osv):
}
+ def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=80):
+ if not args:
+ args = []
+ if context is None:
+ context = {}
+ ids = self.search(cr, user, ['|',('name',operator,name),('code',operator,name)] + args, limit=limit, context=context)
+ return self.name_get(cr, user, ids, context)
+
+
def name_get(self, cr, uid, ids, context=None):
if not len(ids):
return []
@@ -1270,7 +1350,15 @@ class account_tax_code(osv.osv):
return False
level -= 1
return True
+
+ def copy(self, cr, uid, id, default=None, context=None):
+ if default is None:
+ default = {}
+ default = default.copy()
+ default.update({'line_ids': []})
+ return super(account_tax_code, self).copy(cr, uid, id, default, context)
+
_constraints = [
(_check_recursion, 'Error ! You can not create recursive accounts.', ['parent_id'])
]
diff --git a/addons/account/account_analytic_line.py b/addons/account/account_analytic_line.py
index ce6341cc9b2..1fa0a5c6cfa 100644
--- a/addons/account/account_analytic_line.py
+++ b/addons/account/account_analytic_line.py
@@ -30,7 +30,7 @@ from tools import config
class account_analytic_line(osv.osv):
_inherit = 'account.analytic.line'
- _description = 'Analytic lines'
+ _description = 'Analytic Line'
_columns = {
'product_uom_id' : fields.many2one('product.uom', 'UoM'),
'product_id' : fields.many2one('product.product', 'Product'),
@@ -42,7 +42,7 @@ class account_analytic_line(osv.osv):
}
_defaults = {
'date': lambda *a: time.strftime('%Y-%m-%d'),
- 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.analytic.line', c),
+ 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.analytic.line', context=c),
}
_order = 'date'
@@ -118,7 +118,7 @@ account_analytic_line()
class timesheet_invoice(osv.osv):
_name = "report.hr.timesheet.invoice.journal"
- _description = "Analytic account costs and revenues"
+ _description = "Analytic Account Costs and Revenues"
_auto = False
_columns = {
'name': fields.char('Year',size=64,required=False, readonly=True),
diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py
index deb010c7cd0..9b1497b563f 100644
--- a/addons/account/account_bank_statement.py
+++ b/addons/account/account_bank_statement.py
@@ -387,7 +387,7 @@ account_bank_statement()
class account_bank_statement_reconcile(osv.osv):
_name = "account.bank.statement.reconcile"
- _description = "Statement reconcile"
+ _description = "Statement Reconcile"
def _total_entry(self, cursor, user, ids, name, attr, context=None):
result = {}
@@ -558,35 +558,40 @@ class account_bank_statement_line(osv.osv):
def onchange_partner_id(self, cursor, user, line_id, partner_id, type, currency_id,
context={}):
+ res = {'value': {}}
if not partner_id:
- return {}
- res_currency_obj = self.pool.get('res.currency')
- res_users_obj = self.pool.get('res.users')
-
- company_currency_id = res_users_obj.browse(cursor, user, user,
- context=context).company_id.currency_id.id
-
- if not currency_id:
- currency_id = company_currency_id
-
- part = self.pool.get('res.partner').browse(cursor, user, partner_id,
+ return res
+ line = self.browse(cursor, user, line_id)
+
+ if not line or (line and not line[0].account_id):
+ part = self.pool.get('res.partner').browse(cursor, user, partner_id,
context=context)
- if type == 'supplier':
- account_id = part.property_account_payable.id
- else:
- account_id = part.property_account_receivable.id
+ if type == 'supplier':
+ account_id = part.property_account_payable.id
+ else:
+ account_id = part.property_account_receivable.id
+ res['value']['account_id'] = account_id
- cursor.execute('SELECT sum(debit-credit) \
+ if not line or (line and not line[0].amount):
+ res_users_obj = self.pool.get('res.users')
+ res_currency_obj = self.pool.get('res.currency')
+ company_currency_id = res_users_obj.browse(cursor, user, user,
+ context=context).company_id.currency_id.id
+ if not currency_id:
+ currency_id = company_currency_id
+
+ cursor.execute('SELECT sum(debit-credit) \
FROM account_move_line \
WHERE (reconcile_id is null) \
AND partner_id = %s \
AND account_id=%s', (partner_id, account_id))
- res = cursor.fetchone()
- balance = res and res[0] or 0.0
+ pgres = cursor.fetchone()
+ balance = pgres and pgres[0] or 0.0
- balance = res_currency_obj.compute(cursor, user, company_currency_id,
+ balance = res_currency_obj.compute(cursor, user, company_currency_id,
currency_id, balance, context=context)
- return {'value': {'amount': balance, 'account_id': account_id}}
+ res['value']['amount'] = balance
+ return res
def _reconcile_amount(self, cursor, user, ids, name, args, context=None):
if not ids:
@@ -633,7 +638,7 @@ class account_bank_statement_line(osv.osv):
'note': fields.text('Notes'),
'reconcile_amount': fields.function(_reconcile_amount,
string='Amount reconciled', method=True, type='float'),
- 'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of bank statement line."),
+ 'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of bank statement lines."),
}
_defaults = {
'name': lambda self,cr,uid,context={}: self.pool.get('ir.sequence').get(cr, uid, 'account.bank.statement.line'),
diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml
index 16e3cc656cd..2da7c71021c 100644
--- a/addons/account/account_invoice_view.xml
+++ b/addons/account/account_invoice_view.xml
@@ -479,22 +479,23 @@