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.

176 lines
5.7 KiB

5 years ago
5 years ago
  1. # Copyright 2019 Coop IT Easy SCRL fs
  2. # Robin Keunen <robin@coopiteasy.be>
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. import odoo.tests.common as common
  5. class EMCBaseCase(common.TransactionCase):
  6. @classmethod
  7. def setUpClass(cls, *args, **kwargs):
  8. super().setUpClass(*args, **kwargs)
  9. def _chart_template_create(self):
  10. transfer_account_id = self.env["account.account.template"].create(
  11. {
  12. "code": "000",
  13. "name": "Liquidity Transfers",
  14. "reconcile": True,
  15. "user_type_id": self.env.ref(
  16. "account.data_account_type_current_assets"
  17. ).id,
  18. }
  19. )
  20. self.chart = self.env["account.chart.template"].create(
  21. {
  22. "name": "Test COA",
  23. "code_digits": 4,
  24. "bank_account_code_prefix": 1014,
  25. "cash_account_code_prefix": 1014,
  26. "currency_id": self.env.ref("base.USD").id,
  27. "transfer_account_code_prefix": "000",
  28. }
  29. )
  30. transfer_account_id.update({"chart_template_id": self.chart.id})
  31. self.env["ir.model.data"].create(
  32. {
  33. "res_id": transfer_account_id.id,
  34. "model": transfer_account_id._name,
  35. "name": "Liquidity Transfers",
  36. }
  37. )
  38. act = self.env["account.account.template"].create(
  39. {
  40. "code": "001",
  41. "name": "Expenses",
  42. "user_type_id": self.env.ref(
  43. "account.data_account_type_expenses"
  44. ).id,
  45. "chart_template_id": self.chart.id,
  46. "reconcile": True,
  47. }
  48. )
  49. self.env["ir.model.data"].create(
  50. {"res_id": act.id, "model": act._name, "name": "expenses"}
  51. )
  52. act = self.env["account.account.template"].create(
  53. {
  54. "code": "002",
  55. "name": "Product Sales",
  56. "user_type_id": self.env.ref(
  57. "account.data_account_type_revenue"
  58. ).id,
  59. "chart_template_id": self.chart.id,
  60. "reconcile": True,
  61. }
  62. )
  63. self.env["ir.model.data"].create(
  64. {"res_id": act.id, "model": act._name, "name": "sales"}
  65. )
  66. act = self.env["account.account.template"].create(
  67. {
  68. "code": "003",
  69. "name": "Account Receivable",
  70. "user_type_id": self.env.ref(
  71. "account.data_account_type_receivable"
  72. ).id,
  73. "chart_template_id": self.chart.id,
  74. "reconcile": True,
  75. }
  76. )
  77. self.env["ir.model.data"].create(
  78. {"res_id": act.id, "model": act._name, "name": "receivable"}
  79. )
  80. act = self.env["account.account.template"].create(
  81. {
  82. "code": "004",
  83. "name": "Account Payable",
  84. "user_type_id": self.env.ref(
  85. "account.data_account_type_payable"
  86. ).id,
  87. "chart_template_id": self.chart.id,
  88. "reconcile": True,
  89. }
  90. )
  91. self.env["ir.model.data"].create(
  92. {"res_id": act.id, "model": act._name, "name": "payable"}
  93. )
  94. def _add_chart_of_accounts(self):
  95. self.company = self.env.user.company_id
  96. self.chart.try_loading_for_current_company()
  97. self.revenue = self.env["account.account"].search(
  98. [
  99. (
  100. "user_type_id",
  101. "=",
  102. self.env.ref("account.data_account_type_revenue").id,
  103. )
  104. ],
  105. limit=1,
  106. )
  107. self.expense = self.env["account.account"].search(
  108. [
  109. (
  110. "user_type_id",
  111. "=",
  112. self.env.ref("account.data_account_type_expenses").id,
  113. )
  114. ],
  115. limit=1,
  116. )
  117. self.receivable = self.env["account.account"].search(
  118. [
  119. (
  120. "user_type_id",
  121. "=",
  122. self.env.ref("account.data_account_type_receivable").id,
  123. )
  124. ],
  125. limit=1,
  126. )
  127. self.payable = self.env["account.account"].search(
  128. [
  129. (
  130. "user_type_id",
  131. "=",
  132. self.env.ref("account.data_account_type_payable").id,
  133. )
  134. ],
  135. limit=1,
  136. )
  137. self.equity_account = self.env.ref("easy_my_coop.account_equity_demo")
  138. self.cooperator_account = self.env.ref(
  139. "easy_my_coop.account_cooperator_demo"
  140. )
  141. return True
  142. def _journals_setup(self):
  143. self.subscription_journal = self.env.ref(
  144. "easy_my_coop.subscription_journal"
  145. )
  146. self.subscription_journal.write(
  147. {
  148. "default_debit_account_id": self.equity_account.id,
  149. "default_credit_account_id": self.equity_account.id,
  150. }
  151. )
  152. self.bank_journal = self.env["account.journal"].search(
  153. [("type", "=", "bank")], limit=1
  154. )
  155. return True
  156. def setUp(self):
  157. super(EMCBaseCase, self).setUp()
  158. self._chart_template_create()
  159. self._add_chart_of_accounts()
  160. self._journals_setup()
  161. def as_user(self):
  162. self.uid = self.ref("base.user_demo")
  163. def as_emc_user(self):
  164. self.uid = self.ref("easy_my_coop.res_users_user_emc_demo")
  165. def as_emc_manager(self):
  166. self.uid = self.ref("easy_my_coop.res_users_manager_emc_demo")