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.

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