Reviewers: ,


Please review this at http://codereview.tryton.org/505005/

Affected files:
  M CHANGELOG
  M account.py
  M account.xml


Index: CHANGELOG
===================================================================

--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,4 @@
+* Compute the aged balance in the past
 * Allow to open accounts from balance sheet
 * Add start/end balance to Trial balance


Index: account.py
===================================================================

--- a/account.py
+++ b/account.py
@@ -2144,8 +2144,6 @@
     _name = 'account.open_aged_balance.start'
     _description = __doc__
     company = fields.Many2One('company.company', 'Company', required=True)
-    fiscalyear = fields.Many2One('account.fiscalyear', 'Fiscal Year',
-            required=True)
     balance_type = fields.Selection(
[('customer', 'Customer'), ('supplier', 'Supplier'), ('both', 'Both')],
         "Type", required=True)
@@ -2156,13 +2154,6 @@
         [('day', 'Day'), ('month', 'Month')], "Unit", required=True)
     posted = fields.Boolean('Posted Move', help='Show only posted move')

-    def default_fiscalyear(self):
-        fiscalyear_obj = Pool().get('account.fiscalyear')
-        fiscalyear_id = fiscalyear_obj.find(
-                Transaction().context.get('company'), exception=False)
-        if fiscalyear_id:
-            return fiscalyear_id
-
     def default_balance_type(self):
         return "customer"

@@ -2211,7 +2202,6 @@
                     error_description="term_overlap_desc")
         data = {
             'company': session.start.company.id,
-            'fiscalyear': session.start.fiscalyear.id,
             'term1': session.start.term1,
             'term2': session.start.term2,
             'term3': session.start.term3,
@@ -2233,23 +2223,16 @@
     def parse(self, report, objects, data, localcontext):
         pool = Pool()
         party_obj = pool.get('party.party')
-        move_line_obj = pool.get('account.move.line')
         company_obj = pool.get('company.company')
         date_obj = pool.get('ir.date')
         cursor = Transaction().cursor

         company = company_obj.browse(data['company'])
-        localcontext['digits'] = company.currency.digits
-        localcontext['fiscalyear'] = data['fiscalyear']
-        localcontext['posted'] = data['posted']
-        with Transaction().set_context(context=localcontext):
-            line_query, _ = move_line_obj.query_get()
-
         terms = (data['term1'], data['term2'], data['term3'])
         if data['unit'] == 'month':
-            coef = 30
+            coef = datetime.timedelta(days=30)
         else:
-            coef = 1
+            coef = datetime.timedelta(days=1)

         kind = {
             'both': ('payable', 'receivable'),
@@ -2259,19 +2242,15 @@

         res = {}
         for position, term in enumerate(terms):
-            if position == 0:
-                term_query = '(l.maturity_date <= %s '\
-                    'OR l.maturity_date IS NULL) '
-                term_args = (date_obj.today() +
-                        datetime.timedelta(days=term * coef),)
+            if position == 2:
+                term_query = 'l.maturity_date <= %s'
+                term_args = (date_obj.today() - term * coef,)
             else:
                 term_query = '(l.maturity_date <= %s '\
                     'AND l.maturity_date > %s) '
                 term_args = (
- date_obj.today() + datetime.timedelta(days=term * coef),
-                    date_obj.today()
-                    + datetime.timedelta(days=terms[position - 1] * coef),
-                    )
+                    date_obj.today() - term * coef,
+                    date_obj.today() - terms[position + 1] * coef)

             cursor.execute('SELECT l.party, SUM(l.debit) - SUM(l.credit) '
                 'FROM account_move_line l '
@@ -2283,7 +2262,6 @@
                     'AND l.reconciliation IS NULL '
                     'AND a.company = %s '
                     'AND ' + term_query + ' '
-                    'AND ' + line_query + ' '
                     'GROUP BY l.party '
                     'HAVING (SUM(l.debit) - SUM(l.credit) != 0)',
                 kind + (data['company'],) + term_args)

Index: account.xml
===================================================================

--- a/account.xml
+++ b/account.xml
@@ -1004,9 +1004,6 @@
             <field name="arch" type="xml">
                 <![CDATA[
                 <form string="Open Aged Balance" col="4">
-                    <label name="fiscalyear"/>
-                    <field name="fiscalyear"/>
-                    <newline/>
                     <label name="balance_type"/>
                     <field name="balance_type"/>
                     <newline/>



--
[email protected] mailing list

Reply via email to