test_so_expense_purchase_price.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo.addons.hr_expense.tests.common import TestExpenseCommon
  4. from odoo.tests import tagged
  5. @tagged('-at_install', 'post_install')
  6. class TestExpenseMargin(TestExpenseCommon):
  7. def test_expense_reinvoice_purchase_price(self):
  8. # re-invoiceable products
  9. product_with_cost = self.product_a
  10. product_with_cost.write({'standard_price': 1000, 'expense_policy': 'sales_price'})
  11. product_with_no_cost = self.product_b
  12. product_with_no_cost.write({'standard_price': 0, 'expense_policy': 'sales_price'})
  13. # create SO line and confirm SO (with only one line)
  14. sale_order = self.env['sale.order'].with_context(mail_notrack=True, mail_create_nolog=True).create({
  15. 'partner_id': self.partner_a.id,
  16. 'partner_invoice_id': self.partner_a.id,
  17. 'partner_shipping_id': self.partner_a.id,
  18. 'order_line': [(0, 0, {
  19. 'name': product_with_cost.name,
  20. 'product_id': product_with_cost.id,
  21. 'product_uom_qty': 2.0,
  22. 'price_unit': 13.0,
  23. })],
  24. })
  25. sale_order.action_confirm()
  26. expense_sheet = self.env['hr.expense.sheet'].create({
  27. 'name': 'First Expense for employee',
  28. 'employee_id': self.expense_employee.id,
  29. 'journal_id': self.company_data['default_journal_purchase'].id,
  30. 'accounting_date': '2020-10-12',
  31. 'expense_line_ids': [
  32. # expense with zero cost product, with 15% tax
  33. (0, 0, {
  34. 'name': 'expense_1',
  35. 'date': '2020-10-07',
  36. 'product_id': product_with_no_cost.id,
  37. 'unit_amount': product_with_no_cost.standard_price,
  38. 'total_amount': 100,
  39. 'tax_ids': [(6, 0, self.company_data['default_tax_purchase'].ids)],
  40. 'employee_id': self.expense_employee.id,
  41. 'sale_order_id': sale_order.id,
  42. }),
  43. # expense with zero cost product, with no tax
  44. (0, 0, {
  45. 'name': 'expense_2',
  46. 'date': '2020-10-07',
  47. 'product_id': product_with_no_cost.id,
  48. 'unit_amount': product_with_no_cost.standard_price,
  49. 'total_amount': 100,
  50. 'tax_ids': False,
  51. 'employee_id': self.expense_employee.id,
  52. 'sale_order_id': sale_order.id
  53. }),
  54. # expense with product with cost (1000), with 15% tax
  55. (0, 0, {
  56. 'name': 'expense_3',
  57. 'date': '2020-10-07',
  58. 'product_id': product_with_cost.id,
  59. 'quantity': 3,
  60. 'unit_amount': product_with_cost.standard_price,
  61. 'tax_ids': [(6, 0, self.company_data['default_tax_purchase'].ids)],
  62. 'employee_id': self.expense_employee.id,
  63. 'sale_order_id': sale_order.id
  64. }),
  65. # expense with product with cost (1000), with no tax
  66. (0, 0, {
  67. 'name': 'expense_4',
  68. 'date': '2020-10-07',
  69. 'product_id': product_with_cost.id,
  70. 'quantity': 5,
  71. 'unit_amount': product_with_cost.standard_price,
  72. 'tax_ids': False,
  73. 'employee_id': self.expense_employee.id,
  74. 'sale_order_id': sale_order.id
  75. }),
  76. ],
  77. })
  78. expense_sheet.approve_expense_sheets()
  79. expense_sheet.action_sheet_move_create()
  80. self.assertRecordValues(sale_order.order_line[1:], [
  81. # Expense lines:
  82. {
  83. 'purchase_price': 86.96,
  84. 'is_expense': True,
  85. },
  86. {
  87. 'purchase_price': 100.0,
  88. 'is_expense': True,
  89. },
  90. {
  91. 'purchase_price': 869.57,
  92. 'is_expense': True,
  93. },
  94. {
  95. 'purchase_price': 1000.0,
  96. 'is_expense': True,
  97. },
  98. ])