@ -2,6 +2,7 @@
# Copyright 2018 Tecnativa - Pedro M. Baeza
# Copyright 2018 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from datetime import timedelta
from dateutil.relativedelta import relativedelta
from dateutil.relativedelta import relativedelta
from odoo import fields
from odoo import fields
from odoo.exceptions import ValidationError
from odoo.exceptions import ValidationError
@ -828,10 +829,11 @@ class TestContract(TestContractBase):
)
)
self . assertEqual (
self . assertEqual (
self . acct_line . date_start ,
self . acct_line . date_start ,
start_date + ( suspension_end - start_date ) ,
start_date + ( suspension_end - start_date ) + timedelta ( days = 1 ) ,
)
)
self . assertEqual (
self . assertEqual (
self . acct_line . date_end , end_date + ( suspension_end - start_date )
self . acct_line . date_end ,
end_date + ( suspension_end - start_date ) + timedelta ( days = 1 ) ,
)
)
new_line = self . env [ ' account.analytic.invoice.line ' ] . search (
new_line = self . env [ ' account.analytic.invoice.line ' ] . search (
[ ( ' predecessor_contract_line_id ' , ' = ' , self . acct_line . id ) ]
[ ( ' predecessor_contract_line_id ' , ' = ' , self . acct_line . id ) ]
@ -860,10 +862,11 @@ class TestContract(TestContractBase):
)
)
self . assertEqual (
self . assertEqual (
self . acct_line . date_start ,
self . acct_line . date_start ,
start_date + ( suspension_end - start_date ) ,
start_date + ( suspension_end - start_date ) + timedelta ( days = 1 ) ,
)
)
self . assertEqual (
self . assertEqual (
self . acct_line . date_end , end_date + ( suspension_end - start_date )
self . acct_line . date_end ,
end_date + ( suspension_end - start_date ) + timedelta ( days = 1 ) ,
)
)
new_line = self . env [ ' account.analytic.invoice.line ' ] . search (
new_line = self . env [ ' account.analytic.invoice.line ' ] . search (
[ ( ' predecessor_contract_line_id ' , ' = ' , self . acct_line . id ) ]
[ ( ' predecessor_contract_line_id ' , ' = ' , self . acct_line . id ) ]
@ -893,7 +896,7 @@ class TestContract(TestContractBase):
)
)
self . assertEqual (
self . assertEqual (
self . acct_line . date_start ,
self . acct_line . date_start ,
start_date + ( suspension_end - start_date ) ,
start_date + ( suspension_end - start_date ) + timedelta ( days = 1 ) ,
)
)
self . assertFalse ( self . acct_line . date_end )
self . assertFalse ( self . acct_line . date_end )
new_line = self . env [ ' account.analytic.invoice.line ' ] . search (
new_line = self . env [ ' account.analytic.invoice.line ' ] . search (
@ -923,11 +926,13 @@ class TestContract(TestContractBase):
)
)
self . assertEqual (
self . assertEqual (
self . acct_line . date_start ,
self . acct_line . date_start ,
start_date + ( suspension_end - suspension_start ) ,
start_date
+ ( suspension_end - suspension_start )
+ timedelta ( days = 1 ) ,
)
)
self . assertEqual (
self . assertEqual (
self . acct_line . date_end ,
self . acct_line . date_end ,
end_date + ( suspension_end - suspension_start ) ,
end_date + ( suspension_end - suspension_start ) + timedelta ( days = 1 ) ,
)
)
new_line = self . env [ ' account.analytic.invoice.line ' ] . search (
new_line = self . env [ ' account.analytic.invoice.line ' ] . search (
[ ( ' predecessor_contract_line_id ' , ' = ' , self . acct_line . id ) ]
[ ( ' predecessor_contract_line_id ' , ' = ' , self . acct_line . id ) ]
@ -957,7 +962,9 @@ class TestContract(TestContractBase):
)
)
self . assertEqual (
self . assertEqual (
self . acct_line . date_start ,
self . acct_line . date_start ,
start_date + ( suspension_end - suspension_start ) ,
start_date
+ ( suspension_end - suspension_start )
+ timedelta ( days = 1 ) ,
)
)
self . assertFalse ( self . acct_line . date_end )
self . assertFalse ( self . acct_line . date_end )
new_line = self . env [ ' account.analytic.invoice.line ' ] . search (
new_line = self . env [ ' account.analytic.invoice.line ' ] . search (
@ -988,11 +995,13 @@ class TestContract(TestContractBase):
wizard . stop_plan_successor ( )
wizard . stop_plan_successor ( )
self . assertEqual (
self . assertEqual (
self . acct_line . date_start ,
self . acct_line . date_start ,
start_date + ( suspension_end - suspension_start ) ,
start_date
+ ( suspension_end - suspension_start )
+ timedelta ( days = 1 ) ,
)
)
self . assertEqual (
self . assertEqual (
self . acct_line . date_end ,
self . acct_line . date_end ,
end_date + ( suspension_end - suspension_start ) ,
end_date + ( suspension_end - suspension_start ) + timedelta ( days = 1 ) ,
)
)
new_line = self . env [ ' account.analytic.invoice.line ' ] . search (
new_line = self . env [ ' account.analytic.invoice.line ' ] . search (
[ ( ' predecessor_contract_line_id ' , ' = ' , self . acct_line . id ) ]
[ ( ' predecessor_contract_line_id ' , ' = ' , self . acct_line . id ) ]
@ -1087,6 +1096,62 @@ class TestContract(TestContractBase):
self . acct_line . uncancel ( fields . Date . today ( ) )
self . acct_line . uncancel ( fields . Date . today ( ) )
self . assertFalse ( self . acct_line . is_canceled )
self . assertFalse ( self . acct_line . is_canceled )
def test_cancel_uncancel_with_predecessor ( self ) :
suspension_start = fields . Date . today ( ) + relativedelta ( months = 3 )
suspension_end = fields . Date . today ( ) + relativedelta ( months = 5 )
start_date = fields . Date . today ( )
end_date = fields . Date . today ( ) + relativedelta ( months = 4 )
self . acct_line . write (
{
' date_start ' : start_date ,
' recurring_next_date ' : start_date ,
' date_end ' : end_date ,
}
)
self . acct_line . stop_plan_successor (
suspension_start , suspension_end , True
)
self . assertEqual ( self . acct_line . date_end , suspension_start )
new_line = self . env [ ' account.analytic.invoice.line ' ] . search (
[ ( ' predecessor_contract_line_id ' , ' = ' , self . acct_line . id ) ]
)
self . assertEqual ( self . acct_line . successor_contract_line_id , new_line )
new_line . cancel ( )
self . assertTrue ( new_line . is_canceled )
self . assertFalse ( self . acct_line . successor_contract_line_id )
self . assertEqual ( new_line . predecessor_contract_line_id , self . acct_line )
new_line . uncancel ( suspension_end )
self . assertFalse ( new_line . is_canceled )
self . assertEqual ( self . acct_line . successor_contract_line_id , new_line )
self . assertEqual ( new_line . recurring_next_date , suspension_end )
def test_cancel_uncancel_with_predecessor_has_successor ( self ) :
suspension_start = fields . Date . today ( ) + relativedelta ( months = 6 )
suspension_end = fields . Date . today ( ) + relativedelta ( months = 7 )
start_date = fields . Date . today ( )
end_date = fields . Date . today ( ) + relativedelta ( months = 8 )
self . acct_line . write (
{
' date_start ' : start_date ,
' recurring_next_date ' : start_date ,
' date_end ' : end_date ,
}
)
self . acct_line . stop_plan_successor (
suspension_start , suspension_end , True
)
new_line = self . env [ ' account.analytic.invoice.line ' ] . search (
[ ( ' predecessor_contract_line_id ' , ' = ' , self . acct_line . id ) ]
)
new_line . cancel ( )
suspension_start = fields . Date . today ( ) + relativedelta ( months = 4 )
suspension_end = fields . Date . today ( ) + relativedelta ( months = 5 )
self . acct_line . stop_plan_successor (
suspension_start , suspension_end , True
)
with self . assertRaises ( ValidationError ) :
new_line . uncancel ( suspension_end )
def test_check_has_not_date_end_has_successor ( self ) :
def test_check_has_not_date_end_has_successor ( self ) :
self . acct_line . write ( { ' date_end ' : False , ' is_auto_renew ' : False } )
self . acct_line . write ( { ' date_end ' : False , ' is_auto_renew ' : False } )
with self . assertRaises ( ValidationError ) :
with self . assertRaises ( ValidationError ) :
@ -1126,8 +1191,10 @@ class TestContract(TestContractBase):
)
)
def test_renew ( self ) :
def test_renew ( self ) :
self . acct_line . _onchange_is_auto_renew ( )
self . assertEqual ( self . acct_line . date_end , to_date ( ' 2018-12-31 ' ) )
new_line = self . acct_line . renew ( )
new_line = self . acct_line . renew ( )
self . assertFalse ( self . acct_line . is_auto_renew )
self . assertFalse ( self . acct_line . is_auto_renew )
self . assertTrue ( new_line . is_auto_renew )
self . assertTrue ( new_line . is_auto_renew )
self . assertEqual ( new_line . date_start , to_date ( ' 2019-01-01 ' ) )
self . assertEqual ( new_line . date_start , to_date ( ' 2019-01-01 ' ) )
self . assertEqual ( new_line . date_end , to_date ( ' 2020-01-0 1 ' ) )
self . assertEqual ( new_line . date_end , to_date ( ' 2019-12-3 1 ' ) )