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.

127 lines
3.8 KiB

  1. # -*- coding: utf-8 -*-
  2. from openerp import SUPERUSER_ID, api, tools, _
  3. def post_init_hook(cr, registry):
  4. def update_partners():
  5. """
  6. Set the right account on partners
  7. """
  8. partner_a = env.ref('account_financial_test_data.data_partner_a')
  9. partner_b = env.ref('account_financial_test_data.data_partner_b')
  10. partner_c = env.ref('account_financial_test_data.data_partner_c')
  11. partner_d = env.ref('account_financial_test_data.data_partner_d')
  12. partner_e = env.ref('account_financial_test_data.data_partner_e')
  13. partner_f = env.ref('account_financial_test_data.data_partner_f')
  14. partner_g = env.ref('account_financial_test_data.data_partner_g')
  15. account_a_receivable = env['account.account'].search(
  16. [('code', '=', '411700')]
  17. )
  18. account_receivable = env['account.account'].search(
  19. [('code', '=', '411100')]
  20. )
  21. account_payable = env['account.account'].search(
  22. [('code', '=', '401100')]
  23. )
  24. partner_a.property_account_receivable_id = account_a_receivable[0]
  25. partner_a.property_account_payable_id = account_payable[0]
  26. partners_list = [
  27. partner_b,
  28. partner_c,
  29. partner_d,
  30. partner_e,
  31. partner_f,
  32. partner_g
  33. ]
  34. for partner in partners_list:
  35. partner.property_account_receivable_id = account_receivable[0]
  36. partner.property_account_payable_id = account_payable[0]
  37. return True
  38. def update_account_settings():
  39. """
  40. Configure account settings
  41. """
  42. account_setting_obj = env['account.config.settings']
  43. account_setting = account_setting_obj.create({})
  44. account_setting.group_multi_currency = True
  45. account_setting.default_sale_tax_id = env.ref('l10n_fr.tva_normale').id
  46. account_setting.default_purchase_tax_id = env.ref('l10n_fr.tva_normale').id
  47. account_setting.execute()
  48. return True
  49. def update_account():
  50. """
  51. Change the name and currency of 411700
  52. """
  53. account_to_update = env['account.account'].search(
  54. [('code', '=', '411700')]
  55. )[0]
  56. account_to_update.name = "Clients - USD"
  57. account_to_update.currency_id = env.ref('base.USD').id
  58. return True
  59. def update_product():
  60. """
  61. Update the product with the right settings
  62. """
  63. product = env.ref('account_financial_test_data.data_product_a')
  64. product.standard_price = 1000
  65. product.lst_price = 1000
  66. product.taxes_id = [
  67. (6, 0, [env.ref('l10n_fr.tva_normale').id])
  68. ]
  69. product.supplier_taxes_id = [
  70. (6, 0, [env.ref('l10n_fr.tva_acq_normale_TTC').id])
  71. ]
  72. income_account = env['account.account'].search([
  73. ('code', '=', '707100')
  74. ])[0]
  75. expense_account = env['account.account'].search([
  76. ('code', '=', '607100')
  77. ])[0]
  78. product.property_account_income_id = income_account
  79. product.property_account_expense_id = expense_account
  80. return True
  81. def create_invoices():
  82. invoice_obj = env['account.invoice']
  83. invoice_line_obj = env['account.invoice.line']
  84. invoice_line_values = {
  85. }
  86. invoice_values = {
  87. 'partner_id': env.ref(
  88. 'account_financial_test_data.data_partner_c').id,
  89. 'date_invoice': '05/01/2015',
  90. 'user_id': env.ref('base.user_root').id,
  91. 'currency_id': env.ref('base.EUR').id,
  92. 'invoice_line_ids': [],
  93. }
  94. return True
  95. env = api.Environment(cr, SUPERUSER_ID, {})
  96. update_partners()
  97. update_account_settings()
  98. update_account()
  99. update_product()
  100. # create_invoices()