GoodERP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 satır
7.9KB

  1. from odoo.exceptions import UserError
  2. from odoo import fields, models, api
  3. class CashFlowWizard(models.TransientModel):
  4. _name = "cash.flow.wizard"
  5. _description = "显示现金流量表"
  6. def _default_period_id_impl(self):
  7. """
  8. 默认是当前会计期间
  9. :return: 当前会计期间的对象
  10. """
  11. return self.env['finance.period'].get_date_now_period_id()
  12. @api.model
  13. def _default_period_id(self):
  14. return self._default_period_id_impl()
  15. period_id = fields.Many2one('finance.period', string=u'会计期间',
  16. default=_default_period_id)
  17. @api.model
  18. def get_amount(self, tem, report_ids, period_id):
  19. '''
  20. [('get',u'销售收款'),
  21. ('pay',u'采购付款'),
  22. ('category',u'其他收支'),
  23. ('begin',u'科目期初'),
  24. ('end',u'科目期末'),
  25. ('lines',u'表行计算')]
  26. '''
  27. date_start, date_end = self.env['finance.period'].get_period_month_date_range(
  28. period_id)
  29. ret = 0
  30. if tem.line_type == 'get' or tem.line_type == 'pay':
  31. # 收款单或付款单金额合计
  32. ret = sum([order.amount for order in self.env['money.order'].search([('type', '=', tem.line_type),
  33. ('state',
  34. '=', 'done'),
  35. ('date', '>=',
  36. date_start),
  37. ('date', '<=', date_end)])])
  38. if tem.line_type == 'category':
  39. # 其他收支单金额合计
  40. ret = sum([line.amount + line.tax_amount
  41. for line in self.env['other.money.order.line'].search(
  42. [('category_id', 'in', [c.id for c in tem.category_ids]),
  43. ('other_money_id.state', '=', 'done'),
  44. ('other_money_id.date', '>=', date_start),
  45. ('other_money_id.date', '<=', date_end)])])
  46. if tem.line_type == 'begin':
  47. # 科目期初金额合计
  48. ret = sum([acc.initial_balance_debit - acc.initial_balance_credit
  49. for acc in self.env['trial.balance'].search([('period_id', '=', period_id.id),
  50. ('subject_name_id', 'in', [b.id for b in tem.begin_ids])])])
  51. if tem.line_type == 'end':
  52. # 科目期末金额合计
  53. ret = sum([acc.ending_balance_debit - acc.ending_balance_credit
  54. for acc in self.env['trial.balance'].search([('period_id', '=', period_id.id),
  55. ('subject_name_id', 'in', [e.id for e in tem.end_ids])])])
  56. if tem.line_type == 'lines':
  57. # 根据其他报表行计算
  58. for line in self.env['cash.flow.statement'].browse(report_ids):
  59. for l in tem.plus_ids:
  60. if l.line_num == line.line_num:
  61. ret += line.amount
  62. for l in tem.nega_ids:
  63. if l.line_num == line.line_num:
  64. ret -= line.amount
  65. return ret
  66. @api.model
  67. def get_year_amount(self, tem, report_ids, period_id):
  68. '''
  69. [('get',u'销售收款'),
  70. ('pay',u'采购付款'),
  71. ('category',u'其他收支'),
  72. ('begin',u'科目期初'),
  73. ('end',u'科目期末'),
  74. ('lines',u'表行计算')]
  75. '''
  76. date_start, date_end = self.env['finance.period'].get_period_month_date_range(
  77. period_id)
  78. date_start = date_start[0:5] + '01-01'
  79. ret = 0
  80. if tem.line_type == 'get' or tem.line_type == 'pay':
  81. # 收款单或付款单金额合计
  82. ret = sum([order.amount for order in self.env['money.order'].search([('type', '=', tem.line_type),
  83. ('state',
  84. '=', 'done'),
  85. ('date', '>=',
  86. date_start),
  87. ('date', '<=', date_end)])])
  88. if tem.line_type == 'category':
  89. # 其他收支单金额合计
  90. ret = sum([line.amount + line.tax_amount
  91. for line in self.env['other.money.order.line'].search(
  92. [('category_id', 'in', [c.id for c in tem.category_ids]),
  93. ('other_money_id.state', '=', 'done'),
  94. ('other_money_id.date', '>=', date_start),
  95. ('other_money_id.date', '<=', date_end)])])
  96. if tem.line_type == 'begin':
  97. # 科目期初金额合计
  98. ret = sum([acc.year_init_debit - acc.year_init_credit
  99. for acc in self.env['trial.balance'].search([('period_id', '=', period_id.id),
  100. ('subject_name_id', 'in', [b.id for b in tem.begin_ids])])])
  101. if tem.line_type == 'end':
  102. # 科目期末金额合计
  103. ret = sum([acc.ending_balance_debit - acc.ending_balance_credit
  104. for acc in self.env['trial.balance'].search([('period_id', '=', period_id.id),
  105. ('subject_name_id', 'in', [e.id for e in tem.end_ids])])])
  106. if tem.line_type == 'lines':
  107. # 根据其他报表行计算
  108. for line in self.env['cash.flow.statement'].browse(report_ids):
  109. for l in tem.plus_ids:
  110. if l.line_num == line.line_num:
  111. ret += line.year_amount
  112. for l in tem.nega_ids:
  113. if l.line_num == line.line_num:
  114. ret -= line.year_amount
  115. return ret
  116. def show(self):
  117. """生成现金流量表"""
  118. rep_ids = []
  119. '''
  120. old_report = self.env['cash.flow.statement'].search([('period_id','=',self.period_id.id)])
  121. if old_report:
  122. rep_ids = [rep.id for rep in old_report]
  123. else:
  124. '''
  125. if self.period_id:
  126. templates = self.env['cash.flow.template'].search([])
  127. for tem in templates:
  128. new_rep = self.env['cash.flow.statement'].create(
  129. {
  130. 'name': tem.name,
  131. 'line_num': tem.line_num,
  132. 'amount': self.get_amount(tem, rep_ids, self.period_id),
  133. 'year_amount': self.get_year_amount(tem, rep_ids, self.period_id),
  134. }
  135. )
  136. rep_ids.append(new_rep.id)
  137. view_id = self.env.ref('money.cash_flow_statement_list').id
  138. attachment_information = u'编制单位:' + self.env.user.company_id.name + u',,' + self.period_id.year\
  139. + u'年' + self.period_id.month + u'月' + u',' + u'单位:元'
  140. return {
  141. 'type': 'ir.actions.act_window',
  142. 'name': u'现金流量表:' + self.period_id.name,
  143. 'view_mode': 'list',
  144. 'res_model': 'cash.flow.statement',
  145. 'target': 'main',
  146. 'view_id': False,
  147. 'views': [(view_id, 'list')],
  148. 'context': {'period_id': self.period_id.id, 'attachment_information': attachment_information},
  149. 'domain': [('id', 'in', rep_ids)],
  150. 'limit': 65535,
  151. }
上海开阖软件有限公司 沪ICP备12045867号-1