mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] - can't upsell or downsell a resiliated contract
This commit is contained in:
@@ -17,6 +17,18 @@ class SaleOrder(models.Model):
|
||||
compute='_compute_need_contract_creation'
|
||||
)
|
||||
|
||||
@api.constrains('state')
|
||||
def check_contact_is_not_resiliated(self):
|
||||
for rec in self:
|
||||
if rec.state not in (
|
||||
'sale',
|
||||
'done',
|
||||
'cancel',
|
||||
) and rec.order_line.filtered('contract_id.is_resiliated'):
|
||||
raise ValidationError(
|
||||
_("You can't upsell or downsell a resiliated contract")
|
||||
)
|
||||
|
||||
@api.depends('order_line.contract_id', 'state')
|
||||
def _compute_need_contract_creation(self):
|
||||
for rec in self:
|
||||
|
||||
@@ -67,6 +67,17 @@ class SaleOrderLine(models.Model):
|
||||
help="Specify Interval for automatic renewal.",
|
||||
)
|
||||
|
||||
@api.constrains('contract_id')
|
||||
def check_contact_is_not_resiliated(self):
|
||||
for rec in self:
|
||||
if (
|
||||
rec.order_id.state not in ('sale', 'done', 'cancel')
|
||||
and rec.contract_id.is_resiliated
|
||||
):
|
||||
raise ValidationError(
|
||||
_("You can't upsell or downsell a resiliated contract")
|
||||
)
|
||||
|
||||
@api.multi
|
||||
@api.depends('product_id')
|
||||
def _compute_contract_template_id(self):
|
||||
|
||||
@@ -342,3 +342,18 @@ class TestSaleOrder(TransactionCase):
|
||||
self.env['contract.contract'].search(action['domain']),
|
||||
self.sale.order_line.mapped('contract_id'),
|
||||
)
|
||||
|
||||
def test_check_contact_is_not_resiliated(self):
|
||||
self.contract.is_resiliated = True
|
||||
with self.assertRaises(ValidationError):
|
||||
self.order_line1.contract_id = self.contract
|
||||
|
||||
def test_check_contact_is_not_resiliated(self):
|
||||
self.order_line1.contract_id = self.contract
|
||||
self.sale.action_confirm()
|
||||
self.contract.is_resiliated = True
|
||||
self.sale.action_cancel()
|
||||
with self.assertRaises(ValidationError):
|
||||
self.sale.action_draft()
|
||||
self.contract.is_resiliated = False
|
||||
self.sale.action_draft()
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
domain="['|',('contract_template_id','=',contract_template_id),
|
||||
('contract_template_id','=',False),
|
||||
('partner_id','=',parent.partner_id),
|
||||
('is_resiliated','=',False),
|
||||
]"/>
|
||||
<field name="contract_line_id"
|
||||
attrs="{'invisible': [('is_contract', '=', False)]}"
|
||||
|
||||
Reference in New Issue
Block a user