From b14c3cf104a50a23c86561b4d3e2cfee2649cebf Mon Sep 17 00:00:00 2001 From: Mourad Date: Fri, 12 Nov 2021 11:25:08 +0100 Subject: [PATCH] [IMP] product_contract: black, isort, prettier --- product_contract/__manifest__.py | 2 +- product_contract/models/product_template.py | 4 +++- product_contract/models/sale_order.py | 10 +++++++-- product_contract/models/sale_order_line.py | 10 ++++++--- product_contract/tests/test_product.py | 8 +++---- product_contract/tests/test_sale_order.py | 23 ++++++++++++--------- 6 files changed, 36 insertions(+), 21 deletions(-) diff --git a/product_contract/__manifest__.py b/product_contract/__manifest__.py index ba99e8d6b..eff47ca39 100644 --- a/product_contract/__manifest__.py +++ b/product_contract/__manifest__.py @@ -8,7 +8,7 @@ "category": "Contract Management", "license": "AGPL-3", "author": "LasLabs, " "ACSONE SA/NV, " "Odoo Community Association (OCA)", - "website": "https://github.com/oca/contract", + "website": "https://github.com/OCA/contract", "depends": ["product", "contract", "sale"], "data": [ "views/res_config_settings.xml", diff --git a/product_contract/models/product_template.py b/product_contract/models/product_template.py index 875ff6f3e..8b17a92db 100644 --- a/product_contract/models/product_template.py +++ b/product_contract/models/product_template.py @@ -46,7 +46,9 @@ class ProductTemplate(models.Model): string="Termination Notice type", ) auto_renew_interval = fields.Integer( - default=1, string="Renew Every", help="Renew every (Days/Week/Month/Year)", + default=1, + string="Renew Every", + help="Renew every (Days/Week/Month/Year)", ) auto_renew_rule_type = fields.Selection( [ diff --git a/product_contract/models/sale_order.py b/product_contract/models/sale_order.py index 3255b9d2a..a17d87748 100644 --- a/product_contract/models/sale_order.py +++ b/product_contract/models/sale_order.py @@ -16,8 +16,14 @@ class SaleOrder(models.Model): @api.constrains("state") def check_contact_is_not_terminated(self): for rec in self: - if rec.state not in ("sale", "done", "cancel",) and rec.order_line.filtered( - "contract_id.is_terminated" + if ( + rec.state + not in ( + "sale", + "done", + "cancel", + ) + and rec.order_line.filtered("contract_id.is_terminated") ): raise ValidationError( _("You can't upsell or downsell a terminated contract") diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index fbe27f263..acfb08f39 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -54,7 +54,9 @@ class SaleOrderLine(models.Model): ) is_auto_renew = fields.Boolean(string="Auto Renew", default=False) auto_renew_interval = fields.Integer( - default=1, string="Renew Every", help="Renew every (Days/Week/Month/Year)", + default=1, + string="Renew Every", + help="Renew every (Days/Week/Month/Year)", ) auto_renew_rule_type = fields.Selection( [ @@ -106,7 +108,8 @@ class SaleOrderLine(models.Model): rec.date_end = ( rec.date_start + contract_line_model.get_relative_delta( - rec._get_auto_renew_rule_type(), int(rec.product_uom_qty), + rec._get_auto_renew_rule_type(), + int(rec.product_uom_qty), ) - relativedelta(days=1) ) @@ -125,7 +128,8 @@ class SaleOrderLine(models.Model): rec.date_end = ( rec.date_start + contract_line_model.get_relative_delta( - rec._get_auto_renew_rule_type(), int(rec.product_uom_qty), + rec._get_auto_renew_rule_type(), + int(rec.product_uom_qty), ) - relativedelta(days=1) ) diff --git a/product_contract/tests/test_product.py b/product_contract/tests/test_product.py index cc6afedae..66770a409 100644 --- a/product_contract/tests/test_product.py +++ b/product_contract/tests/test_product.py @@ -14,9 +14,9 @@ class TestProductTemplate(TransactionCase): self.contract = self.env["contract.template"].create({"name": "Test"}) def test_change_is_contract(self): - """ It should verify that the property_contract_template_id + """It should verify that the property_contract_template_id field value is removed for all the companies when - is_contract is set to False """ + is_contract is set to False""" self.service_product.is_contract = True self.service_product.property_contract_template_id = self.contract.id self.service_product.is_contract = False @@ -24,8 +24,8 @@ class TestProductTemplate(TransactionCase): def test_check_contract_product_type(self): """ - It should raise ValidationError on change of is_contract to True - for consu product + It should raise ValidationError on change of is_contract to True + for consu product """ with self.assertRaises(ValidationError): self.consu_product.is_contract = True diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index 728126512..0a4362aa4 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -96,14 +96,15 @@ class TestSaleOrder(TransactionCase): self.assertTrue(self.sale.is_contract) def test_action_confirm(self): - """ It should create a contract for each contract template used in - order_line """ + """It should create a contract for each contract template used in + order_line""" self.order_line1.onchange_product() self.sale.action_confirm() contracts = self.sale.order_line.mapped("contract_id") self.assertEqual(len(contracts), 2) self.assertEqual( - self.order_line1.contract_id.contract_template_id, self.contract_template1, + self.order_line1.contract_id.contract_template_id, + self.contract_template1, ) contract_line = self.order_line1.contract_id.contract_line_ids self.assertEqual(contract_line.date_start, Date.to_date("2018-01-01")) @@ -148,8 +149,8 @@ class TestSaleOrder(TransactionCase): 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 """ + """It should create a contract for each contract template used in + order_line""" self.sale.company_id.create_contract_at_sale_order_confirmation = False self.order_line1.onchange_product() self.sale.action_confirm() @@ -159,7 +160,8 @@ class TestSaleOrder(TransactionCase): self.assertEqual(len(self.sale.order_line.mapped("contract_id")), 2) self.assertFalse(self.sale.need_contract_creation) self.assertEqual( - self.order_line1.contract_id.contract_template_id, self.contract_template1, + self.order_line1.contract_id.contract_template_id, + self.contract_template1, ) contract_line = self.order_line1.contract_id.contract_line_ids self.assertEqual(contract_line.date_start, Date.to_date("2018-01-01")) @@ -174,11 +176,12 @@ class TestSaleOrder(TransactionCase): self.assertEqual(self.sale.contract_count, 2) def test_onchange_product(self): - """ It should get recurrence invoicing info to the sale line from - its product """ + """It should get recurrence invoicing info to the sale line from + its product""" self.order_line1.onchange_product() self.assertEqual( - self.order_line1.recurring_rule_type, self.product1.recurring_rule_type, + self.order_line1.recurring_rule_type, + self.product1.recurring_rule_type, ) self.assertEqual( self.order_line1.recurring_invoicing_type, @@ -348,7 +351,7 @@ class TestSaleOrder(TransactionCase): self.sale.action_draft() def test_order_lines_with_the_same_contract_template(self): - """ It should create one contract with two lines grouped by contract + """It should create one contract with two lines grouped by contract template""" self.product2.with_context(force_company=self.sale.company_id.id).write( {