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.

163 lines
8.0KB

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