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.

76 lines
3.4 KiB

5 years ago
  1. # Copyright 2018 Tecnativa - Carlos Dauden
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. from odoo.addons.contract.tests.test_contract import TestContractBase
  4. class TestContractSaleInvoicing(TestContractBase):
  5. @classmethod
  6. def setUpClass(cls):
  7. super(TestContractSaleInvoicing, cls).setUpClass()
  8. cls.contract.group_id = \
  9. cls.env['account.analytic.account'].search([], limit=1)
  10. cls.product_so = cls.env.ref(
  11. 'product.product_product_1')
  12. cls.product_so.invoice_policy = 'order'
  13. cls.sale_order = cls.env['sale.order'].create({
  14. 'partner_id': cls.partner.id,
  15. 'partner_invoice_id': cls.partner.id,
  16. 'partner_shipping_id': cls.partner.id,
  17. 'order_line': [(0, 0, {'name': cls.product_so.name,
  18. 'product_id': cls.product_so.id,
  19. 'product_uom_qty': 2,
  20. 'product_uom': cls.product_so.uom_id.id,
  21. 'price_unit': cls.product_so.list_price})],
  22. 'pricelist_id': cls.partner.property_product_pricelist.id,
  23. 'analytic_account_id': cls.contract.group_id.id,
  24. 'date_order': '2016-02-15',
  25. })
  26. def test_not_sale_invoicing(self):
  27. self.contract.invoicing_sales = False
  28. self.sale_order.action_confirm()
  29. self.contract.recurring_create_invoice()
  30. self.assertEqual(self.sale_order.invoice_status, 'to invoice')
  31. def test_sale_invoicing(self):
  32. self.contract.invoicing_sales = True
  33. self.sale_order.action_confirm()
  34. self.contract.recurring_create_invoice()
  35. self.assertEqual(self.sale_order.invoice_status, 'invoiced')
  36. def test_contract_sale_invoicing_without(self):
  37. self.contract.invoicing_sales = True
  38. self.sale_order.analytic_account_id = False
  39. self.sale_order.action_confirm()
  40. self.contract.recurring_create_invoice()
  41. self.assertEqual(self.sale_order.invoice_status, 'to invoice')
  42. def test_contract_sale_invoicing(self):
  43. contract_copy = self.contract.copy({
  44. 'filter_with': 'contract',
  45. 'group_by': 'contract',
  46. 'invoicing_sales': True
  47. })
  48. so_val = {
  49. 'date_order': '2016-02-15',
  50. 'contract_id': contract_copy.id
  51. }
  52. sale_order_copy1 = self.sale_order.copy(so_val)
  53. sale_order_copy2 = self.sale_order.copy(so_val)
  54. sale_order_copy1.action_confirm()
  55. sale_order_copy2.action_confirm()
  56. self.env['contract.contract'].cron_recurring_create_invoice()
  57. contract_line_list = [contract_copy.contract_line_ids.id,
  58. self.contract.contract_line_ids.id]
  59. invoice_line = self.env['account.invoice.line'].search([
  60. ('contract_line_id', 'in', contract_line_list)], order='id asc')
  61. self.assertEqual(invoice_line[0].quantity, 1)
  62. self.assertEqual(invoice_line[0].product_id,
  63. sale_order_copy1.order_line.product_id)
  64. self.assertEqual(invoice_line[1].quantity, 1)
  65. self.assertEqual(invoice_line[1].product_id,
  66. sale_order_copy1.order_line.product_id)
  67. self.assertEqual(invoice_line[2].quantity, 3)
  68. self.assertEqual(invoice_line[2].product_id,
  69. sale_order_copy1.order_line.product_id)