[代码分析] 财务报表中的部分变量是如何定义和赋值的?
-
[color=blue][u][size=10pt]account\report\common_report_header.py[/size][/u][/color]
<br />import pooler<br />from tools.translate import _<br /><br />class common_report_header(object):<br /><br /> def _sum_debit(self, period_id=False, journal_id=False):<br /> if journal_id and isinstance(journal_id, int):<br /> journal_id = [journal_id]<br /> if period_id and isinstance(period_id, int):<br /> period_id = [period_id]<br /> if not journal_id:<br /> journal_id = self.journal_ids<br /> if not period_id:<br /> period_id = self.period_ids<br /> if not (period_id and journal_id):<br /> return 0.0<br /> self.cr.execute('SELECT SUM(debit) FROM account_move_line l '<br /> 'WHERE period_id IN %s AND journal_id IN %s ' + self.query_get_clause + ' ',<br /> (tuple(period_id), tuple(journal_id)))<br /> return self.cr.fetchone()[0] or 0.0<br />
找了半天,不知道 [color=red][b]self.journal_ids,self.period_ids,self.query_get_clause[/b][/color]这几个变量在哪里定义,其值从何而来。其子类,比如[color=blue][size=10pt][u]account_balance_sheet.py[/u][/size][/color]也没有找到定义。
请大家帮忙分析一下,谢谢! -
这只是一个class 的定义. 具体的 self.journal_ids 要看这个 class 的子class.
EP:
\addons\account\report\account_general_journal.py<br /><br />....<br />class journal_print(report_sxw.rml_parse, common_report_header):<br /><br /> def __init__(self, cr, uid, name, context=None):<br /> if context is None:<br /> context = {}<br /> super(journal_print, self).__init__(cr, uid, name, context=context)<br /> self.period_ids = []<br /> self.journal_ids = []<br />...<br />
-
Shelly, 你说的这个class的确查询到了上面提到的3个变量。
但 同一目录下的account_profit_loss.py中<br />import time<br />import pooler<br />from report import report_sxw<br />from common_report_header import common_report_header<br />from tools.translate import _<br /><br />class report_pl_account_horizontal(report_sxw.rml_parse, common_report_header):<br /><br /> def __init__(self, cr, uid, name, context=None):<br /> super(report_pl_account_horizontal, self).__init__(cr, uid, name, context=context)<br /> self.result_sum_dr = 0.0<br /> self.result_sum_cr = 0.0<br /> self.res_pl = {}<br /> self.result = {}<br /> self.result_temp = []<br /> self.localcontext.update( {<br />
和同一目录下的 account_balance_sheet.py中<br />import time<br />import pooler<br />from report import report_sxw<br />from account.report import account_profit_loss<br />from common_report_header import common_report_header<br />from tools.translate import _<br /><br />class report_balancesheet_horizontal(report_sxw.rml_parse, common_report_header):<br /> def __init__(self, cr, uid, name, context=None):<br /> super(report_balancesheet_horizontal, self).__init__(cr, uid, name, context=context)<br /> self.obj_pl = account_profit_loss.report_pl_account_horizontal(cr, uid, name, context=context)<br /> self.result_sum_dr = 0.0<br /> self.result_sum_cr = 0.0<br /> self.result = {}<br /> self.res_bl = {}<br /> self.result_temp = []<br /> self.localcontext.update({<br />
都没有查询到,不知道是怎么关联起来的。 -
是的。
被wizard窗口中的过滤字段误导了。
大致过程应该是这样的:
account\account.py<br /> 'balance': fields.function(__compute, digits_compute=dp.get_precision('Account'), method=True, string='Balance', multi='balance'),<br /> 'credit': fields.function(__compute, digits_compute=dp.get_precision('Account'), method=True, string='Credit', multi='balance'),<br /> 'debit': fields.function(__compute, digits_compute=dp.get_precision('Account'), method=True, string='Debit', multi='balance'),<br />
在这个方法__compute里,层层调用才刚刚开始,多少明白一点了。
谢谢Shelly, Jeff,继续往下看。。。