[14.0][IMP] contract_sale_generation: Split test and common

This commit is contained in:
Denis Roussel
2022-02-16 09:32:56 +01:00
parent f61be27bf2
commit 357e37ae5e
3 changed files with 137 additions and 124 deletions

View File

@@ -1,3 +1 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import test_contract_sale from . import test_contract_sale

View File

@@ -0,0 +1,134 @@
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# Copyright 2017 Pesol (<http://pesol.es>)
# Copyright 2017 Angel Moya <angel.moya@pesol.es>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from freezegun import freeze_time
from odoo import fields
from odoo.tests import Form
def to_date(date):
return fields.Date.to_date(date)
class ContractSaleCommon:
# Use case : Prepare some data for current test case
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.analytic_account = cls.env["account.analytic.account"].create(
{
"name": "Contracts",
}
)
contract_date = "2020-01-15"
cls.pricelist = cls.env["product.pricelist"].create(
{
"name": "pricelist for contract test",
}
)
cls.partner = cls.env["res.partner"].create(
{
"name": "partner test contract",
"property_product_pricelist": cls.pricelist.id,
}
)
cls.product_1 = cls.env.ref("product.product_product_1")
cls.product_1.taxes_id += cls.env["account.tax"].search(
[("type_tax_use", "=", "sale")], limit=1
)
cls.product_1.description_sale = "Test description sale"
cls.line_template_vals = {
"product_id": cls.product_1.id,
"name": "Test Contract Template",
"quantity": 1,
"uom_id": cls.product_1.uom_id.id,
"price_unit": 100,
"discount": 50,
"recurring_rule_type": "yearly",
"recurring_interval": 1,
}
cls.template_vals = {
"name": "Test Contract Template",
"contract_type": "sale",
"contract_line_ids": [
(0, 0, cls.line_template_vals),
],
}
cls.template = cls.env["contract.template"].create(cls.template_vals)
# For being sure of the applied price
cls.env["product.pricelist.item"].create(
{
"pricelist_id": cls.partner.property_product_pricelist.id,
"product_id": cls.product_1.id,
"compute_price": "formula",
"base": "list_price",
}
)
cls.contract = cls.env["contract.contract"].create(
{
"name": "Test Contract",
"partner_id": cls.partner.id,
"pricelist_id": cls.partner.property_product_pricelist.id,
"generation_type": "sale",
"sale_autoconfirm": False,
"group_id": cls.analytic_account.id,
}
)
cls.line_vals = {
# "contract_id": cls.contract.id,
# "product_id": cls.product_1.id,
"name": "Services from #START# to #END#",
"quantity": 1,
# "uom_id": cls.product_1.uom_id.id,
"price_unit": 100,
"discount": 50,
"recurring_rule_type": "monthly",
"recurring_interval": 1,
"date_start": "2020-01-01",
"recurring_next_date": "2020-01-15",
}
with Form(cls.contract) as contract_form, freeze_time(contract_date):
contract_form.contract_template_id = cls.template
with contract_form.contract_line_ids.new() as line_form:
line_form.product_id = cls.product_1
line_form.name = "Services from #START# to #END#"
line_form.quantity = 1
line_form.price_unit = 100.0
line_form.discount = 50
line_form.recurring_rule_type = "monthly"
line_form.recurring_interval = 1
line_form.date_start = "2020-01-15"
line_form.recurring_next_date = "2020-01-15"
cls.contract_line = cls.contract.contract_line_ids[1]
cls.contract2 = cls.env["contract.contract"].create(
{
"name": "Test Contract 2",
"generation_type": "sale",
"partner_id": cls.partner.id,
"pricelist_id": cls.partner.property_product_pricelist.id,
"contract_type": "purchase",
"contract_line_ids": [
(
0,
0,
{
"product_id": cls.product_1.id,
"name": "Services from #START# to #END#",
"quantity": 1,
"uom_id": cls.product_1.uom_id.id,
"price_unit": 100,
"discount": 50,
"recurring_rule_type": "monthly",
"recurring_interval": 1,
"date_start": "2018-02-15",
"recurring_next_date": "2018-02-22",
},
)
],
}
)

View File

@@ -2,138 +2,19 @@
# Copyright 2017 Pesol (<http://pesol.es>) # Copyright 2017 Pesol (<http://pesol.es>)
# Copyright 2017 Angel Moya <angel.moya@pesol.es> # Copyright 2017 Angel Moya <angel.moya@pesol.es>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from freezegun import freeze_time
from odoo import fields from odoo import fields
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
from odoo.tests import Form
from odoo.tests.common import SavepointCase from odoo.tests.common import SavepointCase
from .common import ContractSaleCommon
def to_date(date): def to_date(date):
return fields.Date.to_date(date) return fields.Date.to_date(date)
class TestContractSale(SavepointCase): class TestContractSale(ContractSaleCommon, SavepointCase):
# Use case : Prepare some data for current test case
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.analytic_account = cls.env["account.analytic.account"].create(
{
"name": "Contracts",
}
)
contract_date = "2020-01-15"
cls.pricelist = cls.env["product.pricelist"].create(
{
"name": "pricelist for contract test",
}
)
cls.partner = cls.env["res.partner"].create(
{
"name": "partner test contract",
"property_product_pricelist": cls.pricelist.id,
}
)
cls.product_1 = cls.env.ref("product.product_product_1")
cls.product_1.taxes_id += cls.env["account.tax"].search(
[("type_tax_use", "=", "sale")], limit=1
)
cls.product_1.description_sale = "Test description sale"
cls.line_template_vals = {
"product_id": cls.product_1.id,
"name": "Test Contract Template",
"quantity": 1,
"uom_id": cls.product_1.uom_id.id,
"price_unit": 100,
"discount": 50,
"recurring_rule_type": "yearly",
"recurring_interval": 1,
}
cls.template_vals = {
"name": "Test Contract Template",
"contract_type": "sale",
"contract_line_ids": [
(0, 0, cls.line_template_vals),
],
}
cls.template = cls.env["contract.template"].create(cls.template_vals)
# For being sure of the applied price
cls.env["product.pricelist.item"].create(
{
"pricelist_id": cls.partner.property_product_pricelist.id,
"product_id": cls.product_1.id,
"compute_price": "formula",
"base": "list_price",
}
)
cls.contract = cls.env["contract.contract"].create(
{
"name": "Test Contract",
"partner_id": cls.partner.id,
"pricelist_id": cls.partner.property_product_pricelist.id,
"generation_type": "sale",
"sale_autoconfirm": False,
"group_id": cls.analytic_account.id,
}
)
cls.line_vals = {
# "contract_id": cls.contract.id,
# "product_id": cls.product_1.id,
"name": "Services from #START# to #END#",
"quantity": 1,
# "uom_id": cls.product_1.uom_id.id,
"price_unit": 100,
"discount": 50,
"recurring_rule_type": "monthly",
"recurring_interval": 1,
"date_start": "2020-01-01",
"recurring_next_date": "2020-01-15",
}
with Form(cls.contract) as contract_form, freeze_time(contract_date):
contract_form.contract_template_id = cls.template
with contract_form.contract_line_ids.new() as line_form:
line_form.product_id = cls.product_1
line_form.name = "Services from #START# to #END#"
line_form.quantity = 1
line_form.price_unit = 100.0
line_form.discount = 50
line_form.recurring_rule_type = "monthly"
line_form.recurring_interval = 1
line_form.date_start = "2020-01-15"
line_form.recurring_next_date = "2020-01-15"
cls.contract_line = cls.contract.contract_line_ids[1]
cls.contract2 = cls.env["contract.contract"].create(
{
"name": "Test Contract 2",
"generation_type": "sale",
"partner_id": cls.partner.id,
"pricelist_id": cls.partner.property_product_pricelist.id,
"contract_type": "purchase",
"contract_line_ids": [
(
0,
0,
{
"product_id": cls.product_1.id,
"name": "Services from #START# to #END#",
"quantity": 1,
"uom_id": cls.product_1.uom_id.id,
"price_unit": 100,
"discount": 50,
"recurring_rule_type": "monthly",
"recurring_interval": 1,
"date_start": "2018-02-15",
"recurring_next_date": "2018-02-22",
},
)
],
}
)
def test_check_discount(self): def test_check_discount(self):
with self.assertRaises(ValidationError): with self.assertRaises(ValidationError):
self.contract_line.write({"discount": 120}) self.contract_line.write({"discount": 120})