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.

83 lines
2.9 KiB

  1. from odoo import api, fields, models, tools
  2. from psycopg2.extensions import AsIs
  3. class MisCashFlow(models.Model):
  4. _inherit = 'mis.cash_flow'
  5. active = fields.Boolean(default=True)
  6. analytic_account_id = fields.Many2one(
  7. comodel_name='account.analytic.account',
  8. string='Analytic Account',
  9. auto_join=True,
  10. index=True,
  11. readonly=True,
  12. )
  13. @api.model_cr
  14. def init(self):
  15. account_type_receivable = self.env.ref(
  16. 'account.data_account_type_receivable')
  17. query = """
  18. SELECT
  19. -- we use negative id to avoid duplicates and we don't use
  20. -- ROW_NUMBER() because the performance was very poor
  21. -aml.id as id,
  22. CAST('move_line' AS varchar) as line_type,
  23. aml.id as move_line_id,
  24. aml.account_id as account_id,
  25. aml.analytic_account_id as analytic_account_id,
  26. aml.debit as debit,
  27. aml.credit as credit,
  28. aml.reconciled as reconciled,
  29. aml.full_reconcile_id as full_reconcile_id,
  30. aml.partner_id as partner_id,
  31. aml.company_id as company_id,
  32. aml.user_type_id as user_type_id,
  33. aml.name as name,
  34. aml.date_maturity as date,
  35. 1 as active
  36. FROM account_move_line as aml
  37. UNION ALL
  38. SELECT
  39. fl.id as id,
  40. CAST('forecast_line' AS varchar) as line_type,
  41. Null as move_line_id,
  42. fl.account_id as account_id,
  43. fl.active as active,
  44. fl.analytic_account_id as analytic_account_id,
  45. CASE
  46. WHEN fl.balance > 0
  47. THEN fl.balance
  48. ELSE 0.0
  49. END AS debit,
  50. CASE
  51. WHEN fl.balance < 0
  52. THEN -fl.balance
  53. ELSE 0.0
  54. END AS credit,
  55. Null as reconciled,
  56. Null as full_reconcile_id,
  57. fl.partner_id as partner_id,
  58. fl.company_id as company_id,
  59. %i as user_type_id,
  60. fl.name as name,
  61. fl.date as date
  62. FROM mis_cash_flow_forecast_line as fl
  63. """ % account_type_receivable.id
  64. tools.drop_view_if_exists(self.env.cr, self._table)
  65. self._cr.execute(
  66. 'CREATE OR REPLACE VIEW %s AS %s',
  67. (AsIs(self._table), AsIs(query))
  68. )
  69. @api.multi
  70. def action_open_related_line(self):
  71. self.ensure_one()
  72. if self.line_type == 'move_line':
  73. return self.move_line_id.get_formview_action()
  74. else:
  75. return self.env['mis.cash_flow.forecast_line'].browse(
  76. self.id).get_formview_action()