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.

217 lines
7.0 KiB

  1. # -*- coding: utf-8 -*-
  2. from datetime import date, datetime
  3. from openerp import SUPERUSER_ID, api
  4. def post_init_hook(cr, registry):
  5. def update_partners():
  6. """
  7. Set the right account on partners
  8. """
  9. partner_a = env.ref('account_financial_test_data.data_partner_a')
  10. partner_b = env.ref('account_financial_test_data.data_partner_b')
  11. partner_c = env.ref('account_financial_test_data.data_partner_c')
  12. partner_d = env.ref('account_financial_test_data.data_partner_d')
  13. partner_e = env.ref('account_financial_test_data.data_partner_e')
  14. partner_f = env.ref('account_financial_test_data.data_partner_f')
  15. partner_g = env.ref('account_financial_test_data.data_partner_g')
  16. account_a_receivable = env['account.account'].search(
  17. [('code', '=', '411700')]
  18. )
  19. account_receivable = env['account.account'].search(
  20. [('code', '=', '411100')]
  21. )
  22. account_payable = env['account.account'].search(
  23. [('code', '=', '401100')]
  24. )
  25. partner_a.property_account_receivable_id = account_a_receivable[0]
  26. partner_a.property_account_payable_id = account_payable[0]
  27. partners_list = [
  28. partner_b,
  29. partner_c,
  30. partner_d,
  31. partner_e,
  32. partner_f,
  33. partner_g
  34. ]
  35. for partner in partners_list:
  36. partner.property_account_receivable_id = account_receivable[0]
  37. partner.property_account_payable_id = account_payable[0]
  38. return True
  39. def update_account_settings():
  40. """
  41. Configure account settings
  42. """
  43. account_setting_obj = env['account.config.settings']
  44. account_setting = account_setting_obj.create({})
  45. account_setting.group_multi_currency = True
  46. account_setting.default_sale_tax_id = env.ref('l10n_fr.tva_normale').id
  47. account_setting.default_purchase_tax_id = env.ref(
  48. 'l10n_fr.tva_normale').id
  49. account_setting.execute()
  50. return True
  51. def update_account():
  52. """
  53. Change the name and currency of 411700
  54. """
  55. account_to_update = env['account.account'].search(
  56. [('code', '=', '411700')]
  57. )[0]
  58. account_to_update.name = "Clients - USD"
  59. account_to_update.currency_id = env.ref('base.USD').id
  60. return True
  61. def update_product():
  62. """
  63. Update the product with the right settings
  64. """
  65. product = env.ref('account_financial_test_data.data_product_a')
  66. product.standard_price = 1000
  67. product.lst_price = 1000
  68. product.taxes_id = [
  69. (6, 0, [env.ref('l10n_fr.tva_normale').id])
  70. ]
  71. product.supplier_taxes_id = [
  72. (6, 0, [env.ref('l10n_fr.tva_acq_normale_TTC').id])
  73. ]
  74. income_account = env['account.account'].search([
  75. ('code', '=', '707100')
  76. ])[0]
  77. expense_account = env['account.account'].search([
  78. ('code', '=', '607100')
  79. ])[0]
  80. product.property_account_income_id = income_account
  81. product.property_account_expense_id = expense_account
  82. return True
  83. def create_invoices():
  84. """
  85. Creates all necessary invoices
  86. """
  87. now = datetime.now()
  88. this_year = now.year
  89. last_year = now.year - 1
  90. invoice_obj = env['account.invoice']
  91. # invoice_a
  92. invoice_obj.create({
  93. 'partner_id': env.ref(
  94. 'account_financial_test_data.data_partner_c').id,
  95. 'account_id': env.ref(
  96. 'account_financial_test_data.data_partner_c'
  97. ).property_account_receivable_id.id,
  98. 'type': 'out_invoice',
  99. 'date_invoice': date(last_year, 1, 5),
  100. 'date_due': date(last_year, 1, 31),
  101. })
  102. # invoice_b
  103. invoice_obj.create({
  104. 'partner_id': env.ref(
  105. 'account_financial_test_data.data_partner_a').id,
  106. 'type': 'out_invoice',
  107. 'account_id': env.ref(
  108. 'account_financial_test_data.data_partner_a'
  109. ).property_account_receivable_id.id,
  110. 'date_invoice': date(last_year, 1, 5),
  111. 'date_due': date(last_year, 2, 4),
  112. })
  113. # invoice_c
  114. invoice_obj.create({
  115. 'partner_id': env.ref(
  116. 'account_financial_test_data.data_partner_d').id,
  117. 'type': 'out_invoice',
  118. 'account_id': env.ref(
  119. 'account_financial_test_data.data_partner_d'
  120. ).property_account_receivable_id.id,
  121. 'date_invoice': date(last_year, 12, 11),
  122. 'date_due': date(this_year, 3, 10),
  123. })
  124. # invoice_d
  125. invoice_obj.create({
  126. 'partner_id': env.ref(
  127. 'account_financial_test_data.data_partner_g').id,
  128. 'type': 'out_refund',
  129. 'account_id': env.ref(
  130. 'account_financial_test_data.data_partner_g'
  131. ).property_account_receivable_id.id,
  132. 'date_invoice': date(this_year, 1, 3),
  133. 'date_due': date(this_year, 4, 15),
  134. })
  135. # invoice_e
  136. invoice_obj.create({
  137. 'partner_id': env.ref(
  138. 'account_financial_test_data.data_partner_b').id,
  139. 'type': 'out_invoice',
  140. 'account_id': env.ref(
  141. 'account_financial_test_data.data_partner_b'
  142. ).property_account_receivable_id.id,
  143. 'date_invoice': date(this_year, 2, 3),
  144. 'date_due': date(this_year, 2, 15),
  145. })
  146. # invoice_f
  147. invoice_obj.create({
  148. 'partner_id': env.ref(
  149. 'account_financial_test_data.data_partner_a').id,
  150. 'type': 'out_invoice',
  151. 'account_id': env.ref(
  152. 'account_financial_test_data.data_partner_a'
  153. ).property_account_receivable_id.id,
  154. 'date_invoice': date(this_year, 2, 23),
  155. 'date_due': date(this_year, 3, 24),
  156. })
  157. # invoice_g
  158. invoice_obj.create({
  159. 'partner_id': env.ref(
  160. 'account_financial_test_data.data_partner_g').id,
  161. 'type': 'out_invoice',
  162. 'account_id': env.ref(
  163. 'account_financial_test_data.data_partner_g'
  164. ).property_account_receivable_id.id,
  165. 'date_invoice': date(this_year, 3, 17),
  166. 'date_due': date(this_year, 4, 15),
  167. })
  168. # invoice_h
  169. invoice_obj.create({
  170. 'partner_id': env.ref(
  171. 'account_financial_test_data.data_partner_f').id,
  172. 'type': 'out_invoice',
  173. 'account_id': env.ref(
  174. 'account_financial_test_data.data_partner_f'
  175. ).property_account_receivable_id.id,
  176. 'date_invoice': date(this_year, 3, 17),
  177. 'date_due': date(this_year, 4, 15),
  178. })
  179. return True
  180. env = api.Environment(cr, SUPERUSER_ID, {})
  181. update_partners()
  182. update_account_settings()
  183. update_account()
  184. update_product()
  185. create_invoices()