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.

208 lines
7.0 KiB

  1. # -*- coding: utf-8 -*-
  2. from datetime import date, datetime
  3. from openerp import SUPERUSER_ID, api, tools, _
  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('l10n_fr.tva_normale').id
  48. account_setting.execute()
  49. return True
  50. def update_account():
  51. """
  52. Change the name and currency of 411700
  53. """
  54. account_to_update = env['account.account'].search(
  55. [('code', '=', '411700')]
  56. )[0]
  57. account_to_update.name = "Clients - USD"
  58. account_to_update.currency_id = env.ref('base.USD').id
  59. return True
  60. def update_product():
  61. """
  62. Update the product with the right settings
  63. """
  64. product = env.ref('account_financial_test_data.data_product_a')
  65. product.standard_price = 1000
  66. product.lst_price = 1000
  67. product.taxes_id = [
  68. (6, 0, [env.ref('l10n_fr.tva_normale').id])
  69. ]
  70. product.supplier_taxes_id = [
  71. (6, 0, [env.ref('l10n_fr.tva_acq_normale_TTC').id])
  72. ]
  73. income_account = env['account.account'].search([
  74. ('code', '=', '707100')
  75. ])[0]
  76. expense_account = env['account.account'].search([
  77. ('code', '=', '607100')
  78. ])[0]
  79. product.property_account_income_id = income_account
  80. product.property_account_expense_id = expense_account
  81. return True
  82. def create_invoices():
  83. """
  84. Creates all necessary invoices
  85. """
  86. now = datetime.now()
  87. this_year = now.year
  88. last_year = now.year - 1
  89. invoice_obj = env['account.invoice']
  90. invoice_a = invoice_obj.create({
  91. 'partner_id': env.ref(
  92. 'account_financial_test_data.data_partner_c').id,
  93. 'account_id': env.ref(
  94. 'account_financial_test_data.data_partner_c'
  95. ).property_account_receivable_id.id,
  96. 'type': 'out_invoice',
  97. 'date_invoice': date(last_year, 1, 5),
  98. 'date_due': date(last_year, 1, 31),
  99. })
  100. invoice_b = invoice_obj.create({
  101. 'partner_id': env.ref(
  102. 'account_financial_test_data.data_partner_a').id,
  103. 'type': 'out_invoice',
  104. 'account_id': env.ref(
  105. 'account_financial_test_data.data_partner_a'
  106. ).property_account_receivable_id.id,
  107. 'date_invoice': date(last_year, 1, 5),
  108. 'date_due': date(last_year, 2, 4),
  109. })
  110. invoice_c = invoice_obj.create({
  111. 'partner_id': env.ref(
  112. 'account_financial_test_data.data_partner_d').id,
  113. 'type': 'out_invoice',
  114. 'account_id': env.ref(
  115. 'account_financial_test_data.data_partner_d'
  116. ).property_account_receivable_id.id,
  117. 'date_invoice': date(last_year, 12, 11),
  118. 'date_due': date(this_year, 3, 10),
  119. })
  120. invoice_d = invoice_obj.create({
  121. 'partner_id': env.ref(
  122. 'account_financial_test_data.data_partner_g').id,
  123. 'type': 'out_refund',
  124. 'account_id': env.ref(
  125. 'account_financial_test_data.data_partner_g'
  126. ).property_account_receivable_id.id,
  127. 'date_invoice': date(this_year, 1, 3),
  128. 'date_due': date(this_year, 4, 15),
  129. })
  130. invoice_e = invoice_obj.create({
  131. 'partner_id': env.ref(
  132. 'account_financial_test_data.data_partner_b').id,
  133. 'type': 'out_invoice',
  134. 'account_id': env.ref(
  135. 'account_financial_test_data.data_partner_b'
  136. ).property_account_receivable_id.id,
  137. 'date_invoice': date(this_year, 2, 3),
  138. 'date_due': date(this_year, 2, 15),
  139. })
  140. invoice_f = invoice_obj.create({
  141. 'partner_id': env.ref(
  142. 'account_financial_test_data.data_partner_a').id,
  143. 'type': 'out_invoice',
  144. 'account_id': env.ref(
  145. 'account_financial_test_data.data_partner_a'
  146. ).property_account_receivable_id.id,
  147. 'date_invoice': date(this_year, 2, 23),
  148. 'date_due': date(this_year, 3, 24),
  149. })
  150. invoice_g = invoice_obj.create({
  151. 'partner_id': env.ref(
  152. 'account_financial_test_data.data_partner_g').id,
  153. 'type': 'out_invoice',
  154. 'account_id': env.ref(
  155. 'account_financial_test_data.data_partner_g'
  156. ).property_account_receivable_id.id,
  157. 'date_invoice': date(this_year, 3, 17),
  158. 'date_due': date(this_year, 4, 15),
  159. })
  160. invoice_h = invoice_obj.create({
  161. 'partner_id': env.ref(
  162. 'account_financial_test_data.data_partner_f').id,
  163. 'type': 'out_invoice',
  164. 'account_id': env.ref(
  165. 'account_financial_test_data.data_partner_f'
  166. ).property_account_receivable_id.id,
  167. 'date_invoice': date(this_year, 3, 17),
  168. 'date_due': date(this_year, 4, 15),
  169. })
  170. return True
  171. env = api.Environment(cr, SUPERUSER_ID, {})
  172. update_partners()
  173. update_account_settings()
  174. update_account()
  175. update_product()
  176. create_invoices()