[IMP]: improvement in accounting

bzr revid: mga@tinyerp.com-20100723140726-9dcas1qebivvy4vo
This commit is contained in:
Mantavya Gajjar 2010-07-23 19:37:26 +05:30
parent bb78b5c34a
commit c5c499418d
4 changed files with 110 additions and 69 deletions

View File

@ -248,59 +248,59 @@ class account_account(osv.osv):
def __compute(self, cr, uid, ids, field_names, arg=None, context=None, def __compute(self, cr, uid, ids, field_names, arg=None, context=None,
query='', query_params=()): query='', query_params=()):
""" compute the balance, debit and/or credit for the provided """ compute the balance, debit and/or credit for the provided
account ids account ids
Arguments: Arguments:
`ids`: account ids `ids`: account ids
`field_names`: the fields to compute (a list of any of `field_names`: the fields to compute (a list of any of
'balance', 'debit' and 'credit') 'balance', 'debit' and 'credit')
`arg`: unused fields.function stuff `arg`: unused fields.function stuff
`query`: additional query filter (as a string) `query`: additional query filter (as a string)
`query_params`: parameters for the provided query string `query_params`: parameters for the provided query string
(__compute will handle their escaping) as a (__compute will handle their escaping) as a
tuple tuple
""" """
mapping = { mapping = {
'balance': "COALESCE(SUM(l.debit),0) " \ 'balance': "COALESCE(SUM(l.debit),0) " \
"- COALESCE(SUM(l.credit), 0) as balance", "- COALESCE(SUM(l.credit), 0) as balance",
'debit': "COALESCE(SUM(l.debit), 0) as debit", 'debit': "COALESCE(SUM(l.debit), 0) as debit",
'credit': "COALESCE(SUM(l.credit), 0) as credit" 'credit': "COALESCE(SUM(l.credit), 0) as credit"
} }
#get all the necessary accounts #get all the necessary accounts
children_and_consolidated = self._get_children_and_consol(cr, uid, ids, context=context) children_and_consolidated = self._get_children_and_consol(cr, uid, ids, context=context)
#compute for each account the balance/debit/credit from the move lines #compute for each account the balance/debit/credit from the move lines
accounts = {} accounts = {}
if children_and_consolidated: if children_and_consolidated:
aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context) aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
wheres = [""] wheres = [""]
if query.strip(): if query.strip():
wheres.append(query.strip()) wheres.append(query.strip())
if aml_query.strip(): if aml_query.strip():
wheres.append(aml_query.strip()) wheres.append(aml_query.strip())
filters = " AND ".join(wheres) filters = " AND ".join(wheres)
self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG, self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
'Filters: %s'%filters) 'Filters: %s'%filters)
# IN might not work ideally in case there are too many # IN might not work ideally in case there are too many
# children_and_consolidated, in that case join on a # children_and_consolidated, in that case join on a
# values() e.g.: # values() e.g.:
# SELECT l.account_id as id FROM account_move_line l # SELECT l.account_id as id FROM account_move_line l
# INNER JOIN (VALUES (id1), (id2), (id3), ...) AS tmp (id) # INNER JOIN (VALUES (id1), (id2), (id3), ...) AS tmp (id)
# ON l.account_id = tmp.id # ON l.account_id = tmp.id
# or make _get_children_and_consol return a query and join on that # or make _get_children_and_consol return a query and join on that
request = ("SELECT l.account_id as id, " +\ request = ("SELECT l.account_id as id, " +\
' , '.join(map(mapping.__getitem__, field_names)) + ' , '.join(map(mapping.__getitem__, field_names)) +
" FROM account_move_line l" \ " FROM account_move_line l" \
" WHERE l.account_id IN %s " \ " WHERE l.account_id IN %s " \
+ filters + + filters +
" GROUP BY l.account_id") " GROUP BY l.account_id")
params = (tuple(children_and_consolidated),) + query_params params = (tuple(children_and_consolidated),) + query_params
cr.execute(request, params) cr.execute(request, params)
self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG, self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
'Status: %s'%cr.statusmessage) 'Status: %s'%cr.statusmessage)
for res in cr.dictfetchall(): for res in cr.dictfetchall():
accounts[res['id']] = res accounts[res['id']] = res
# consolidate accounts with direct children # consolidate accounts with direct children
children_and_consolidated.reverse() children_and_consolidated.reverse()
@ -2539,9 +2539,9 @@ class wizard_multi_charts_accounts(osv.osv_memory):
'account_paid_id': acc_template_ref[value['account_paid_id']], 'account_paid_id': acc_template_ref[value['account_paid_id']],
}) })
# Creating Journals # Creating Journals Sales and Purchase
vals_journal={} vals_journal={}
data_id = data_pool.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_journal_view')]) data_id = data_pool.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_sp_journal_view')])
data = data_pool.browse(cr, uid, data_id[0]) data = data_pool.browse(cr, uid, data_id[0])
view_id = data.res_id view_id = data.res_id
@ -2573,6 +2573,7 @@ class wizard_multi_charts_accounts(osv.osv_memory):
vals_journal['type'] = 'purchase' vals_journal['type'] = 'purchase'
vals_journal['code'] = _('EXJ') vals_journal['code'] = _('EXJ')
vals_journal['sequence_id'] = seq_id_purchase vals_journal['sequence_id'] = seq_id_purchase
vals_journal['view_id'] = view_id
if obj_multi.chart_template_id.property_account_payable: if obj_multi.chart_template_id.property_account_payable:
vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_expense_categ.id] vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_expense_categ.id]

View File

@ -183,7 +183,7 @@ class account_move_line(osv.osv):
# Compute the current move # Compute the current move
move_id = False move_id = False
partner_id = False partner_id = False
if context.get('journal_id',False) and context.get('period_id',False): if context.get('journal_id', False) and context.get('period_id', False):
if 'move_id' in fields: if 'move_id' in fields:
cr.execute('select move_id \ cr.execute('select move_id \
from \ from \
@ -199,6 +199,7 @@ class account_move_line(osv.osv):
return data return data
else: else:
data['move_id'] = move_id data['move_id'] = move_id
if 'date' in fields: if 'date' in fields:
cr.execute('select date \ cr.execute('select date \
from \ from \
@ -214,7 +215,6 @@ class account_move_line(osv.osv):
period = period_obj.browse(cr, uid, context['period_id'], period = period_obj.browse(cr, uid, context['period_id'],
context=context) context=context)
data['date'] = period.date_start data['date'] = period.date_start
if not move_id: if not move_id:
return data return data
@ -786,6 +786,31 @@ class account_move_line(osv.osv):
return j+(p and (':'+p) or '') return j+(p and (':'+p) or '')
return False return False
# 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 fields_view_get(self, cr, uid, view_id=None, view_type='form', context={}, toolbar=False, submenu=False): def fields_view_get(self, cr, uid, view_id=None, view_type='form', context={}, toolbar=False, submenu=False):
result = super(osv.osv, self).fields_view_get(cr, uid, view_id,view_type,context,toolbar=toolbar, submenu=submenu) result = super(osv.osv, self).fields_view_get(cr, uid, view_id,view_type,context,toolbar=toolbar, submenu=submenu)
if view_type != 'tree': if view_type != 'tree':
@ -848,11 +873,14 @@ class account_move_line(osv.osv):
elif field == 'credit': elif field == 'credit':
attrs.append('sum="Total credit"') attrs.append('sum="Total credit"')
elif field == 'account_tax_id': elif field == 'account_tax_id':
attrs.append('domain="[(\'parent_id\',\'=\',False)]"') attrs.append('domain="[(\'parent_id\',\'=\',False), (\'type_tax_use\',\'=\',context.get(journal_id.type, \'sale\'))]"')
elif field == 'account_id' and journal.id: elif field == 'account_id' and journal.id:
attrs.append('domain="[(\'journal_id\', \'=\', '+str(journal.id)+'),(\'type\',\'&lt;&gt;\',\'view\'), (\'type\',\'&lt;&gt;\',\'closed\')]" on_change="onchange_account_id(account_id, partner_id)"') attrs.append('domain="[(\'journal_id\', \'=\', '+str(journal.id)+'),(\'type\',\'&lt;&gt;\',\'view\'), (\'type\',\'&lt;&gt;\',\'closed\')]" on_change="onchange_account_id(account_id, partner_id)"')
elif field == 'partner_id': elif field == 'partner_id':
attrs.append('on_change="onchange_partner_id(move_id, partner_id, account_id, debit, credit, date, journal_id)"') attrs.append('on_change="onchange_partner_id(move_id, partner_id, account_id, debit, credit, date, journal_id)"')
# elif field == 'date':
# attrs.append('on_change="onchange_date(date)"')
# if field.readonly: # if field.readonly:
# attrs.append('readonly="1"') # attrs.append('readonly="1"')
# if field.required: # if field.required:

View File

@ -269,9 +269,9 @@
<field colspan="4" name="name" select="1"/> <field colspan="4" name="name" select="1"/>
<field name="field" select="1"/> <field name="field" select="1"/>
<field name="sequence"/> <field name="sequence"/>
<newline/> <!-- <newline/>-->
<field name="readonly"/> <!-- <field name="readonly"/>-->
<field name="required"/> <!-- <field name="required"/>-->
</form> </form>
</field> </field>
</record> </record>
@ -283,8 +283,8 @@
<tree string="Journal Column"> <tree string="Journal Column">
<field name="sequence"/> <field name="sequence"/>
<field name="name"/> <field name="name"/>
<field name="required"/> <!-- <field name="required"/>-->
<field name="readonly"/> <!-- <field name="readonly"/>-->
</tree> </tree>
</field> </field>
</record> </record>
@ -295,11 +295,18 @@
<field name="type">form</field> <field name="type">form</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Journal View"> <form string="Journal View">
<field colspan="4" name="name" select="1"/> <field name="name" select="1"/>
<field colspan="4" name="columns_id" nolabel="1" widget="one2many_list"/> <field colspan="4" name="columns_id" nolabel="1" widget="one2many_list"/>
</form> </form>
</field> </field>
</record> </record>
<record id="action_account_journal_view" model="ir.actions.act_window">
<field name="name">Journal Views</field>
<field name="res_model">account.journal.view</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem action="action_account_journal_view" id="menu_action_account_journal_view" parent="account.menu_low_level"/>
<!-- <!--
# Account Journal # Account Journal
@ -953,7 +960,7 @@
<field eval="9" name="priority"/> <field eval="9" name="priority"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Account Entry Line"> <form string="Account Entry Line">
<notebook> <notebook colspan="4">
<page string="Information"> <page string="Information">
<separator colspan="4" string="General Information"/> <separator colspan="4" string="General Information"/>
<field name="name" select="1"/> <field name="name" select="1"/>
@ -1001,8 +1008,11 @@
<search string="Search Entry Lines"> <search string="Search Entry Lines">
<group col='10' colspan='4'> <group col='10' colspan='4'>
<filter icon="terp-document-new" string="Draft" domain="[('state','=','draft')]" help="Draft Entry Lines"/> <filter icon="terp-document-new" string="Draft" domain="[('state','=','draft')]" help="Draft Entry Lines"/>
<filter icon="terp-camera_test" string="Posted" domain="[('state','=','valid')]" help="Posted Entry Lines"/>
<separator orientation="vertical"/> <separator orientation="vertical"/>
<filter icon="terp-camera_test" string="Posted" domain="[('state','=','valid')]" help="Posted Entry Lines"/>
<filter icon="terp-stock_symbol-selection" string="Unposted" domain="[('move_id.state','=','draft')]" help="Unposted Entry Lines"/>
<separator orientation="vertical"/>
<filter icon="terp-stock_symbol-selection" string="Unreconciled" domain="[('reconcile_id','=',False), ('account_id.type','in',['receivable', 'payable'])]" help="Unreconciled Entry Lines"/>
<field name="date" select='1'/> <field name="date" select='1'/>
<field name="account_id" select='1'/> <field name="account_id" select='1'/>
<field name="partner_id" select='1'> <field name="partner_id" select='1'>
@ -1012,8 +1022,8 @@
</group> </group>
<newline/> <newline/>
<group col="10" colspan="4"> <group col="10" colspan="4">
<field name="journal_id" widget="selection" context="{'journal_id':self, 'visible_id':self or 0, 'normal_view':False}"/> <field name="journal_id" required="1" widget="selection" context="{'journal_id':self, 'visible_id':self or 0, 'normal_view':False}"/>
<field name="period_id" widget="selection" context="{'period_id':self}"/> <field name="period_id" required="1" widget="selection" context="{'period_id':self}"/>
</group> </group>
</search> </search>
</field> </field>
@ -1255,7 +1265,6 @@
<field name="view_id" ref="view_move_line_tree"/> <field name="view_id" ref="view_move_line_tree"/>
<field name="search_view_id" ref="view_account_move_line_filter"/> <field name="search_view_id" ref="view_account_move_line_filter"/>
<field name="domain">[('journal_id.type', 'in', ['purchase', 'sale_refund'])]</field> <field name="domain">[('journal_id.type', 'in', ['purchase', 'sale_refund'])]</field>
<field name="context">{'journal_id':1}</field>
</record> </record>
<menuitem action="action_account_moves_purchase" id="menu_eaction_account_moves_purchase" parent="menu_finance_payables"/> <menuitem action="action_account_moves_purchase" id="menu_eaction_account_moves_purchase" parent="menu_finance_payables"/>

View File

@ -296,9 +296,12 @@ class account_installer(osv.osv_memory):
'account_paid_id': acc_template_ref[value['account_paid_id']], 'account_paid_id': acc_template_ref[value['account_paid_id']],
}) })
# Creating Journals # Creating Journals Sales and Purchase
vals_journal={} vals_journal={}
view_id = self.pool.get('account.journal.view').search(cr,uid,[('name','=','Journal View')])[0] data_id = data_pool.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_sp_journal_view')])
data = data_pool.browse(cr, uid, data_id[0])
view_id = data.res_id
seq_id = obj_sequence.search(cr,uid,[('name','=','Account Journal')])[0] seq_id = obj_sequence.search(cr,uid,[('name','=','Account Journal')])[0]
if seq_journal: if seq_journal: