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.

71 lines
2.7 KiB

  1. # Copyright 2019 Tecnativa - Vicent Cubells <vicent.cubells@tecnativa.com>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from dateutil.relativedelta import relativedelta
  4. from odoo.tests import common
  5. from odoo import fields
  6. class TestContractPriceRevision(common.SavepointCase):
  7. @classmethod
  8. def setUpClass(cls):
  9. super(TestContractPriceRevision, cls).setUpClass()
  10. partner = cls.env['res.partner'].create({
  11. 'name': 'Partner test',
  12. })
  13. product = cls.env['product.product'].create({
  14. 'name': 'Test Product',
  15. })
  16. cls.contract = cls.env['account.analytic.account'].create({
  17. 'name': 'Contract test',
  18. 'partner_id': partner.id,
  19. 'date_start': fields.Date.today(),
  20. 'recurring_next_date': fields.Date.to_string(
  21. fields.date.today() + relativedelta(days=7)),
  22. 'recurring_rule_type': 'monthly',
  23. 'recurring_invoice_line_ids': [(0, 0, {
  24. 'product_id': product.id,
  25. 'quantity': 1.0,
  26. 'uom_id': product.uom_id.id,
  27. 'name': product.name,
  28. 'price_unit': 33.0,
  29. 'automatic_price': True,
  30. }), (0, 0, {
  31. 'product_id': product.id,
  32. 'quantity': 1.0,
  33. 'uom_id': product.uom_id.id,
  34. 'name': product.name,
  35. 'price_unit': 25.0,
  36. 'automatic_price': False,
  37. })]
  38. })
  39. def execute_wizard(self):
  40. wizard = self.env['create.revision.line.wizard'].create({
  41. 'date_start': fields.Date.today(),
  42. 'date_end': fields.Date.to_string(
  43. fields.date.today() + relativedelta(years=1)),
  44. 'variation_percent': 100.0,
  45. })
  46. wizard.with_context(
  47. {'active_ids': [self.contract.id]}).action_apply()
  48. def test_contract_price_revision_wizard(self):
  49. self.assertEqual(len(self.contract.recurring_invoice_line_ids.ids), 2)
  50. self.execute_wizard()
  51. self.assertEqual(len(self.contract.recurring_invoice_line_ids.ids), 3)
  52. lines = self.contract.mapped('recurring_invoice_line_ids').filtered(
  53. lambda x: x.price_unit == 50.0)
  54. self.assertEqual(len(lines), 1)
  55. def test_contract_price_revision_invoicing(self):
  56. self.execute_wizard()
  57. self.contract.recurring_create_invoice()
  58. invoices = self.env['account.invoice'].search([
  59. ('contract_id', '=', self.contract.id)])
  60. self.assertEqual(len(invoices), 1)
  61. lines = invoices.mapped('invoice_line_ids')
  62. self.assertEqual(len(lines), 2)
  63. lines = lines.filtered(lambda x: x.price_unit == 50.0)
  64. self.assertEqual(len(lines), 1)