Odoo中文社区可以通过以下三个域名访问:shine-it.net , odoocn.org,odoo.net.cn

原论坛用户的基本信息和发帖这里都予以保留,请注意:原论坛用户无需重新注册新用户,但是您的密码需要重置

开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

如果您登录系统碰到问题,请在微信公众号留言:

[代码分析] 财务报表中的部分变量是如何定义和赋值的?



  • [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 />&nbsp; &nbsp; def _sum_debit(self, period_id=False, journal_id=False):<br />&nbsp; &nbsp; &nbsp; &nbsp; if journal_id and isinstance(journal_id, int):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; journal_id = [journal_id]<br />&nbsp; &nbsp; &nbsp; &nbsp; if period_id and isinstance(period_id, int):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; period_id = [period_id]<br />&nbsp; &nbsp; &nbsp; &nbsp; if not journal_id:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; journal_id = self.journal_ids<br />&nbsp; &nbsp; &nbsp; &nbsp; if not period_id:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; period_id = self.period_ids<br />&nbsp; &nbsp; &nbsp; &nbsp; if not (period_id and journal_id):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 0.0<br />&nbsp; &nbsp; &nbsp; &nbsp; self.cr.execute(&#039;SELECT SUM(debit) FROM account_move_line l &#039;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;WHERE period_id IN %s AND journal_id IN %s &#039; + self.query_get_clause + &#039; &#039;,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (tuple(period_id), tuple(journal_id)))<br />&nbsp; &nbsp; &nbsp; &nbsp; 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 />&nbsp; &nbsp; def __init__(self, cr, uid, name, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; if context is None:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context = {}<br />&nbsp; &nbsp; &nbsp; &nbsp; super(journal_print, self).__init__(cr, uid, name, context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp; self.period_ids = &#91;]<br />&nbsp; &nbsp; &nbsp; &nbsp; self.journal_ids = &#91;]<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 />&nbsp; &nbsp; def __init__(self, cr, uid, name, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; super(report_pl_account_horizontal, self).__init__(cr, uid, name, context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp; self.result_sum_dr = 0.0<br />&nbsp; &nbsp; &nbsp; &nbsp; self.result_sum_cr = 0.0<br />&nbsp; &nbsp; &nbsp; &nbsp; self.res_pl = {}<br />&nbsp; &nbsp; &nbsp; &nbsp; self.result = {}<br />&nbsp; &nbsp; &nbsp; &nbsp; self.result_temp = &#91;]<br />&nbsp; &nbsp; &nbsp; &nbsp; 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 />&nbsp; &nbsp; def __init__(self, cr, uid, name, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; super(report_balancesheet_horizontal, self).__init__(cr, uid, name, context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp; self.obj_pl = account_profit_loss.report_pl_account_horizontal(cr, uid, name, context=context)<br />&nbsp; &nbsp; &nbsp; &nbsp; self.result_sum_dr = 0.0<br />&nbsp; &nbsp; &nbsp; &nbsp; self.result_sum_cr = 0.0<br />&nbsp; &nbsp; &nbsp; &nbsp; self.result = {}<br />&nbsp; &nbsp; &nbsp; &nbsp; self.res_bl = {}<br />&nbsp; &nbsp; &nbsp; &nbsp; self.result_temp = &#91;]<br />&nbsp; &nbsp; &nbsp; &nbsp; self.localcontext.update({<br />
    


    都没有查询到,不知道是怎么关联起来的。



  • 如果 class A 里某个方法有个特别的变量


    而你 class B 继承于 class A 但不使用 class A里的那个方法.. 是不是不用管那个变量呢?

    仅供参考....



  • 是的。
    被wizard窗口中的过滤字段误导了。
    大致过程应该是这样的:
    account\account.py

    <br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;balance&#039;: fields.function(__compute, digits_compute=dp.get_precision(&#039;Account&#039;), method=True, string=&#039;Balance&#039;, multi=&#039;balance&#039;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;credit&#039;: fields.function(__compute, digits_compute=dp.get_precision(&#039;Account&#039;), method=True, string=&#039;Credit&#039;, multi=&#039;balance&#039;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;debit&#039;: fields.function(__compute, digits_compute=dp.get_precision(&#039;Account&#039;), method=True, string=&#039;Debit&#039;, multi=&#039;balance&#039;),<br />
    


    在这个方法__compute里,层层调用才刚刚开始,多少明白一点了。
    谢谢Shelly, Jeff,继续往下看。。。