~openerp-indonesia-team/openerp-indonesia/openerp-addons-Indonesia

« back to all changes in this revision

Viewing changes to account/account_move_line.py

  • Committer: Iman(ADSOFT)
  • Date: 2011-05-06 23:31:40 UTC
  • Revision ID: alle@openerp.co.id-20110506233140-egef2xos807fw784
updates

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
        if context.get('company_id', False):
46
46
            company_clause = " AND " +obj+".company_id = %s" % context.get('company_id', False)
47
47
        if not context.get('fiscalyear', False):
48
 
            fiscalyear_ids = fiscalyear_obj.search(cr, uid, [('state', '=', 'draft')])
 
48
            if context.get('all_fiscalyear', False):
 
49
                #this option is needed by the aged balance report because otherwise, if we search only the draft ones, an open invoice of a closed fiscalyear won't be displayed
 
50
                fiscalyear_ids = fiscalyear_obj.search(cr, uid, [])
 
51
            else:
 
52
                fiscalyear_ids = fiscalyear_obj.search(cr, uid, [('state', '=', 'draft')])
49
53
        else:
50
54
            #for initial balance as well as for normal query, we check only the selected FY because the best practice is to generate the FY opening entries
51
55
            fiscalyear_ids = [context['fiscalyear']]
74
78
                context['periods'] = fiscalperiod_obj.build_ctx_periods(cr, uid, context['period_from'], context['period_to'])
75
79
        if context.get('periods', False):
76
80
            if initial_bal:
77
 
                query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN (%s) %s %s)" % (fiscalyear_clause, where_move_state, where_move_lines_by_date)
 
81
                query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN (%s)) %s %s" % (fiscalyear_clause, where_move_state, where_move_lines_by_date)
78
82
                period_ids = fiscalperiod_obj.search(cr, uid, [('id', 'in', context['periods'])], order='date_start', limit=1)
79
83
                if period_ids and period_ids[0]:
80
84
                    first_period = fiscalperiod_obj.browse(cr, uid, period_ids[0], context=context)
97
101
            query += ' AND '+obj+'.account_id IN (%s)' % ','.join(map(str, child_ids))
98
102
 
99
103
        query += company_clause
100
 
 
101
104
        return query
102
105
 
103
106
    def _amount_residual(self, cr, uid, ids, field_names, args, context=None):
104
107
        """
105
 
           This function returns the residual amount on a receivable or payable account.move.line. 
106
 
           By default, it returns an amount in the currency of this journal entry (maybe different 
107
 
           of the company currency), but if you pass 'residual_in_company_currency' = True in the 
 
108
           This function returns the residual amount on a receivable or payable account.move.line.
 
109
           By default, it returns an amount in the currency of this journal entry (maybe different
 
110
           of the company currency), but if you pass 'residual_in_company_currency' = True in the
108
111
           context then the returned amount will be in company currency.
109
112
        """
110
113
        res = {}
116
119
                'amount_residual': 0.0,
117
120
                'amount_residual_currency': 0.0,
118
121
            }
119
 
 
 
122
 
120
123
            if move_line.reconcile_id:
121
124
                continue
122
125
            if not move_line.account_id.type in ('payable', 'receivable'):
123
126
                #this function does not suport to be used on move lines not related to payable or receivable accounts
124
127
                continue
125
 
            
 
128
 
126
129
            if move_line.currency_id:
127
130
                move_line_total = move_line.amount_currency
128
131
                sign = move_line.amount_currency < 0 and -1 or 1
223
226
        # Starts: Manual entry from account.move form
224
227
        if context.get('lines',[]):
225
228
            total_new = 0.00
226
 
            for i in context['lines']:
227
 
                if i[2]:
228
 
                    total_new += (i[2]['debit'] or 0.00)- (i[2]['credit'] or 0.00)
229
 
                    for item in i[2]:
230
 
                            data[item] = i[2][item]
 
229
            for line_record in context['lines']:
 
230
                if not isinstance(line_record, (tuple, list)):
 
231
                    line_record_detail = self.read(cr, uid, line_record, ['analytic_account_id','debit','credit','name','reconcile_id','tax_code_id','tax_amount','account_id','ref','currency_id','date_maturity','amount_currency','partner_id', 'reconcile_partial_id'])
 
232
                else:
 
233
                    line_record_detail = line_record[2]
 
234
                total_new += (line_record_detail['debit'] or 0.00)- (line_record_detail['credit'] or 0.00)
 
235
                for item in line_record_detail.keys():
 
236
                    data[item] = line_record_detail[item]
231
237
            if context['journal']:
232
238
                journal_data = journal_obj.browse(cr, uid, context['journal'], context=context)
233
239
                if journal_data.type == 'purchase':
491
497
        'journal_id': fields.many2one('account.journal', 'Journal', required=True, select=1),
492
498
        'blocked': fields.boolean('Litigation', help="You can check this box to mark this journal item as a litigation with the associated partner"),
493
499
        'partner_id': fields.many2one('res.partner', 'Partner', select=1, ondelete='restrict'),
494
 
        'date_maturity': fields.date('Due date', help="This field is used for payable and receivable journal entries. You can put the limit date for the payment of this line."),
495
 
        'date': fields.related('move_id','date', string='Effective date', type='date', required=True,
 
500
        'date_maturity': fields.date('Due date', select=True ,help="This field is used for payable and receivable journal entries. You can put the limit date for the payment of this line."),
 
501
        'date': fields.related('move_id','date', string='Effective date', type='date', required=True, select=True,
496
502
                                store = {
497
503
                                    'account.move': (_get_move_lines, ['date'], 20)
498
504
                                }),
499
 
        'date_created': fields.date('Creation date'),
 
505
        'date_created': fields.date('Creation date', select=True),
500
506
        'analytic_lines': fields.one2many('account.analytic.line', 'move_id', 'Analytic lines'),
501
507
        'centralisation': fields.selection([('normal','Normal'),('credit','Credit Centralisation'),('debit','Debit Centralisation')], 'Centralisation', size=6),
502
508
        'balance': fields.function(_balance, fnct_search=_balance_search, method=True, string='Balance'),
585
591
                return False
586
592
        return True
587
593
 
588
 
    def _check_partner_id(self, cr, uid, ids, context=None):
589
 
        lines = self.browse(cr, uid, ids, context=context)
590
 
        for l in lines:
591
 
            if l.account_id.type in ('receivable', 'payable') and not l.partner_id:
592
 
                return False
593
 
        return True
594
 
 
595
594
    _constraints = [
596
595
        (_check_no_view, 'You can not create move line on view account.', ['account_id']),
597
596
        (_check_no_closed, 'You can not create move line on closed account.', ['account_id']),
598
597
        (_check_company_id, 'Company must be same for its related account and period.',['company_id'] ),
599
 
        (_check_partner_id, 'You can not create move line on receivable/payable account without partner', ['account_id'] )
600
598
    ]
601
599
 
602
600
    #TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id
898
896
        if context.get('account_id', False):
899
897
            cr.execute('SELECT code FROM account_account WHERE id = %s', (context['account_id'], ))
900
898
            res = cr.fetchone()
901
 
            res = _('Entries: ')+ (res[0] or '')
 
899
            if res:
 
900
                res = _('Entries: ')+ (res[0] or '')
902
901
            return res
903
902
        if (not context.get('journal_id', False)) or (not context.get('period_id', False)):
904
903
            return False
907
906
        cr.execute('SELECT code FROM account_period WHERE id = %s', (context['period_id'], ))
908
907
        p = cr.fetchone()[0] or ''
909
908
        if j or p:
910
 
            return j+(p and (':'+p) or '')
 
909
            return j + (p and (':' + p) or '')
911
910
        return False
912
911
 
913
912
    def onchange_date(self, cr, user, ids, date, context=None):
941
940
        journal_pool = self.pool.get('account.journal')
942
941
        if context is None:
943
942
            context = {}
944
 
        result = super(osv.osv, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar, submenu=submenu)
 
943
        result = super(account_move_line, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar, submenu=submenu)
945
944
        if view_type != 'tree':
946
945
            #Remove the toolbar from the form view
947
946
            if view_type == 'form':
950
949
            #Restrict the list of journal view in search view
951
950
            if view_type == 'search' and result['fields'].get('journal_id', False):
952
951
                result['fields']['journal_id']['selection'] = journal_pool.name_search(cr, uid, '', [], context=context)
 
952
                ctx = context.copy()
 
953
                #we add the refunds journal in the selection field of journal
 
954
                if context.get('journal_type', False) == 'sale':
 
955
                    ctx.update({'journal_type': 'sale_refund'})
 
956
                    result['fields']['journal_id']['selection'] += journal_pool.name_search(cr, uid, '', [], context=ctx)
 
957
                elif context.get('journal_type', False) == 'purchase':
 
958
                    ctx.update({'journal_type': 'purchase_refund'})
 
959
                    result['fields']['journal_id']['selection'] += journal_pool.name_search(cr, uid, '', [], context=ctx)
953
960
            return result
954
961
        if context.get('view_mode', False):
955
962
            return result
1032
1039
 
1033
1040
            if field in widths:
1034
1041
                attrs.append('width="'+str(widths[field])+'"')
1035
 
            attrs.append("invisible=\"context.get('visible_id') not in %s\"" % (fields.get(field)))
 
1042
 
 
1043
            if field in ('journal_id',):
 
1044
                attrs.append("invisible=\"context.get('journal_id', False)\"")
 
1045
            elif field in ('period_id',):
 
1046
                attrs.append("invisible=\"context.get('period_id', False)\"")
 
1047
            else:
 
1048
                attrs.append("invisible=\"context.get('visible_id') not in %s\"" % (fields.get(field)))
1036
1049
            xml += '''<field name="%s" %s/>\n''' % (field,' '.join(attrs))
1037
1050
 
1038
1051
        xml += '''</tree>'''