[IMP]: account module improvements for the bank and cash statements

bzr revid: mga@tinyerp.com-20100726144132-43czgtm069okzshd
This commit is contained in:
Mantavya Gajjar
2010-07-26 20:11:32 +05:30
parent a7a62e439b
commit 3aa3051b4d
5 changed files with 80 additions and 45 deletions
+1 -1
View File
@@ -1030,7 +1030,6 @@ class account_move(osv.osv):
res.append((move.id, name))
return res
def _get_period(self, cr, uid, context):
periods = self.pool.get('account.period').find(cr, uid)
if periods:
@@ -1117,6 +1116,7 @@ class account_move(osv.osv):
'You cannot create entries on different periods/journals in the same move',
['line_id']),
]
def post(self, cr, uid, ids, context=None):
if self.validate(cr, uid, ids, context) and len(ids):
for move in self.browse(cr, uid, ids):
+26
View File
@@ -160,6 +160,32 @@ class account_bank_statement(osv.osv):
'period_id': _get_period,
}
def onchange_date(self, cr, user, ids, date, context={}):
"""
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
"""
res = {}
period_pool = self.pool.get('account.period')
pids = period_pool.search(cr, user, [('date_start','<=',date), ('date_stop','>=',date)])
if pids:
res.update({
'period_id':pids[0]
})
context.update({
'period_id':pids[0]
})
return {
'value':res,
'context':context,
}
def button_confirm_bank(self, cr, uid, ids, context={}):
done = []
res_currency_obj = self.pool.get('res.currency')
+41 -32
View File
@@ -174,6 +174,17 @@ class account_cash_statement(osv.osv):
return company_id
def _get_cash_box_lines(self, cr, uid, ids, context={}):
res = []
curr = [1, 2, 5, 10, 20, 50, 100, 500]
for rs in curr:
dct = {
'pieces':rs,
'number':0
}
res.append(dct)
return res
_columns = {
'company_id':fields.many2one('res.company', 'Company', required=False),
'journal_id': fields.many2one('account.journal', 'Journal', required=True),
@@ -197,24 +208,23 @@ class account_cash_statement(osv.osv):
'date': lambda *a:time.strftime("%Y-%m-%d %H:%M:%S"),
'journal_id': _default_journal_id,
'user_id': lambda self, cr, uid, context=None: uid,
'company_id': _get_company
'company_id': _get_company,
'starting_details_ids':_get_cash_box_lines,
'ending_details_ids':_get_cash_box_lines
}
def create(self, cr, uid, vals, context=None):
company_id = vals and vals.get('company_id',False)
if company_id:
open_jrnl = self.search(cr, uid, [('company_id', '=', vals['company_id']), ('journal_id', '=', vals['journal_id']), ('state', '=', 'open')])
sql = [
('company_id', '=', vals['company_id']),
('journal_id', '=', vals['journal_id']),
('state', '=', 'open')
]
open_jrnl = self.search(cr, uid, sql)
if open_jrnl:
raise osv.except_osv('Error', u'Une caisse de type espèce est déjà ouverte')
if 'starting_details_ids' in vals:
vals['starting_details_ids'] = starting_details_ids = map(list, vals['starting_details_ids'])
for i in starting_details_ids:
if i and i[0] and i[1]:
i[0], i[1] = 0, 0
raise osv.except_osv('Error', _('You can not have two open register for the same journal'))
res_id = super(account_cash_statement, self).create(cr, uid, vals, context=context)
res = self._get_starting_balance(cr, uid, [res_id])
for rs in res:
super(account_cash_statement, self).write(cr, uid, rs, res.get(rs))
return res_id
def write(self, cr, uid, ids, vals, context=None):
@@ -284,27 +294,26 @@ class account_cash_statement(osv.osv):
number = self.pool.get('ir.sequence').get(cr, uid, statement.journal_id.sequence_id.code)
if len(statement.starting_details_ids) > 0:
sid = []
for line in statement.starting_details_ids:
sid.append(line.id)
cash_pool.unlink(cr, uid, sid)
cr.execute("select id from account_bank_statement where journal_id=%s and user_id=%s and state=%s order by id desc limit 1", (statement.journal_id.id, uid, 'confirm'))
rs = cr.fetchone()
rs = rs and rs[0] or None
if rs:
statement = statement_pool.browse(cr, uid, rs)
balance_start = statement.balance_end_real or 0.0
open_ids = cash_pool.search(cr, uid, [('ending_id','=',statement.id)])
for sid in open_ids:
default = {
'ending_id': False,
'starting_id':ids[0]
}
cash_pool.copy(cr, uid, sid, default)
# if len(statement.starting_details_ids) > 0:
# sid = []
# for line in statement.starting_details_ids:
# sid.append(line.id)
# cash_pool.unlink(cr, uid, sid)
#
# cr.execute("select id from account_bank_statement where journal_id=%s and user_id=%s and state=%s order by id desc limit 1", (statement.journal_id.id, uid, 'confirm'))
# rs = cr.fetchone()
# rs = rs and rs[0] or None
# if rs:
# statement = statement_pool.browse(cr, uid, rs)
# balance_start = statement.balance_end_real or 0.0
# open_ids = cash_pool.search(cr, uid, [('ending_id','=',statement.id)])
# for sid in open_ids:
# default = {
# 'ending_id': False,
# 'starting_id':ids[0]
# }
# cash_pool.copy(cr, uid, sid, default)
#
vals = {
'date':time.strftime("%Y-%m-%d %H:%M:%S"),
'state':'open',
+1 -1
View File
@@ -819,7 +819,7 @@ class account_move_line(osv.osv):
fld = []
fields = {}
flds = []
title = self.view_header_get(cr, uid, view_id, view_type, context)
title = "Accounting Entries" #self.view_header_get(cr, uid, view_id, view_type, context)
xml = '''<?xml version="1.0"?>\n<tree string="%s" editable="top" refresh="5" on_write="on_create_write">\n\t''' % (title)
journal_pool = self.pool.get('account.journal')
+11 -11
View File
@@ -477,9 +477,9 @@
<filter string="Draft" domain="[('state','=','draft')]" icon="terp-document-new"/>
<filter string="Confirm" domain="[('state','=','confirm')]" icon="terp-camera_test"/>
<separator orientation="vertical"/>
<field name="journal_id" widget="selection"/>
<field name="date"/>
<field name="name"/>
<field name="journal_id"/>
</group>
<newline/>
<group expand="0" string="Group By...">
@@ -498,7 +498,7 @@
<form string="Bank Statement">
<group col="6" colspan="4">
<field name="name" select="1"/>
<field name="date" select="1"/>
<field name="date" select="1" on_change="onchange_date(date)"/>
<field name="journal_id" domain="[('type', '=', 'bank')]" on_change="onchange_journal_id(journal_id)" select="1"/>
<field name="period_id"/>
<field name="balance_start"/>
@@ -578,12 +578,12 @@
<field name="filter" eval="True"/>
</record>
<record id="action_bank_statement_tree2" model="ir.actions.act_window">
<field name="name">New Statement</field>
<field name="res_model">account.bank.statement</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
</record>
<!-- <record id="action_bank_statement_tree2" model="ir.actions.act_window">-->
<!-- <field name="name">New Statement</field>-->
<!-- <field name="res_model">account.bank.statement</field>-->
<!-- <field name="view_type">form</field>-->
<!-- <field name="view_mode">form,tree</field>-->
<!-- </record>-->
<record id="view_bank_statement_reconcile" model="ir.ui.view">
<field name="name">account.bank.statement.reconcile.form</field>
@@ -2420,7 +2420,7 @@
</page>
<page string="CashBox">
<group col="2" colspan="2" expand="1">
<field name="starting_details_ids" nolabel="1" colspan="2" attrs="{'readonly':[('state','=','draft')]}">
<field name="starting_details_ids" nolabel="1" colspan="2" attrs="{'readonly':[('state','!=','draft')]}">
<tree string = "Opening Balance" editable="bottom">
<field name="pieces"/>
<field name="number" on_change="on_change_sub(pieces,number, parent.balance_end)"/>
@@ -2434,7 +2434,7 @@
</field>
</group>
<group col="2" colspan="2" expand="1">
<field name="ending_details_ids" nolabel="1" colspan="2" attrs="{'readonly':[('state','=','draft')]}">
<field name="ending_details_ids" nolabel="1" colspan="2" attrs="{'readonly':[('state','!=','open')]}">
<tree string = "Closing Balance" editable="bottom">
<field name="pieces"/>
<field name="number" on_change="on_change_sub(pieces,number, parent.balance_end)"/>
@@ -2455,7 +2455,7 @@
<group col="6" colspan="4">
<group col="2" colspan="2">
<separator string="Dates" colspan="4"/>
<field name="date" select="1" attrs="{'readonly':[('state','!=','draft')]}"/>
<field name="date" select="1" attrs="{'readonly':[('state','!=','draft')]}" on_change="onchange_date(date)"/>
<field name="closing_date" select="1" attrs="{'readonly':[('state','=','confirm')]}"/>
</group>
<group col="2" colspan="2">