odoo-addon-contract 17.0.1.4.5.1__py3-none-any.whl → 18.0.2.0.0.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. odoo/addons/contract/README.rst +14 -10
  2. odoo/addons/contract/__manifest__.py +3 -10
  3. odoo/addons/contract/controllers/main.py +1 -8
  4. odoo/addons/contract/data/contract_cron.xml +0 -2
  5. odoo/addons/contract/data/mail_template.xml +18 -17
  6. odoo/addons/contract/data/template_mail_notification.xml +1 -1
  7. odoo/addons/contract/i18n/contract.pot +141 -823
  8. odoo/addons/contract/migrations/18.0.2.0.0/pre-migrate.py +92 -0
  9. odoo/addons/contract/models/__init__.py +2 -6
  10. odoo/addons/contract/models/account_move.py +0 -8
  11. odoo/addons/contract/models/account_move_line.py +14 -0
  12. odoo/addons/contract/models/contract.py +266 -308
  13. odoo/addons/contract/models/contract_line.py +34 -861
  14. odoo/addons/contract/models/{contract_recurrency_mixin.py → contract_recurring_mixin.py} +101 -82
  15. odoo/addons/contract/models/contract_tag.py +1 -3
  16. odoo/addons/contract/models/contract_template.py +81 -2
  17. odoo/addons/contract/models/contract_template_line.py +249 -3
  18. odoo/addons/contract/report/contract_views.xml +0 -2
  19. odoo/addons/contract/report/report_contract.xml +13 -13
  20. odoo/addons/contract/security/contract_security.xml +6 -15
  21. odoo/addons/contract/security/contract_tag.xml +1 -3
  22. odoo/addons/contract/security/ir.model.access.csv +0 -2
  23. odoo/addons/contract/static/description/index.html +24 -18
  24. odoo/addons/contract/static/src/js/contract_portal_tour.esm.js +6 -3
  25. odoo/addons/contract/tests/test_contract.py +42 -927
  26. odoo/addons/contract/tests/test_multicompany.py +5 -4
  27. odoo/addons/contract/tests/test_portal.py +6 -3
  28. odoo/addons/contract/views/contract.xml +91 -234
  29. odoo/addons/contract/views/contract_line.xml +48 -117
  30. odoo/addons/contract/views/contract_portal_templates.xml +181 -222
  31. odoo/addons/contract/views/contract_tag.xml +3 -3
  32. odoo/addons/contract/views/contract_template.xml +100 -72
  33. odoo/addons/contract/views/contract_template_line.xml +76 -5
  34. odoo/addons/contract/views/res_config_settings.xml +5 -6
  35. odoo/addons/contract/views/res_partner_view.xml +0 -5
  36. odoo/addons/contract/wizards/__init__.py +0 -2
  37. odoo/addons/contract/wizards/contract_manually_create_invoice.py +6 -6
  38. odoo/addons/contract/wizards/contract_manually_create_invoice.xml +2 -3
  39. {odoo_addon_contract-17.0.1.4.5.1.dist-info → odoo_addon_contract-18.0.2.0.0.9.dist-info}/METADATA +17 -13
  40. {odoo_addon_contract-17.0.1.4.5.1.dist-info → odoo_addon_contract-18.0.2.0.0.9.dist-info}/RECORD +42 -55
  41. odoo/addons/contract/data/contract_renew_cron.xml +0 -14
  42. odoo/addons/contract/models/abstract_contract.py +0 -82
  43. odoo/addons/contract/models/abstract_contract_line.py +0 -271
  44. odoo/addons/contract/models/contract_line_constraints.py +0 -429
  45. odoo/addons/contract/models/contract_terminate_reason.py +0 -14
  46. odoo/addons/contract/models/res_company.py +0 -15
  47. odoo/addons/contract/models/res_config_settings.py +0 -18
  48. odoo/addons/contract/security/contract_terminate_reason.xml +0 -23
  49. odoo/addons/contract/security/groups.xml +0 -9
  50. odoo/addons/contract/views/abstract_contract_line.xml +0 -117
  51. odoo/addons/contract/views/contract_terminate_reason.xml +0 -38
  52. odoo/addons/contract/wizards/contract_contract_terminate.py +0 -42
  53. odoo/addons/contract/wizards/contract_contract_terminate.xml +0 -33
  54. odoo/addons/contract/wizards/contract_line_wizard.py +0 -53
  55. odoo/addons/contract/wizards/contract_line_wizard.xml +0 -111
  56. {odoo_addon_contract-17.0.1.4.5.1.dist-info → odoo_addon_contract-18.0.2.0.0.9.dist-info}/WHEEL +0 -0
  57. {odoo_addon_contract-17.0.1.4.5.1.dist-info → odoo_addon_contract-18.0.2.0.0.9.dist-info}/top_level.txt +0 -0
@@ -5,13 +5,12 @@
5
5
 
6
6
  import logging
7
7
  from collections import namedtuple
8
- from datetime import timedelta
9
8
 
10
9
  from dateutil.relativedelta import relativedelta
11
10
  from freezegun import freeze_time
12
11
 
13
- from odoo import fields
14
- from odoo.exceptions import UserError, ValidationError
12
+ from odoo import Command, fields
13
+ from odoo.exceptions import ValidationError
15
14
  from odoo.tests import Form, common
16
15
 
17
16
 
@@ -57,8 +56,8 @@ class TestContractBase(common.TransactionCase):
57
56
  cls.template_vals = {
58
57
  "name": "Test Contract Template",
59
58
  "contract_line_ids": [
60
- (0, 0, cls.section_template_vals),
61
- (0, 0, cls.line_template_vals),
59
+ Command.create(cls.section_template_vals),
60
+ Command.create(cls.line_template_vals),
62
61
  ],
63
62
  }
64
63
  cls.template = cls.env["contract.template"].create(cls.template_vals)
@@ -87,9 +86,7 @@ class TestContractBase(common.TransactionCase):
87
86
  "line_recurrence": True,
88
87
  "contract_type": "purchase",
89
88
  "contract_line_ids": [
90
- (
91
- 0,
92
- 0,
89
+ Command.create(
93
90
  {
94
91
  "product_id": cls.product_1.id,
95
92
  "name": "Services from #START# to #END#",
@@ -118,14 +115,8 @@ class TestContractBase(common.TransactionCase):
118
115
  "recurring_interval": 1,
119
116
  "date_start": "2018-01-01",
120
117
  "recurring_next_date": "2018-01-15",
121
- "is_auto_renew": False,
122
118
  }
123
119
  cls.acct_line = cls.env["contract.line"].create(cls.line_vals)
124
- cls.contract.company_id.create_new_line_at_contract_line_renew = True
125
- cls.terminate_reason = cls.env["contract.terminate.reason"].create(
126
- {"name": "terminate_reason"}
127
- )
128
-
129
120
  cls.contract3 = cls.env["contract.contract"].create(
130
121
  {
131
122
  "name": "Test Contract 3",
@@ -137,18 +128,14 @@ class TestContractBase(common.TransactionCase):
137
128
  "recurring_rule_type": "monthly",
138
129
  "date_start": "2018-02-15",
139
130
  "contract_line_ids": [
140
- (
141
- 0,
142
- 0,
131
+ Command.create(
143
132
  {
144
133
  "product_id": False,
145
134
  "name": "Header for #INVOICEMONTHNAME# Services",
146
135
  "display_type": "line_section",
147
136
  },
148
137
  ),
149
- (
150
- 0,
151
- 0,
138
+ Command.create(
152
139
  {
153
140
  "product_id": False,
154
141
  "name": "Services from #START# to #END#",
@@ -156,9 +143,7 @@ class TestContractBase(common.TransactionCase):
156
143
  "price_unit": 100,
157
144
  },
158
145
  ),
159
- (
160
- 0,
161
- 0,
146
+ Command.create(
162
147
  {
163
148
  "product_id": False,
164
149
  "name": "Line",
@@ -221,8 +206,12 @@ class TestContract(TestContractBase):
221
206
  self.contract.write(
222
207
  {
223
208
  "modification_ids": [
224
- (0, 0, {"date": "2020-01-01", "description": "Modification 1"}),
225
- (0, 0, {"date": "2020-02-01", "description": "Modification 2"}),
209
+ Command.create(
210
+ {"date": "2020-01-01", "description": "Modification 1"}
211
+ ),
212
+ Command.create(
213
+ {"date": "2020-02-01", "description": "Modification 2"}
214
+ ),
226
215
  ]
227
216
  }
228
217
  )
@@ -251,6 +240,14 @@ class TestContract(TestContractBase):
251
240
  self.acct_line.invalidate_model()
252
241
  self.assertEqual(self.acct_line.price_unit, 10)
253
242
 
243
+ def test_automatic_price_change(self):
244
+ self.acct_line.automatic_price = True
245
+ self.product_1.list_price = 1100
246
+ self.assertEqual(self.acct_line.price_unit, 1100)
247
+ # Change contract type
248
+ self.acct_line.contract_id.contract_type = "purchase"
249
+ self.assertFalse(self.acct_line.automatic_price)
250
+
254
251
  def test_contract(self):
255
252
  self.assertEqual(self.contract.recurring_next_date, to_date("2018-01-15"))
256
253
  self.assertAlmostEqual(self.acct_line.price_subtotal, 50.0)
@@ -272,9 +269,9 @@ class TestContract(TestContractBase):
272
269
  def test_contract_daily(self):
273
270
  recurring_next_date = to_date("2018-02-23")
274
271
  last_date_invoiced = to_date("2018-02-22")
275
- self.acct_line.recurring_next_date = "2018-02-22"
276
272
  self.acct_line.recurring_rule_type = "daily"
277
273
  self.contract.pricelist_id = False
274
+ self.acct_line.recurring_next_date = "2018-02-22"
278
275
  self.contract.recurring_create_invoice()
279
276
  invoice_daily = self.contract._get_related_invoices()
280
277
  self.assertTrue(invoice_daily)
@@ -315,9 +312,9 @@ class TestContract(TestContractBase):
315
312
  def test_contract_weekly_post_paid(self):
316
313
  recurring_next_date = to_date("2018-03-01")
317
314
  last_date_invoiced = to_date("2018-02-21")
318
- self.acct_line.recurring_next_date = "2018-02-22"
319
315
  self.acct_line.recurring_rule_type = "weekly"
320
316
  self.acct_line.recurring_invoicing_type = "post-paid"
317
+ self.acct_line.recurring_next_date = "2018-02-22"
321
318
  self.contract.recurring_create_invoice()
322
319
  invoices_weekly = self.contract._get_related_invoices()
323
320
  self.assertTrue(invoices_weekly)
@@ -327,9 +324,9 @@ class TestContract(TestContractBase):
327
324
  def test_contract_weekly_pre_paid(self):
328
325
  recurring_next_date = to_date("2018-03-01")
329
326
  last_date_invoiced = to_date("2018-02-28")
330
- self.acct_line.recurring_next_date = "2018-02-22"
331
327
  self.acct_line.recurring_rule_type = "weekly"
332
328
  self.acct_line.recurring_invoicing_type = "pre-paid"
329
+ self.acct_line.recurring_next_date = "2018-02-22"
333
330
  self.contract.recurring_create_invoice()
334
331
  invoices_weekly = self.contract._get_related_invoices()
335
332
  self.assertTrue(invoices_weekly)
@@ -339,9 +336,9 @@ class TestContract(TestContractBase):
339
336
  def test_contract_yearly_post_paid(self):
340
337
  recurring_next_date = to_date("2019-02-22")
341
338
  last_date_invoiced = to_date("2018-02-21")
342
- self.acct_line.recurring_next_date = "2018-02-22"
343
339
  self.acct_line.recurring_rule_type = "yearly"
344
340
  self.acct_line.recurring_invoicing_type = "post-paid"
341
+ self.acct_line.recurring_next_date = "2018-02-22"
345
342
  self.contract.recurring_create_invoice()
346
343
  invoices_weekly = self.contract._get_related_invoices()
347
344
  self.assertTrue(invoices_weekly)
@@ -352,9 +349,9 @@ class TestContract(TestContractBase):
352
349
  recurring_next_date = to_date("2019-02-22")
353
350
  last_date_invoiced = to_date("2019-02-21")
354
351
  self.acct_line.date_end = "2020-02-22"
355
- self.acct_line.recurring_next_date = "2018-02-22"
356
352
  self.acct_line.recurring_rule_type = "yearly"
357
353
  self.acct_line.recurring_invoicing_type = "pre-paid"
354
+ self.acct_line.recurring_next_date = "2018-02-22"
358
355
  self.contract.recurring_create_invoice()
359
356
  invoices_weekly = self.contract._get_related_invoices()
360
357
  self.assertTrue(invoices_weekly)
@@ -364,9 +361,9 @@ class TestContract(TestContractBase):
364
361
  def test_contract_monthly_lastday(self):
365
362
  recurring_next_date = to_date("2018-02-28")
366
363
  last_date_invoiced = to_date("2018-02-22")
367
- self.acct_line.recurring_next_date = "2018-02-22"
368
364
  self.acct_line.recurring_invoicing_type = "post-paid"
369
365
  self.acct_line.recurring_rule_type = "monthlylastday"
366
+ self.acct_line.recurring_next_date = "2018-02-22"
370
367
  self.contract.recurring_create_invoice()
371
368
  invoices_monthly_lastday = self.contract._get_related_invoices()
372
369
  self.assertTrue(invoices_monthly_lastday)
@@ -377,9 +374,9 @@ class TestContract(TestContractBase):
377
374
  recurring_next_date = to_date("2018-05-22")
378
375
  last_date_invoiced = to_date("2018-05-21")
379
376
  self.acct_line.date_end = "2020-02-22"
380
- self.acct_line.recurring_next_date = "2018-02-22"
381
377
  self.acct_line.recurring_rule_type = "quarterly"
382
378
  self.acct_line.recurring_invoicing_type = "pre-paid"
379
+ self.acct_line.recurring_next_date = "2018-02-22"
383
380
  self.contract.recurring_create_invoice()
384
381
  invoices_weekly = self.contract._get_related_invoices()
385
382
  self.assertTrue(invoices_weekly)
@@ -390,9 +387,9 @@ class TestContract(TestContractBase):
390
387
  recurring_next_date = to_date("2018-05-22")
391
388
  last_date_invoiced = to_date("2018-02-21")
392
389
  self.acct_line.date_end = "2020-02-22"
393
- self.acct_line.recurring_next_date = "2018-02-22"
394
390
  self.acct_line.recurring_rule_type = "quarterly"
395
391
  self.acct_line.recurring_invoicing_type = "post-paid"
392
+ self.acct_line.recurring_next_date = "2018-02-22"
396
393
  self.contract.recurring_create_invoice()
397
394
  invoices_weekly = self.contract._get_related_invoices()
398
395
  self.assertTrue(invoices_weekly)
@@ -403,9 +400,9 @@ class TestContract(TestContractBase):
403
400
  recurring_next_date = to_date("2018-08-22")
404
401
  last_date_invoiced = to_date("2018-08-21")
405
402
  self.acct_line.date_end = "2020-02-22"
406
- self.acct_line.recurring_next_date = "2018-02-22"
407
403
  self.acct_line.recurring_rule_type = "semesterly"
408
404
  self.acct_line.recurring_invoicing_type = "pre-paid"
405
+ self.acct_line.recurring_next_date = "2018-02-22"
409
406
  self.contract.recurring_create_invoice()
410
407
  invoices_weekly = self.contract._get_related_invoices()
411
408
  self.assertTrue(invoices_weekly)
@@ -416,9 +413,9 @@ class TestContract(TestContractBase):
416
413
  recurring_next_date = to_date("2018-08-22")
417
414
  last_date_invoiced = to_date("2018-02-21")
418
415
  self.acct_line.date_end = "2020-02-22"
419
- self.acct_line.recurring_next_date = "2018-02-22"
420
416
  self.acct_line.recurring_rule_type = "semesterly"
421
417
  self.acct_line.recurring_invoicing_type = "post-paid"
418
+ self.acct_line.recurring_next_date = "2018-02-22"
422
419
  self.contract.recurring_create_invoice()
423
420
  invoices_weekly = self.contract._get_related_invoices()
424
421
  self.assertTrue(invoices_weekly)
@@ -487,7 +484,9 @@ class TestContract(TestContractBase):
487
484
  def test_uom(self):
488
485
  uom_litre = self.env.ref("uom.product_uom_litre")
489
486
  self.acct_line.uom_id = uom_litre.id
490
- self.acct_line._onchange_product_id()
487
+ product = self.acct_line.product_id
488
+ self.acct_line.product_id = False
489
+ self.acct_line.product_id = product
491
490
  self.assertEqual(self.acct_line.uom_id, self.acct_line.product_id.uom_id)
492
491
 
493
492
  def test_no_pricelist(self):
@@ -519,10 +518,10 @@ class TestContract(TestContractBase):
519
518
  self.contract._onchange_contract_template_id()
520
519
  res = {
521
520
  "contract_line_ids": [
522
- (0, 0, {"display_type": "line_section", "name": "Test section"}),
523
- (
524
- 0,
525
- 0,
521
+ Command.create(
522
+ {"display_type": "line_section", "name": "Test section"}
523
+ ),
524
+ Command.create(
526
525
  {
527
526
  "product_id": self.product_1.id,
528
527
  "name": "Services from #START# to #END#",
@@ -541,7 +540,6 @@ class TestContract(TestContractBase):
541
540
 
542
541
  def test_onchange_contract_template_id_lines(self):
543
542
  """It should create invoice lines for the contract lines."""
544
- self.acct_line.cancel()
545
543
  self.acct_line.unlink()
546
544
  self.contract.contract_template_id = self.template
547
545
 
@@ -576,28 +574,11 @@ class TestContract(TestContractBase):
576
574
  result = self.contract.action_contract_send()
577
575
  self.assertEqual(result["res_model"], "mail.compose.message")
578
576
 
579
- def test_onchange_contract_type(self):
580
- self.contract._onchange_contract_type()
581
- self.assertEqual(self.contract.journal_id.type, "sale")
582
- self.assertEqual(self.contract.journal_id.company_id, self.contract.company_id)
583
- self.contract.contract_type = "purchase"
584
- self.contract._onchange_contract_type()
585
- self.assertFalse(any(self.contract.contract_line_ids.mapped("automatic_price")))
586
-
587
- def test_contract_onchange_product_id_uom(self):
588
- """It should update the UoM for the line."""
589
- line = self._add_template_line(
590
- {"uom_id": self.env.ref("uom.product_uom_litre").id}
591
- )
592
- line.product_id.uom_id = self.env.ref("uom.product_uom_day").id
593
- line._onchange_product_id()
594
- self.assertEqual(line.uom_id, line.product_id.uom_id)
595
-
596
577
  def test_contract_onchange_product_id_name(self):
597
578
  """It should update the name for the line."""
598
579
  line = self._add_template_line()
599
- line.product_id.description_sale = "Test"
600
- line._onchange_product_id()
580
+ self.product_2.description_sale = "Test Name Change"
581
+ line.product_id = self.product_2
601
582
  self.assertEqual(
602
583
  line.name, line.product_id.get_product_multiline_description_sale()
603
584
  )
@@ -1096,629 +1077,6 @@ class TestContract(TestContractBase):
1096
1077
  min(self.contract.contract_line_ids.mapped("recurring_next_date")),
1097
1078
  )
1098
1079
 
1099
- def test_date_end(self):
1100
- """recurring next date for a contract is the min for all lines"""
1101
- self.acct_line.date_end = "2018-01-01"
1102
- self.acct_line.copy()
1103
- self.acct_line.write({"date_end": False, "is_auto_renew": False})
1104
- self.assertFalse(self.contract.date_end)
1105
-
1106
- def test_cancel_contract_line(self):
1107
- """It should raise a validation error"""
1108
- self.acct_line.cancel()
1109
- with self.assertRaises(ValidationError):
1110
- self.acct_line.stop(self.today)
1111
-
1112
- def test_stop_contract_line(self):
1113
- """It should put end to the contract line"""
1114
- self.acct_line.write(
1115
- {
1116
- "date_start": self.today,
1117
- "recurring_next_date": self.today,
1118
- "date_end": self.today + relativedelta(months=7),
1119
- "is_auto_renew": True,
1120
- }
1121
- )
1122
- self.acct_line.stop(self.today + relativedelta(months=5))
1123
- self.assertEqual(self.acct_line.date_end, self.today + relativedelta(months=5))
1124
-
1125
- def test_stop_upcoming_contract_line(self):
1126
- """It should put end to the contract line"""
1127
- self.acct_line.write(
1128
- {
1129
- "date_start": self.today + relativedelta(months=3),
1130
- "recurring_next_date": self.today + relativedelta(months=3),
1131
- "date_end": self.today + relativedelta(months=7),
1132
- "is_auto_renew": True,
1133
- }
1134
- )
1135
- self.acct_line.stop(self.today)
1136
- self.assertEqual(self.acct_line.date_end, self.today + relativedelta(months=7))
1137
- self.assertTrue(self.acct_line.is_canceled)
1138
-
1139
- def test_stop_past_contract_line(self):
1140
- """Past contract line are ignored on stop"""
1141
- self.acct_line.write(
1142
- {"date_end": self.today + relativedelta(months=5), "is_auto_renew": True}
1143
- )
1144
- self.acct_line.stop(self.today + relativedelta(months=7))
1145
- self.assertEqual(self.acct_line.date_end, self.today + relativedelta(months=5))
1146
-
1147
- def test_stop_contract_line_without_date_end(self):
1148
- """Past contract line are ignored on stop"""
1149
- self.acct_line.write({"date_end": False, "is_auto_renew": False})
1150
- self.acct_line.stop(self.today + relativedelta(months=7))
1151
- self.assertEqual(self.acct_line.date_end, self.today + relativedelta(months=7))
1152
-
1153
- def test_stop_wizard(self):
1154
- self.acct_line.write(
1155
- {
1156
- "date_start": self.today,
1157
- "recurring_next_date": self.today,
1158
- "date_end": self.today + relativedelta(months=5),
1159
- "is_auto_renew": True,
1160
- }
1161
- )
1162
- wizard = self.env["contract.line.wizard"].create(
1163
- {
1164
- "date_end": self.today + relativedelta(months=3),
1165
- "contract_line_id": self.acct_line.id,
1166
- }
1167
- )
1168
- wizard.stop()
1169
- self.assertEqual(self.acct_line.date_end, self.today + relativedelta(months=3))
1170
- self.assertFalse(self.acct_line.is_auto_renew)
1171
-
1172
- def test_stop_plan_successor_contract_line_0(self):
1173
- successor_contract_line = self.acct_line.copy(
1174
- {
1175
- "date_start": self.today + relativedelta(months=5),
1176
- "recurring_next_date": self.today + relativedelta(months=5),
1177
- }
1178
- )
1179
- self.acct_line.write(
1180
- {
1181
- "successor_contract_line_id": successor_contract_line.id,
1182
- "is_auto_renew": False,
1183
- "date_end": self.today,
1184
- }
1185
- )
1186
- suspension_start = self.today + relativedelta(months=5)
1187
- suspension_end = self.today + relativedelta(months=6)
1188
- with self.assertRaises(ValidationError):
1189
- self.acct_line.stop_plan_successor(suspension_start, suspension_end, True)
1190
-
1191
- def test_stop_plan_successor_contract_line_1(self):
1192
- """
1193
- * contract line end's before the suspension period:
1194
- -> apply stop
1195
- """
1196
- suspension_start = self.today + relativedelta(months=5)
1197
- suspension_end = self.today + relativedelta(months=6)
1198
- start_date = self.today
1199
- end_date = self.today + relativedelta(months=4)
1200
- self.acct_line.write(
1201
- {
1202
- "date_start": start_date,
1203
- "recurring_next_date": start_date,
1204
- "date_end": end_date,
1205
- }
1206
- )
1207
- self.acct_line.stop_plan_successor(suspension_start, suspension_end, True)
1208
- self.assertEqual(self.acct_line.date_end, end_date)
1209
- new_line = self.env["contract.line"].search(
1210
- [("predecessor_contract_line_id", "=", self.acct_line.id)]
1211
- )
1212
- self.assertFalse(new_line)
1213
-
1214
- def test_stop_plan_successor_contract_line_2(self):
1215
- """
1216
- * contract line start before the suspension period and end in it
1217
- -> apply stop at suspension start date
1218
- -> apply plan successor:
1219
- - date_start: suspension.date_end
1220
- - date_end: suspension.date_end + (contract_line.date_end
1221
- - suspension.date_start)
1222
- """
1223
- suspension_start = self.today + relativedelta(months=3)
1224
- suspension_end = self.today + relativedelta(months=5)
1225
- start_date = self.today
1226
- end_date = self.today + relativedelta(months=4)
1227
- self.acct_line.write(
1228
- {
1229
- "date_start": start_date,
1230
- "recurring_next_date": start_date,
1231
- "date_end": end_date,
1232
- }
1233
- )
1234
- self.acct_line.stop_plan_successor(suspension_start, suspension_end, True)
1235
- self.assertEqual(
1236
- self.acct_line.date_end, suspension_start - relativedelta(days=1)
1237
- )
1238
- new_line = self.env["contract.line"].search(
1239
- [("predecessor_contract_line_id", "=", self.acct_line.id)]
1240
- )
1241
- self.assertTrue(new_line)
1242
- new_date_end = (
1243
- suspension_end + (end_date - suspension_start) + relativedelta(days=1)
1244
- )
1245
- self.assertEqual(new_line.date_start, suspension_end + relativedelta(days=1))
1246
- self.assertEqual(new_line.date_end, new_date_end)
1247
- self.assertTrue(self.acct_line.manual_renew_needed)
1248
-
1249
- def test_stop_plan_successor_contract_line_3(self):
1250
- """
1251
- * contract line start before the suspension period and end after it
1252
- -> apply stop at suspension start date
1253
- -> apply plan successor:
1254
- - date_start: suspension.date_end
1255
- - date_end: suspension.date_end + (suspension.date_end
1256
- - suspension.date_start)
1257
- """
1258
- suspension_start = self.today + relativedelta(months=3)
1259
- suspension_end = self.today + relativedelta(months=5)
1260
- start_date = self.today
1261
- end_date = self.today + relativedelta(months=6)
1262
- self.acct_line.write(
1263
- {
1264
- "date_start": start_date,
1265
- "recurring_next_date": start_date,
1266
- "date_end": end_date,
1267
- }
1268
- )
1269
- self.acct_line.stop_plan_successor(suspension_start, suspension_end, True)
1270
- self.assertEqual(
1271
- self.acct_line.date_end, suspension_start - relativedelta(days=1)
1272
- )
1273
- new_line = self.env["contract.line"].search(
1274
- [("predecessor_contract_line_id", "=", self.acct_line.id)]
1275
- )
1276
- self.assertTrue(new_line)
1277
- new_date_end = (
1278
- end_date + (suspension_end - suspension_start) + relativedelta(days=1)
1279
- )
1280
- self.assertEqual(new_line.date_start, suspension_end + relativedelta(days=1))
1281
- self.assertEqual(new_line.date_end, new_date_end)
1282
- self.assertTrue(self.acct_line.manual_renew_needed)
1283
-
1284
- def test_stop_plan_successor_contract_line_3_without_end_date(self):
1285
- """
1286
- * contract line start before the suspension period and end after it
1287
- -> apply stop at suspension start date
1288
- -> apply plan successor:
1289
- - date_start: suspension.date_end
1290
- - date_end: suspension.date_end + (suspension.date_end
1291
- - suspension.date_start)
1292
- """
1293
- suspension_start = self.today + relativedelta(months=3)
1294
- suspension_end = self.today + relativedelta(months=5)
1295
- start_date = self.today
1296
- end_date = False
1297
- self.acct_line.write(
1298
- {
1299
- "date_start": start_date,
1300
- "recurring_next_date": start_date,
1301
- "date_end": end_date,
1302
- "is_auto_renew": False,
1303
- }
1304
- )
1305
- self.acct_line.stop_plan_successor(suspension_start, suspension_end, False)
1306
- self.assertEqual(
1307
- self.acct_line.date_end, suspension_start - relativedelta(days=1)
1308
- )
1309
- new_line = self.env["contract.line"].search(
1310
- [("predecessor_contract_line_id", "=", self.acct_line.id)]
1311
- )
1312
- self.assertTrue(new_line)
1313
- self.assertEqual(new_line.date_start, suspension_end + relativedelta(days=1))
1314
- self.assertFalse(new_line.date_end)
1315
- self.assertTrue(self.acct_line.manual_renew_needed)
1316
-
1317
- def test_stop_plan_successor_contract_line_4(self):
1318
- """
1319
- * contract line start and end's in the suspension period
1320
- -> apply delay
1321
- - delay: suspension.date_end - contract_line.end_date
1322
- """
1323
- suspension_start = self.today + relativedelta(months=2)
1324
- suspension_end = self.today + relativedelta(months=5)
1325
- start_date = self.today + relativedelta(months=3)
1326
- end_date = self.today + relativedelta(months=4)
1327
- self.acct_line.write(
1328
- {
1329
- "date_start": start_date,
1330
- "recurring_next_date": start_date,
1331
- "date_end": end_date,
1332
- }
1333
- )
1334
- self.acct_line.stop_plan_successor(suspension_start, suspension_end, True)
1335
- self.assertEqual(
1336
- self.acct_line.date_start,
1337
- start_date + (suspension_end - start_date) + timedelta(days=1),
1338
- )
1339
- self.assertEqual(
1340
- self.acct_line.date_end,
1341
- end_date + (suspension_end - start_date) + timedelta(days=1),
1342
- )
1343
- new_line = self.env["contract.line"].search(
1344
- [("predecessor_contract_line_id", "=", self.acct_line.id)]
1345
- )
1346
- self.assertFalse(new_line)
1347
-
1348
- def test_stop_plan_successor_contract_line_5(self):
1349
- """
1350
- * contract line start in the suspension period and end after it
1351
- -> apply delay
1352
- - delay: suspension.date_end - contract_line.date_start
1353
- """
1354
- suspension_start = self.today + relativedelta(months=2)
1355
- suspension_end = self.today + relativedelta(months=5)
1356
- start_date = self.today + relativedelta(months=3)
1357
- end_date = self.today + relativedelta(months=6)
1358
- self.acct_line.write(
1359
- {
1360
- "date_start": start_date,
1361
- "recurring_next_date": start_date,
1362
- "date_end": end_date,
1363
- }
1364
- )
1365
- self.acct_line.stop_plan_successor(suspension_start, suspension_end, True)
1366
- self.assertEqual(
1367
- self.acct_line.date_start,
1368
- start_date + (suspension_end - start_date) + timedelta(days=1),
1369
- )
1370
- self.assertEqual(
1371
- self.acct_line.date_end,
1372
- end_date + (suspension_end - start_date) + timedelta(days=1),
1373
- )
1374
- new_line = self.env["contract.line"].search(
1375
- [("predecessor_contract_line_id", "=", self.acct_line.id)]
1376
- )
1377
- self.assertFalse(new_line)
1378
-
1379
- def test_stop_plan_successor_contract_line_5_without_date_end(self):
1380
- """
1381
- * contract line start in the suspension period and end after it
1382
- -> apply delay
1383
- - delay: suspension.date_end - contract_line.date_start
1384
- """
1385
- suspension_start = self.today + relativedelta(months=2)
1386
- suspension_end = self.today + relativedelta(months=5)
1387
- start_date = self.today + relativedelta(months=3)
1388
- end_date = False
1389
- self.acct_line.write(
1390
- {
1391
- "date_start": start_date,
1392
- "recurring_next_date": start_date,
1393
- "date_end": end_date,
1394
- "is_auto_renew": False,
1395
- }
1396
- )
1397
- self.acct_line.stop_plan_successor(suspension_start, suspension_end, True)
1398
- self.assertEqual(
1399
- self.acct_line.date_start,
1400
- start_date + (suspension_end - start_date) + timedelta(days=1),
1401
- )
1402
- self.assertFalse(self.acct_line.date_end)
1403
- new_line = self.env["contract.line"].search(
1404
- [("predecessor_contract_line_id", "=", self.acct_line.id)]
1405
- )
1406
- self.assertFalse(new_line)
1407
-
1408
- def test_stop_plan_successor_contract_line_6(self):
1409
- """
1410
- * contract line start and end after the suspension period
1411
- -> apply delay
1412
- - delay: suspension.date_end - suspension.start_date
1413
- """
1414
- suspension_start = self.today + relativedelta(months=2)
1415
- suspension_end = self.today + relativedelta(months=3)
1416
- start_date = self.today + relativedelta(months=4)
1417
- end_date = self.today + relativedelta(months=6)
1418
- self.acct_line.write(
1419
- {
1420
- "date_start": start_date,
1421
- "recurring_next_date": start_date,
1422
- "date_end": end_date,
1423
- }
1424
- )
1425
- self.acct_line.stop_plan_successor(suspension_start, suspension_end, True)
1426
- self.assertEqual(
1427
- self.acct_line.date_start,
1428
- start_date + (suspension_end - suspension_start) + timedelta(days=1),
1429
- )
1430
- self.assertEqual(
1431
- self.acct_line.date_end,
1432
- end_date + (suspension_end - suspension_start) + timedelta(days=1),
1433
- )
1434
- new_line = self.env["contract.line"].search(
1435
- [("predecessor_contract_line_id", "=", self.acct_line.id)]
1436
- )
1437
- self.assertFalse(new_line)
1438
-
1439
- def test_stop_plan_successor_contract_line_6_without_date_end(self):
1440
- """
1441
- * contract line start and end after the suspension period
1442
- -> apply delay
1443
- - delay: suspension.date_end - suspension.start_date
1444
- """
1445
- suspension_start = self.today + relativedelta(months=2)
1446
- suspension_end = self.today + relativedelta(months=3)
1447
- start_date = self.today + relativedelta(months=4)
1448
- end_date = False
1449
- self.acct_line.write(
1450
- {
1451
- "date_start": start_date,
1452
- "recurring_next_date": start_date,
1453
- "date_end": end_date,
1454
- "is_auto_renew": False,
1455
- }
1456
- )
1457
- self.acct_line.stop_plan_successor(suspension_start, suspension_end, True)
1458
- self.assertEqual(
1459
- self.acct_line.date_start,
1460
- start_date + (suspension_end - suspension_start) + timedelta(days=1),
1461
- )
1462
- self.assertFalse(self.acct_line.date_end)
1463
- new_line = self.env["contract.line"].search(
1464
- [("predecessor_contract_line_id", "=", self.acct_line.id)]
1465
- )
1466
- self.assertFalse(new_line)
1467
-
1468
- def test_stop_plan_successor_wizard(self):
1469
- suspension_start = self.today + relativedelta(months=2)
1470
- suspension_end = self.today + relativedelta(months=3)
1471
- start_date = self.today + relativedelta(months=4)
1472
- end_date = self.today + relativedelta(months=6)
1473
- self.acct_line.write(
1474
- {
1475
- "date_start": start_date,
1476
- "recurring_next_date": start_date,
1477
- "date_end": end_date,
1478
- }
1479
- )
1480
- wizard = self.env["contract.line.wizard"].create(
1481
- {
1482
- "date_start": suspension_start,
1483
- "date_end": suspension_end,
1484
- "is_auto_renew": False,
1485
- "contract_line_id": self.acct_line.id,
1486
- }
1487
- )
1488
- wizard.stop_plan_successor()
1489
- self.assertEqual(
1490
- self.acct_line.date_start,
1491
- start_date + (suspension_end - suspension_start) + timedelta(days=1),
1492
- )
1493
- self.assertEqual(
1494
- self.acct_line.date_end,
1495
- end_date + (suspension_end - suspension_start) + timedelta(days=1),
1496
- )
1497
- new_line = self.env["contract.line"].search(
1498
- [("predecessor_contract_line_id", "=", self.acct_line.id)]
1499
- )
1500
- self.assertFalse(new_line)
1501
-
1502
- def test_plan_successor_contract_line(self):
1503
- self.acct_line.write(
1504
- {
1505
- "date_start": self.today,
1506
- "recurring_next_date": self.today,
1507
- "date_end": self.today + relativedelta(months=3),
1508
- "is_auto_renew": False,
1509
- }
1510
- )
1511
- self.acct_line.plan_successor(
1512
- self.today + relativedelta(months=5),
1513
- self.today + relativedelta(months=7),
1514
- True,
1515
- )
1516
- new_line = self.env["contract.line"].search(
1517
- [("predecessor_contract_line_id", "=", self.acct_line.id)]
1518
- )
1519
- self.assertFalse(self.acct_line.is_auto_renew)
1520
- self.assertTrue(new_line.is_auto_renew)
1521
- self.assertTrue(new_line, "should create a new contract line")
1522
- self.assertEqual(new_line.date_start, self.today + relativedelta(months=5))
1523
- self.assertEqual(new_line.date_end, self.today + relativedelta(months=7))
1524
-
1525
- def test_overlap(self):
1526
- self.acct_line.write(
1527
- {
1528
- "date_start": self.today,
1529
- "recurring_next_date": self.today,
1530
- "date_end": self.today + relativedelta(months=3),
1531
- "is_auto_renew": False,
1532
- }
1533
- )
1534
- self.acct_line.plan_successor(
1535
- self.today + relativedelta(months=5),
1536
- self.today + relativedelta(months=7),
1537
- True,
1538
- )
1539
- new_line = self.env["contract.line"].search(
1540
- [("predecessor_contract_line_id", "=", self.acct_line.id)]
1541
- )
1542
- with self.assertRaises(ValidationError):
1543
- new_line.date_start = self.today + relativedelta(months=2)
1544
- with self.assertRaises(ValidationError):
1545
- self.acct_line.date_end = self.today + relativedelta(months=6)
1546
-
1547
- def test_plan_successor_wizard(self):
1548
- self.acct_line.write(
1549
- {
1550
- "date_start": self.today,
1551
- "recurring_next_date": self.today,
1552
- "date_end": self.today + relativedelta(months=2),
1553
- "is_auto_renew": False,
1554
- }
1555
- )
1556
- wizard = self.env["contract.line.wizard"].create(
1557
- {
1558
- "date_start": self.today + relativedelta(months=3),
1559
- "date_end": self.today + relativedelta(months=5),
1560
- "is_auto_renew": True,
1561
- "contract_line_id": self.acct_line.id,
1562
- }
1563
- )
1564
- wizard.plan_successor()
1565
- new_line = self.env["contract.line"].search(
1566
- [("predecessor_contract_line_id", "=", self.acct_line.id)]
1567
- )
1568
- self.assertFalse(self.acct_line.is_auto_renew)
1569
- self.assertTrue(new_line.is_auto_renew)
1570
- self.assertTrue(new_line, "should create a new contract line")
1571
- self.assertEqual(new_line.date_start, self.today + relativedelta(months=3))
1572
- self.assertEqual(new_line.date_end, self.today + relativedelta(months=5))
1573
-
1574
- def test_cancel(self):
1575
- self.acct_line.write(
1576
- {"date_end": self.today + relativedelta(months=5), "is_auto_renew": True}
1577
- )
1578
- self.acct_line.cancel()
1579
- self.assertTrue(self.acct_line.is_canceled)
1580
- self.assertFalse(self.acct_line.is_auto_renew)
1581
- with self.assertRaises(ValidationError):
1582
- self.acct_line.is_auto_renew = True
1583
- self.acct_line.uncancel(self.today)
1584
- self.assertFalse(self.acct_line.is_canceled)
1585
-
1586
- def test_uncancel_wizard(self):
1587
- self.acct_line.cancel()
1588
- self.assertTrue(self.acct_line.is_canceled)
1589
- wizard = self.env["contract.line.wizard"].create(
1590
- {"recurring_next_date": self.today, "contract_line_id": self.acct_line.id}
1591
- )
1592
- wizard.uncancel()
1593
- self.assertFalse(self.acct_line.is_canceled)
1594
-
1595
- def test_cancel_uncancel_with_predecessor(self):
1596
- suspension_start = self.today + relativedelta(months=3)
1597
- suspension_end = self.today + relativedelta(months=5)
1598
- start_date = self.today
1599
- end_date = self.today + relativedelta(months=4)
1600
- self.acct_line.write(
1601
- {
1602
- "date_start": start_date,
1603
- "recurring_next_date": start_date,
1604
- "date_end": end_date,
1605
- }
1606
- )
1607
- self.acct_line.stop_plan_successor(suspension_start, suspension_end, True)
1608
- self.assertEqual(
1609
- self.acct_line.date_end, suspension_start - relativedelta(days=1)
1610
- )
1611
- new_line = self.env["contract.line"].search(
1612
- [("predecessor_contract_line_id", "=", self.acct_line.id)]
1613
- )
1614
- self.assertEqual(self.acct_line.successor_contract_line_id, new_line)
1615
- new_line.cancel()
1616
- self.assertTrue(new_line.is_canceled)
1617
- self.assertFalse(self.acct_line.successor_contract_line_id)
1618
- self.assertEqual(new_line.predecessor_contract_line_id, self.acct_line)
1619
- new_line.uncancel(suspension_end + relativedelta(days=1))
1620
- self.assertFalse(new_line.is_canceled)
1621
- self.assertEqual(self.acct_line.successor_contract_line_id, new_line)
1622
- self.assertEqual(
1623
- new_line.recurring_next_date,
1624
- suspension_end + relativedelta(days=1),
1625
- )
1626
-
1627
- def test_cancel_uncancel_with_predecessor_has_successor(self):
1628
- suspension_start = self.today + relativedelta(months=6)
1629
- suspension_end = self.today + relativedelta(months=7)
1630
- start_date = self.today
1631
- end_date = self.today + relativedelta(months=8)
1632
- self.acct_line.write(
1633
- {
1634
- "date_start": start_date,
1635
- "recurring_next_date": start_date,
1636
- "date_end": end_date,
1637
- }
1638
- )
1639
- self.acct_line.stop_plan_successor(suspension_start, suspension_end, True)
1640
- new_line = self.env["contract.line"].search(
1641
- [("predecessor_contract_line_id", "=", self.acct_line.id)]
1642
- )
1643
- new_line.cancel()
1644
- suspension_start = self.today + relativedelta(months=4)
1645
- suspension_end = self.today + relativedelta(months=5)
1646
- self.acct_line.stop_plan_successor(suspension_start, suspension_end, True)
1647
- with self.assertRaises(ValidationError):
1648
- new_line.uncancel(suspension_end)
1649
-
1650
- def test_check_has_not_date_end_has_successor(self):
1651
- self.acct_line.write({"date_end": False, "is_auto_renew": False})
1652
- with self.assertRaises(ValidationError):
1653
- self.acct_line.plan_successor(
1654
- to_date("2016-03-01"), to_date("2016-09-01"), False
1655
- )
1656
-
1657
- def test_check_has_not_date_end_is_auto_renew(self):
1658
- with self.assertRaises(ValidationError):
1659
- self.acct_line.write({"date_end": False, "is_auto_renew": True})
1660
-
1661
- def test_check_has_successor_is_auto_renew(self):
1662
- with self.assertRaises(ValidationError):
1663
- self.acct_line.plan_successor(
1664
- to_date("2016-03-01"), to_date("2018-09-01"), False
1665
- )
1666
-
1667
- def test_search_contract_line_to_renew(self):
1668
- self.acct_line.write({"date_end": self.today, "is_auto_renew": True})
1669
- line_1 = self.acct_line.copy({"date_end": self.today + relativedelta(months=1)})
1670
- line_2 = self.acct_line.copy({"date_end": self.today - relativedelta(months=1)})
1671
- line_3 = self.acct_line.copy({"date_end": self.today - relativedelta(months=2)})
1672
- line_4 = self.acct_line.copy({"date_end": self.today + relativedelta(months=2)})
1673
- to_renew = self.acct_line.search(
1674
- self.acct_line._contract_line_to_renew_domain()
1675
- )
1676
- self.assertEqual(set(to_renew), {self.acct_line, line_1, line_2, line_3})
1677
- self.acct_line.cron_renew_contract_line()
1678
- self.assertTrue(self.acct_line.successor_contract_line_id)
1679
- self.assertTrue(line_1.successor_contract_line_id)
1680
- self.assertTrue(line_2.successor_contract_line_id)
1681
- self.assertTrue(line_3.successor_contract_line_id)
1682
- self.assertFalse(line_4.successor_contract_line_id)
1683
-
1684
- def test_renew_create_new_line(self):
1685
- date_start = self.today - relativedelta(months=9)
1686
- date_end = date_start + relativedelta(months=12) - relativedelta(days=1)
1687
- self.acct_line.write(
1688
- {
1689
- "is_auto_renew": True,
1690
- "date_start": date_start,
1691
- "recurring_next_date": date_start,
1692
- "date_end": self.today,
1693
- }
1694
- )
1695
- self.acct_line._onchange_is_auto_renew()
1696
- self.assertEqual(self.acct_line.date_end, date_end)
1697
- new_line = self.acct_line.renew()
1698
- self.assertFalse(self.acct_line.is_auto_renew)
1699
- self.assertTrue(new_line.is_auto_renew)
1700
- self.assertEqual(new_line.date_start, date_start + relativedelta(months=12))
1701
- self.assertEqual(new_line.date_end, date_end + relativedelta(months=12))
1702
-
1703
- def test_renew_extend_original_line(self):
1704
- self.contract.company_id.create_new_line_at_contract_line_renew = False
1705
- date_start = self.today - relativedelta(months=9)
1706
- date_end = date_start + relativedelta(months=12) - relativedelta(days=1)
1707
- self.acct_line.write(
1708
- {
1709
- "is_auto_renew": True,
1710
- "date_start": date_start,
1711
- "recurring_next_date": date_start,
1712
- "date_end": self.today,
1713
- }
1714
- )
1715
- self.acct_line._onchange_is_auto_renew()
1716
- self.assertEqual(self.acct_line.date_end, date_end)
1717
- self.acct_line.renew()
1718
- self.assertTrue(self.acct_line.is_auto_renew)
1719
- self.assertEqual(self.acct_line.date_start, date_start)
1720
- self.assertEqual(self.acct_line.date_end, date_end + relativedelta(months=12))
1721
-
1722
1080
  def test_cron_recurring_create_invoice(self):
1723
1081
  self.acct_line.date_start = "2018-01-01"
1724
1082
  self.acct_line.recurring_invoicing_type = "post-paid"
@@ -1760,7 +1118,6 @@ class TestContract(TestContractBase):
1760
1118
  )
1761
1119
  self.assertEqual(first, to_date("2018-03-01"))
1762
1120
  self.assertEqual(last, to_date("2018-03-15"))
1763
- self.acct_line.manual_renew_needed = True
1764
1121
 
1765
1122
  def test_get_period_to_invoice_monthlylastday_prepaid(self):
1766
1123
  self.acct_line.date_start = "2018-01-05"
@@ -1950,140 +1307,6 @@ class TestContract(TestContractBase):
1950
1307
  self.assertEqual(first, to_date("2020-01-05"))
1951
1308
  self.assertEqual(last, to_date("2020-03-15"))
1952
1309
 
1953
- def test_unlink(self):
1954
- with self.assertRaises(ValidationError):
1955
- self.acct_line.unlink()
1956
-
1957
- def test_contract_line_state(self):
1958
- lines = self.env["contract.line"]
1959
- # upcoming
1960
- lines |= self.acct_line.copy(
1961
- {
1962
- "date_start": self.today + relativedelta(months=3),
1963
- "recurring_next_date": self.today + relativedelta(months=3),
1964
- "date_end": self.today + relativedelta(months=5),
1965
- }
1966
- )
1967
- # in-progress
1968
- lines |= self.acct_line.copy(
1969
- {
1970
- "date_start": self.today,
1971
- "recurring_next_date": self.today,
1972
- "date_end": self.today + relativedelta(months=5),
1973
- }
1974
- )
1975
- # in-progress
1976
- lines |= self.acct_line.copy(
1977
- {
1978
- "date_start": self.today,
1979
- "recurring_next_date": self.today,
1980
- "date_end": self.today + relativedelta(months=5),
1981
- "manual_renew_needed": True,
1982
- }
1983
- )
1984
- # to-renew
1985
- lines |= self.acct_line.copy(
1986
- {
1987
- "date_start": self.today - relativedelta(months=5),
1988
- "recurring_next_date": self.today - relativedelta(months=5),
1989
- "date_end": self.today - relativedelta(months=2),
1990
- "manual_renew_needed": True,
1991
- }
1992
- )
1993
- # upcoming-close
1994
- lines |= self.acct_line.copy(
1995
- {
1996
- "date_start": self.today - relativedelta(months=5),
1997
- "recurring_next_date": self.today - relativedelta(months=5),
1998
- "date_end": self.today + relativedelta(days=20),
1999
- "is_auto_renew": False,
2000
- }
2001
- )
2002
- # closed
2003
- lines |= self.acct_line.copy(
2004
- {
2005
- "date_start": self.today - relativedelta(months=5),
2006
- "recurring_next_date": self.today - relativedelta(months=5),
2007
- "date_end": self.today - relativedelta(months=2),
2008
- "is_auto_renew": False,
2009
- }
2010
- )
2011
- # canceled
2012
- lines |= self.acct_line.copy(
2013
- {
2014
- "date_start": self.today - relativedelta(months=5),
2015
- "recurring_next_date": self.today - relativedelta(months=5),
2016
- "date_end": self.today - relativedelta(months=2),
2017
- "is_canceled": True,
2018
- }
2019
- )
2020
- # section
2021
- lines |= self.env["contract.line"].create(
2022
- {
2023
- "contract_id": self.contract.id,
2024
- "display_type": "line_section",
2025
- "name": "Test section",
2026
- }
2027
- )
2028
- states = [
2029
- "upcoming",
2030
- "in-progress",
2031
- "to-renew",
2032
- "upcoming-close",
2033
- "closed",
2034
- "canceled",
2035
- False,
2036
- ]
2037
- self.assertEqual(set(lines.mapped("state")), set(states))
2038
- # Test search method
2039
- lines.flush_recordset() # Needed for computed stored fields
2040
- # like termination_notice_date
2041
- for state in states:
2042
- lines = self.env["contract.line"].search([("state", "=", state)])
2043
- self.assertTrue(lines, state)
2044
- self.assertTrue(state in lines.mapped("state"), state)
2045
- lines = self.env["contract.line"].search([("state", "!=", state)])
2046
- self.assertFalse(state in lines.mapped("state"), state)
2047
- lines = self.env["contract.line"].search([("state", "in", states)])
2048
- self.assertEqual(set(lines.mapped("state")), set(states))
2049
- lines = self.env["contract.line"].search([("state", "in", [])])
2050
- self.assertFalse(lines.mapped("state"))
2051
- with self.assertRaises(TypeError):
2052
- self.env["contract.line"].search([("state", "in", "upcoming")])
2053
- lines = self.env["contract.line"].search([("state", "not in", [])])
2054
- self.assertEqual(set(lines.mapped("state")), set(states))
2055
- lines = self.env["contract.line"].search([("state", "not in", states)])
2056
- self.assertFalse(lines.mapped("state"))
2057
- state2 = ["upcoming", "in-progress"]
2058
- lines = self.env["contract.line"].search([("state", "not in", state2)])
2059
- self.assertEqual(set(lines.mapped("state")), set(states) - set(state2))
2060
-
2061
- def test_check_auto_renew_contract_line_with_successor(self):
2062
- """
2063
- A contract line with a successor can't be set to auto-renew
2064
- """
2065
- successor_contract_line = self.acct_line.copy()
2066
- with self.assertRaises(ValidationError):
2067
- self.acct_line.write(
2068
- {
2069
- "is_auto_renew": True,
2070
- "successor_contract_line_id": successor_contract_line.id,
2071
- }
2072
- )
2073
-
2074
- def test_check_no_date_end_contract_line_with_successor(self):
2075
- """
2076
- A contract line with a successor must have a end date
2077
- """
2078
- successor_contract_line = self.acct_line.copy()
2079
- with self.assertRaises(ValidationError):
2080
- self.acct_line.write(
2081
- {
2082
- "date_end": False,
2083
- "successor_contract_line_id": successor_contract_line.id,
2084
- }
2085
- )
2086
-
2087
1310
  def test_check_last_date_invoiced_1(self):
2088
1311
  """
2089
1312
  start end can't be before the date of last invoice
@@ -2106,49 +1329,11 @@ class TestContract(TestContractBase):
2106
1329
  {"last_date_invoiced": self.acct_line.date_end + relativedelta(days=1)}
2107
1330
  )
2108
1331
 
2109
- def test_delay_invoiced_contract_line(self):
2110
- self.acct_line.write(
2111
- {"last_date_invoiced": self.acct_line.date_start + relativedelta(days=1)}
2112
- )
2113
- with self.assertRaises(ValidationError):
2114
- self.acct_line._delay(relativedelta(months=1))
2115
-
2116
- def test_cancel_invoiced_contract_line(self):
2117
- self.acct_line.write(
2118
- {"last_date_invoiced": self.acct_line.date_start + relativedelta(days=1)}
2119
- )
2120
- with self.assertRaises(ValidationError):
2121
- self.acct_line.cancel()
2122
-
2123
- def test_action_uncancel(self):
2124
- action = self.acct_line.action_uncancel()
2125
- self.assertEqual(
2126
- action["context"]["default_contract_line_id"], self.acct_line.id
2127
- )
2128
-
2129
- def test_action_plan_successor(self):
2130
- action = self.acct_line.action_plan_successor()
2131
- self.assertEqual(
2132
- action["context"]["default_contract_line_id"], self.acct_line.id
2133
- )
2134
-
2135
- def test_action_stop(self):
2136
- action = self.acct_line.action_stop()
2137
- self.assertEqual(
2138
- action["context"]["default_contract_line_id"], self.acct_line.id
2139
- )
2140
-
2141
- def test_action_stop_plan_successor(self):
2142
- action = self.acct_line.action_stop_plan_successor()
2143
- self.assertEqual(
2144
- action["context"]["default_contract_line_id"], self.acct_line.id
2145
- )
2146
-
2147
1332
  def test_purchase_get_view(self):
2148
1333
  purchase_tree_view = self.env.ref("contract.contract_line_supplier_tree_view")
2149
1334
  purchase_form_view = self.env.ref("contract.contract_line_supplier_form_view")
2150
1335
  view = self.acct_line.with_context(default_contract_type="purchase").get_view(
2151
- view_type="tree"
1336
+ view_type="list"
2152
1337
  )
2153
1338
  self.assertEqual(view["id"], purchase_tree_view.id)
2154
1339
  view = self.acct_line.with_context(default_contract_type="purchase").get_view(
@@ -2221,16 +1406,9 @@ class TestContract(TestContractBase):
2221
1406
  self.assertFalse(section.create_invoice_visibility)
2222
1407
 
2223
1408
  def test_invoice_contract_without_lines(self):
2224
- self.contract.contract_line_ids.cancel()
2225
1409
  self.contract.contract_line_ids.unlink()
2226
1410
  self.assertFalse(self.contract.recurring_create_invoice())
2227
1411
 
2228
- def test_stop_at_last_date_invoiced(self):
2229
- self.contract.recurring_create_invoice()
2230
- self.assertTrue(self.acct_line.recurring_next_date)
2231
- self.acct_line.stop(self.acct_line.last_date_invoiced)
2232
- self.assertFalse(self.acct_line.recurring_next_date)
2233
-
2234
1412
  def test_check_last_date_invoiced_before_next_invoice_date(self):
2235
1413
  with self.assertRaises(ValidationError):
2236
1414
  self.acct_line.write(
@@ -2242,69 +1420,6 @@ class TestContract(TestContractBase):
2242
1420
  }
2243
1421
  )
2244
1422
 
2245
- def test_stop_and_update_recurring_invoice_date(self):
2246
- self.acct_line.write(
2247
- {
2248
- "date_start": "2019-01-01",
2249
- "date_end": "2019-12-31",
2250
- "recurring_next_date": "2020-01-01",
2251
- "recurring_invoicing_type": "post-paid",
2252
- "recurring_rule_type": "yearly",
2253
- }
2254
- )
2255
- self.acct_line.stop(to_date("2019-05-31"))
2256
- self.assertEqual(self.acct_line.date_end, to_date("2019-05-31"))
2257
- self.assertEqual(self.acct_line.recurring_next_date, to_date("2019-06-01"))
2258
-
2259
- def test_action_terminate_contract(self):
2260
- action = self.contract.action_terminate_contract()
2261
- wizard = (
2262
- self.env[action["res_model"]]
2263
- .with_context(**action["context"])
2264
- .create(
2265
- {
2266
- "terminate_date": "2018-03-01",
2267
- "terminate_reason_id": self.terminate_reason.id,
2268
- "terminate_comment": "terminate_comment",
2269
- }
2270
- )
2271
- )
2272
- self.assertEqual(wizard.contract_id, self.contract)
2273
- with self.assertRaises(UserError):
2274
- wizard.terminate_contract()
2275
- group_can_terminate_contract = self.env.ref("contract.can_terminate_contract")
2276
- group_can_terminate_contract.users |= self.env.user
2277
- wizard.terminate_contract()
2278
- self.assertTrue(self.contract.is_terminated)
2279
- self.assertEqual(self.contract.terminate_date, to_date("2018-03-01"))
2280
- self.assertEqual(self.contract.terminate_reason_id.id, self.terminate_reason.id)
2281
- self.assertEqual(self.contract.terminate_comment, "terminate_comment")
2282
- self.contract.action_cancel_contract_termination()
2283
- self.assertFalse(self.contract.is_terminated)
2284
- self.assertFalse(self.contract.terminate_reason_id)
2285
- self.assertFalse(self.contract.terminate_comment)
2286
-
2287
- def test_terminate_date_before_last_date_invoiced(self):
2288
- self.contract.recurring_create_invoice()
2289
- self.assertEqual(self.acct_line.last_date_invoiced, to_date("2018-02-14"))
2290
- group_can_terminate_contract = self.env.ref("contract.can_terminate_contract")
2291
- group_can_terminate_contract.users |= self.env.user
2292
- with self.assertRaises(ValidationError):
2293
- self.contract._terminate_contract(
2294
- self.terminate_reason,
2295
- "terminate_comment",
2296
- to_date("2018-02-13"),
2297
- )
2298
- # Try terminate contract line with last_date_invoiced allowed
2299
- self.contract._terminate_contract(
2300
- self.terminate_reason,
2301
- "terminate_comment",
2302
- to_date("2018-02-13"),
2303
- terminate_lines_with_last_date_invoiced=True,
2304
- )
2305
- self.assertTrue(self.contract.is_terminated)
2306
- self.assertEqual(self.acct_line.date_end, to_date("2018-02-14"))
2307
-
2308
1423
  def test_recurrency_propagation(self):
2309
1424
  # Existing contract
2310
1425
  vals = {