mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] product_contract: black, isort, prettier
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
"category": "Contract Management",
|
"category": "Contract Management",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"author": "LasLabs, " "ACSONE SA/NV, " "Odoo Community Association (OCA)",
|
"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"],
|
"depends": ["product", "contract", "sale"],
|
||||||
"data": [
|
"data": [
|
||||||
"views/res_config_settings.xml",
|
"views/res_config_settings.xml",
|
||||||
|
|||||||
@@ -46,7 +46,9 @@ class ProductTemplate(models.Model):
|
|||||||
string="Termination Notice type",
|
string="Termination Notice type",
|
||||||
)
|
)
|
||||||
auto_renew_interval = fields.Integer(
|
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(
|
auto_renew_rule_type = fields.Selection(
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -16,8 +16,14 @@ class SaleOrder(models.Model):
|
|||||||
@api.constrains("state")
|
@api.constrains("state")
|
||||||
def check_contact_is_not_terminated(self):
|
def check_contact_is_not_terminated(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
if rec.state not in ("sale", "done", "cancel",) and rec.order_line.filtered(
|
if (
|
||||||
"contract_id.is_terminated"
|
rec.state
|
||||||
|
not in (
|
||||||
|
"sale",
|
||||||
|
"done",
|
||||||
|
"cancel",
|
||||||
|
)
|
||||||
|
and rec.order_line.filtered("contract_id.is_terminated")
|
||||||
):
|
):
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_("You can't upsell or downsell a terminated contract")
|
_("You can't upsell or downsell a terminated contract")
|
||||||
|
|||||||
@@ -54,7 +54,9 @@ class SaleOrderLine(models.Model):
|
|||||||
)
|
)
|
||||||
is_auto_renew = fields.Boolean(string="Auto Renew", default=False)
|
is_auto_renew = fields.Boolean(string="Auto Renew", default=False)
|
||||||
auto_renew_interval = fields.Integer(
|
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(
|
auto_renew_rule_type = fields.Selection(
|
||||||
[
|
[
|
||||||
@@ -106,7 +108,8 @@ class SaleOrderLine(models.Model):
|
|||||||
rec.date_end = (
|
rec.date_end = (
|
||||||
rec.date_start
|
rec.date_start
|
||||||
+ contract_line_model.get_relative_delta(
|
+ 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)
|
- relativedelta(days=1)
|
||||||
)
|
)
|
||||||
@@ -125,7 +128,8 @@ class SaleOrderLine(models.Model):
|
|||||||
rec.date_end = (
|
rec.date_end = (
|
||||||
rec.date_start
|
rec.date_start
|
||||||
+ contract_line_model.get_relative_delta(
|
+ 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)
|
- relativedelta(days=1)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ class TestProductTemplate(TransactionCase):
|
|||||||
self.contract = self.env["contract.template"].create({"name": "Test"})
|
self.contract = self.env["contract.template"].create({"name": "Test"})
|
||||||
|
|
||||||
def test_change_is_contract(self):
|
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
|
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.is_contract = True
|
||||||
self.service_product.property_contract_template_id = self.contract.id
|
self.service_product.property_contract_template_id = self.contract.id
|
||||||
self.service_product.is_contract = False
|
self.service_product.is_contract = False
|
||||||
@@ -24,8 +24,8 @@ class TestProductTemplate(TransactionCase):
|
|||||||
|
|
||||||
def test_check_contract_product_type(self):
|
def test_check_contract_product_type(self):
|
||||||
"""
|
"""
|
||||||
It should raise ValidationError on change of is_contract to True
|
It should raise ValidationError on change of is_contract to True
|
||||||
for consu product
|
for consu product
|
||||||
"""
|
"""
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
self.consu_product.is_contract = True
|
self.consu_product.is_contract = True
|
||||||
|
|||||||
@@ -96,14 +96,15 @@ class TestSaleOrder(TransactionCase):
|
|||||||
self.assertTrue(self.sale.is_contract)
|
self.assertTrue(self.sale.is_contract)
|
||||||
|
|
||||||
def test_action_confirm(self):
|
def test_action_confirm(self):
|
||||||
""" It should create a contract for each contract template used in
|
"""It should create a contract for each contract template used in
|
||||||
order_line """
|
order_line"""
|
||||||
self.order_line1.onchange_product()
|
self.order_line1.onchange_product()
|
||||||
self.sale.action_confirm()
|
self.sale.action_confirm()
|
||||||
contracts = self.sale.order_line.mapped("contract_id")
|
contracts = self.sale.order_line.mapped("contract_id")
|
||||||
self.assertEqual(len(contracts), 2)
|
self.assertEqual(len(contracts), 2)
|
||||||
self.assertEqual(
|
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
|
contract_line = self.order_line1.contract_id.contract_line_ids
|
||||||
self.assertEqual(contract_line.date_start, Date.to_date("2018-01-01"))
|
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)
|
self.assertEqual(self.order_line1.qty_to_invoice, 0)
|
||||||
|
|
||||||
def test_action_confirm_without_contract_creation(self):
|
def test_action_confirm_without_contract_creation(self):
|
||||||
""" It should create a contract for each contract template used in
|
"""It should create a contract for each contract template used in
|
||||||
order_line """
|
order_line"""
|
||||||
self.sale.company_id.create_contract_at_sale_order_confirmation = False
|
self.sale.company_id.create_contract_at_sale_order_confirmation = False
|
||||||
self.order_line1.onchange_product()
|
self.order_line1.onchange_product()
|
||||||
self.sale.action_confirm()
|
self.sale.action_confirm()
|
||||||
@@ -159,7 +160,8 @@ class TestSaleOrder(TransactionCase):
|
|||||||
self.assertEqual(len(self.sale.order_line.mapped("contract_id")), 2)
|
self.assertEqual(len(self.sale.order_line.mapped("contract_id")), 2)
|
||||||
self.assertFalse(self.sale.need_contract_creation)
|
self.assertFalse(self.sale.need_contract_creation)
|
||||||
self.assertEqual(
|
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
|
contract_line = self.order_line1.contract_id.contract_line_ids
|
||||||
self.assertEqual(contract_line.date_start, Date.to_date("2018-01-01"))
|
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)
|
self.assertEqual(self.sale.contract_count, 2)
|
||||||
|
|
||||||
def test_onchange_product(self):
|
def test_onchange_product(self):
|
||||||
""" It should get recurrence invoicing info to the sale line from
|
"""It should get recurrence invoicing info to the sale line from
|
||||||
its product """
|
its product"""
|
||||||
self.order_line1.onchange_product()
|
self.order_line1.onchange_product()
|
||||||
self.assertEqual(
|
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.assertEqual(
|
||||||
self.order_line1.recurring_invoicing_type,
|
self.order_line1.recurring_invoicing_type,
|
||||||
@@ -348,7 +351,7 @@ class TestSaleOrder(TransactionCase):
|
|||||||
self.sale.action_draft()
|
self.sale.action_draft()
|
||||||
|
|
||||||
def test_order_lines_with_the_same_contract_template(self):
|
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"""
|
template"""
|
||||||
self.product2.with_context(force_company=self.sale.company_id.id).write(
|
self.product2.with_context(force_company=self.sale.company_id.id).write(
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user