diff --git a/contract_sale/views/contract.xml b/contract_sale/views/contract.xml index 1bf893b9..98317050 100644 --- a/contract_sale/views/contract.xml +++ b/contract_sale/views/contract.xml @@ -4,7 +4,7 @@ diff --git a/contract_sale_payment_mode/tests/test_sale_order.py b/contract_sale_payment_mode/tests/test_sale_order.py index 158b2cf6..661d8efa 100644 --- a/contract_sale_payment_mode/tests/test_sale_order.py +++ b/contract_sale_payment_mode/tests/test_sale_order.py @@ -8,7 +8,9 @@ from odoo.addons.product_contract.tests.test_sale_order import TestSaleOrder class TestSaleOrderPaymentMode(TestSaleOrder): def setUp(self): super(TestSaleOrderPaymentMode, self).setUp() - self.payment_mode = self.env['account.payment.mode'].search([], limit=1) + self.payment_mode = self.env['account.payment.mode'].search( + [], limit=1 + ) self.sale.payment_mode_id = self.payment_mode def test_action_confirm_with_payment_mode(self): diff --git a/product_contract/models/sale_order.py b/product_contract/models/sale_order.py index d84b0a21..58f08249 100644 --- a/product_contract/models/sale_order.py +++ b/product_contract/models/sale_order.py @@ -107,7 +107,7 @@ class SaleOrder(models.Model): def action_show_contracts(self): self.ensure_one() action = self.env.ref( - "contract.contract_contract_customer_form_view" + "contract.action_customer_contract" ).read()[0] contracts = ( self.env['contract.line'] diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index 1be510c0..6f55f5c4 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -231,3 +231,18 @@ class SaleOrderLine(models.Model): return super( SaleOrderLine, self.filtered(lambda l: not l.contract_id) ).invoice_line_create(invoice_id, qty) + + @api.depends( + 'qty_invoiced', + 'qty_delivered', + 'product_uom_qty', + 'order_id.state', + 'product_id.is_contract', + ) + def _get_to_invoice_qty(self): + """ + sale line linked to contracts must not be invoiced from sale order + """ + res = super()._get_to_invoice_qty() + self.filtered('product_id.is_contract').update({'qty_to_invoice': 0.0}) + return res diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index e1637439..5c163510 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -110,6 +110,17 @@ class TestSaleOrder(TransactionCase): contract_line.recurring_next_date, Date.to_date('2018-01-31') ) + def test_sale_order_invoice_status(self): + """ + sale line linked to contracts must not be invoiced from sale order + """ + self.sale.action_confirm() + self.assertEqual(self.order_line1.invoice_status, 'no') + invoice = self.order_line1.contract_id.recurring_create_invoice() + self.assertTrue(invoice) + self.assertEqual(self.order_line1.invoice_qty, 1) + self.assertEqual(self.order_line1.qty_to_invoice, 0) + def test_action_confirm_without_contract_creation(self): """ It should create a contract for each contract template used in order_line """