Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to manage the account cashflow operations in OpenERP(Odoo)?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 489
    Comment on it
    In below example, I have written Python script for account cashflow operations. see below python code in .py file :
    1. import time
    2. from datetime import datetime, date, timedelta
    3. import tools
    4. from osv import osv, fields
    5. import decimal_precision as dp
    6. from lxml import etree
    7. import logging
    8. _logger = logging.getLogger(__name__)
    9. from tools.translate import _
    10.  
    11. class account_cashflow_code(osv.osv):
    12. _name = 'account.cashflow.code'
    13. _description = 'Cash Flow Code'
    14. _order = 'sequence,type desc,code'
    15. def format_date(self, cr, uid, date, context):
    16. ''' format date according to language from context '''
    17. if not context:
    18. return date
    19. lang = context.get('lang')
    20. lang_obj = self.pool.get('res.lang')
    21. lang_id = lang_obj.search(cr, uid, [('code','=',lang)])[0]
    22. date_format = str(lang_obj.browse(cr, uid, lang_id).date_format)
    23. return date.strftime(date_format)
    24.  
    25. def _balance_period(self, cr, uid, ids, field_name=None, arg=None, context=None, date_start=None, date_stop=None, day=None):
    26. if context is None:
    27. context = {}
    28. if not date_start:
    29. date_start = context.get('date_start', None)
    30. if not date_stop:
    31. date_stop = context.get('date_stop', None)
    32. company_id = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.id
    33. journal_ids = context.get('journal_ids')
    34.  
    35. if day:
    36. date_start = day
    37. cr.execute('SELECT cashflow_code_id, sum(balance) FROM account_cashflow_balance ' \
    38. 'WHERE date = %s AND journal_id IN %s GROUP BY cashflow_code_id',
    39. (day, tuple(journal_ids)))
    40. elif date_start:
    41. cr.execute('SELECT cashflow_code_id, sum(balance) FROM account_cashflow_balance ' \
    42. 'WHERE date >= %s AND date <= %s AND journal_id IN %s GROUP BY cashflow_code_id',
    43. (date_start, date_stop, tuple(journal_ids)))
    44. else:
    45. cr.execute('SELECT id, 0.0 as amount FROM account_cashflow_code ')
    46. balances = dict(cr.fetchall())
    47. # add 'init' balance
    48. balance_init_id = context.get('balance_init_id', None)
    49. if date_start:
    50. balopen_obj = self.pool.get('account.cashflow.opening.balance')
    51. balance_init = {balance_init_id: balopen_obj.calc_opening_balance(cr, uid, date_start, balance_init_id, journal_ids)}
    52. else:
    53. balance_init = {balance_init_id: 0.0}
    54. balances.update(balance_init)
    55. # calculate period balances
    56. dp = self.pool.get('decimal.precision').precision_get(cr, uid, 'Account')
    57. period_balances = {}
    58. def _rec_get(record):
    59. amount = balances.get(record.id, 0.0)
    60. for rec in record.child_ids:
    61. amount += _rec_get(rec) * rec.parent_sign
    62. return amount
    63. for record in self.browse(cr, uid, ids, context=context):
    64. period_balances[record.id] = round(_rec_get(record), dp)
    65. return period_balances
    66.  
    67. def _balance_day(self, cr, uid, ids, field_name, arg, context):
    68. if context is None:
    69. context = {}
    70. day = None
    71. if context.get('date_start', None):
    72. date_start = context.get('date_start')
    73. nbr_days = int(context.get('nbr_days'))
    74. x = int(field_name[-2:])
    75. if x == 1:
    76. day = date_start
    77. elif x <= nbr_days:
    78. day = (datetime.strptime(date_start, '%Y-%m-%d').date() + timedelta(days = int(field_name[-2:])-1)).isoformat()
    79. return self._balance_period(cr, uid, ids, field_name, arg, context, day=day)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: