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.

85 lines
3.6KB

  1. # Copyright 2016 上海开阖软件有限公司 (http://www.osbzr.com)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import fields, models, api, tools
  4. MONEY_TYPE = [
  5. ('pay', u'采购'),
  6. ('get', u'销售'),
  7. ('other_pay', u'其他支出'),
  8. ('other_get', u'其他收入'),
  9. ]
  10. class MoneyGetPayReport(models.Model):
  11. _name = "money.get.pay.report"
  12. _description = u"资金收支报表"
  13. _auto = False
  14. _order = 'date'
  15. date = fields.Date(string=u'日期')
  16. name = fields.Char(string=u'单据编号')
  17. type = fields.Selection(MONEY_TYPE,
  18. string=u'类别',
  19. help=u'按类型筛选')
  20. partner_id = fields.Many2one('partner',
  21. string=u'往来单位')
  22. category_id = fields.Many2one('core.category',
  23. u'收支类别',
  24. help=u'类型:运费、咨询费等')
  25. get = fields.Float(string=u'收入',
  26. digits='Amount')
  27. pay = fields.Float(string=u'支出',
  28. digits='Amount')
  29. amount = fields.Float(string=u'金额',
  30. digits='Amount')
  31. def init(self):
  32. # union money_order, other_money_order
  33. cr = self._cr
  34. tools.drop_view_if_exists(cr, 'money_get_pay_report')
  35. cr.execute("""
  36. CREATE or REPLACE VIEW money_get_pay_report AS (
  37. SELECT ROW_NUMBER() OVER(ORDER BY name,date) AS id,
  38. date,
  39. name,
  40. type,
  41. partner_id,
  42. category_id,
  43. get,
  44. pay,
  45. amount
  46. FROM
  47. (
  48. SELECT mo.date,
  49. mo.name,
  50. mo.type,
  51. mo.partner_id,
  52. NULL AS category_id,
  53. (CASE WHEN mo.type = 'get' THEN COALESCE(rc.rate,1)*(mol.amount) ELSE 0 END) AS get,
  54. (CASE WHEN mo.type = 'pay' THEN COALESCE(rc.rate,1)*(mol.amount) ELSE 0 END) AS pay,
  55. (CASE WHEN mo.type = 'get' THEN COALESCE(rc.rate,1)*(mol.amount) ELSE -COALESCE(rc.rate,1)*(mol.amount) END) AS amount
  56. FROM money_order AS mo
  57. LEFT JOIN money_order_line as mol on mol.money_id=mo.id
  58. left join bank_account as ba on mol.bank_id = ba.id
  59. left join res_currency_rate as rc on rc.currency_id=ba.currency_id
  60. WHERE mo.state = 'done'
  61. UNION ALL
  62. SELECT omo.date,
  63. omo.name,
  64. omo.type,
  65. omo.partner_id,
  66. omol.category_id,
  67. (CASE WHEN omo.type = 'other_get' THEN COALESCE(rc.rate,1)*(omol.amount + omol.tax_amount) ELSE 0 END) AS get,
  68. (CASE WHEN omo.type = 'other_pay' THEN COALESCE(rc.rate,1)*(omol.amount + omol.tax_amount) ELSE 0 END) AS pay,
  69. (CASE WHEN omo.type = 'other_get' THEN COALESCE(rc.rate,1)*(omol.amount + omol.tax_amount) ELSE -COALESCE(rc.rate,1)*(omol.amount + omol.tax_amount) END) AS amount
  70. FROM other_money_order AS omo
  71. LEFT JOIN other_money_order_line AS omol ON omo.id = omol.other_money_id
  72. left join bank_account as ba on omo.bank_id = ba.id
  73. left join res_currency_rate as rc on rc.currency_id=ba.currency_id
  74. WHERE omo.state = 'done'
  75. ) AS mr
  76. )
  77. """)
上海开阖软件有限公司 沪ICP备12045867号-1