diff --git a/product_contract/__manifest__.py b/product_contract/__manifest__.py
index 09769091..fc857821 100644
--- a/product_contract/__manifest__.py
+++ b/product_contract/__manifest__.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# Copyright 2018 ACSONE SA/NV.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
@@ -12,10 +11,7 @@
"ACSONE SA/NV, "
"Odoo Community Association (OCA)",
'website': 'https://github.com/oca/contract',
- 'depends': [
- 'product',
- 'contract_sale',
- ],
+ 'depends': ['product', 'contract_sale'],
'data': [
'views/product_template.xml',
'views/sale_order.xml',
diff --git a/product_contract/models/product_template.py b/product_contract/models/product_template.py
index 1d256201..b10ef3de 100644
--- a/product_contract/models/product_template.py
+++ b/product_contract/models/product_template.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# Copyright 2018 ACSONE SA/NV.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
diff --git a/product_contract/models/sale_order.py b/product_contract/models/sale_order.py
index 3a38c116..ad6f9690 100644
--- a/product_contract/models/sale_order.py
+++ b/product_contract/models/sale_order.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# Copyright 2018 ACSONE SA/NV.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py
index 2284a33a..b0434540 100644
--- a/product_contract/models/sale_order_line.py
+++ b/product_contract/models/sale_order_line.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# Copyright 2017 ACSONE SA/NV.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
@@ -51,6 +50,13 @@ class SaleOrderLine(models.Model):
date_start = fields.Date(string='Date Start')
date_end = fields.Date(string='Date End', index=True)
+ contract_line_id = fields.Many2one(
+ comodel_name="account.analytic.invoice.line",
+ string="Contract Line to replace",
+ required=False,
+ copy=False,
+ )
+
@api.onchange('product_id')
def onchange_product(self):
if self.product_id.is_contract:
@@ -97,6 +103,7 @@ class SaleOrderLine(models.Model):
contract_line |= contract_line_env.create(
rec._prepare_contract_line_values(contract)
)
+ rec.contract_line_id.stop(rec.date_start)
return contract_line
@api.constrains('contract_id')
diff --git a/product_contract/tests/test_product.py b/product_contract/tests/test_product.py
index 3676dc05..76d1aef8 100644
--- a/product_contract/tests/test_product.py
+++ b/product_contract/tests/test_product.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# Copyright 2018 ACSONE SA/NV.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py
index e60cffff..37feb78b 100644
--- a/product_contract/tests/test_sale_order.py
+++ b/product_contract/tests/test_sale_order.py
@@ -1,9 +1,10 @@
-# -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
+# Copyright 2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase
from odoo.exceptions import ValidationError
+from odoo.fields import Date
class TestSaleOrder(TransactionCase):
@@ -51,6 +52,36 @@ class TestSaleOrder(TransactionCase):
self.order_line1 = self.sale.order_line.filtered(
lambda l: l.product_id == self.product1
)
+ self.contract = self.env["account.analytic.account"].create(
+ {
+ "name": "Test Contract 2",
+ "partner_id": self.sale.partner_id.id,
+ "pricelist_id":
+ self.sale.partner_id.property_product_pricelist.id,
+ "recurring_invoices": True,
+ "contract_type": "purchase",
+ "contract_template_id": self.contract_template1.id,
+ "recurring_invoice_line_ids": [
+ (
+ 0,
+ 0,
+ {
+ "product_id": self.product1.id,
+ "name": "Services from #START# to #END#",
+ "quantity": 1,
+ "uom_id": self.product1.uom_id.id,
+ "price_unit": 100,
+ "discount": 50,
+ "recurring_rule_type": "monthly",
+ "recurring_interval": 1,
+ "date_start": "2016-02-15",
+ "recurring_next_date": "2016-02-29",
+ },
+ )
+ ],
+ }
+ )
+ self.contract_line = self.contract.recurring_invoice_line_ids[0]
def test_compute_is_contract(self):
"""Sale Order should have is_contract true if one of its lines is
@@ -153,3 +184,13 @@ class TestSaleOrder(TransactionCase):
self.sale.action_confirm()
invoice = self.order_line1.contract_id.recurring_create_invoice()
self.assertTrue(invoice in self.sale.invoice_ids)
+
+ def test_contract_upsell(self):
+ """Should stop contract line at sale order line start date"""
+ self.order_line1.contract_id = self.contract
+ self.order_line1.contract_line_id = self.contract_line
+ self.order_line1.date_start = "2018-01-01"
+ self.sale.action_confirm()
+ self.assertEqual(
+ self.contract_line.date_end, Date.to_date("2018-01-01")
+ )
diff --git a/product_contract/views/sale_order.xml b/product_contract/views/sale_order.xml
index 4443c39d..b24f7fe6 100644
--- a/product_contract/views/sale_order.xml
+++ b/product_contract/views/sale_order.xml
@@ -25,14 +25,17 @@
-
-
-
-
+
+
+
+
+