mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[MIG] contract_variable_qty_timesheet: Migration to 16.0
This commit is contained in:
@@ -2,44 +2,70 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields
|
||||
from odoo.tests import common
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestContractVariableQtyTimesheet(common.TransactionCase):
|
||||
class TestContractVariableQtyTimesheet(TransactionCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.partner = cls.env["res.partner"].create({"name": "Test partner"})
|
||||
cls.company = cls.env.company
|
||||
cls.partner = cls.env["res.partner"].create(
|
||||
{"name": "Test partner", "company_id": cls.company.id}
|
||||
)
|
||||
cls.plan = cls.env["account.analytic.plan"].create({"name": "Test Plan"})
|
||||
cls.analytic_account = cls.env["account.analytic.account"].create(
|
||||
{"name": "Test analytic account"}
|
||||
{
|
||||
"name": "Test analytic account",
|
||||
"plan_id": cls.plan.id,
|
||||
"company_id": cls.company.id,
|
||||
}
|
||||
)
|
||||
cls.contract = cls.env["contract.contract"].create(
|
||||
{"name": "Test contract", "partner_id": cls.partner.id}
|
||||
{
|
||||
"name": "Test contract",
|
||||
"partner_id": cls.partner.id,
|
||||
"company_id": cls.company.id,
|
||||
}
|
||||
)
|
||||
cls.product = cls.env["product.product"].create(
|
||||
{"name": "Test product", "company_id": cls.company.id}
|
||||
)
|
||||
cls.employee = cls.env["hr.employee"].create(
|
||||
{
|
||||
"name": "Test Employee",
|
||||
"company_id": cls.company.id,
|
||||
}
|
||||
)
|
||||
cls.product = cls.env["product.product"].create({"name": "Test product"})
|
||||
contract_line_vals = {
|
||||
"name": "Test contract line",
|
||||
"contract_id": cls.contract.id,
|
||||
"analytic_account_id": cls.analytic_account.id,
|
||||
"product_id": cls.product.id,
|
||||
"uom_id": cls.product.uom_id.id,
|
||||
"name": "Test line contract",
|
||||
"recurring_interval": 1,
|
||||
"recurring_rule_type": "monthly",
|
||||
"recurring_invoicing_type": "pre-paid",
|
||||
"date_start": "2020-01-01",
|
||||
"recurring_next_date": "2020-01-01",
|
||||
"qty_type": "variable",
|
||||
"date_end": "2020-12-31",
|
||||
"product_id": cls.product.id,
|
||||
"qty_formula_id": cls.env.ref(
|
||||
"contract_variable_qty_timesheet."
|
||||
"contract_line_qty_formula_project_timesheet"
|
||||
"contract_variable_qty_timesheet.contract_line_qty_formula_project_timesheet"
|
||||
).id,
|
||||
"sequence": 10,
|
||||
"state": "in-progress",
|
||||
"company_id": cls.company.id,
|
||||
"qty_type": "variable",
|
||||
"analytic_distribution": {str(cls.analytic_account.id): 100},
|
||||
}
|
||||
cls.contract_line = cls.env["contract.line"].create(contract_line_vals)
|
||||
cls.project = cls.env["project.project"].create(
|
||||
{"name": "Test project", "analytic_account_id": cls.analytic_account.id}
|
||||
{
|
||||
"name": "Test project",
|
||||
"analytic_account_id": cls.analytic_account.id,
|
||||
"company_id": cls.company.id,
|
||||
}
|
||||
)
|
||||
cls.task = cls.env["project.task"].create(
|
||||
{"project_id": cls.project.id, "name": "Test task"}
|
||||
{
|
||||
"project_id": cls.project.id,
|
||||
"name": "Test task",
|
||||
"company_id": cls.company.id,
|
||||
}
|
||||
)
|
||||
|
||||
def _contract_invoicing(self, contract):
|
||||
@@ -53,38 +79,38 @@ class TestContractVariableQtyTimesheet(common.TransactionCase):
|
||||
"account_id": self.analytic_account.id,
|
||||
"project_id": project and project.id,
|
||||
"task_id": task and task.id,
|
||||
"name": "Test {} {}".format(date, unit_amount),
|
||||
"name": f"Test {date} {unit_amount}",
|
||||
"date": date,
|
||||
"product_id": product and product.id,
|
||||
"unit_amount": unit_amount,
|
||||
"employee_id": self.employee.id,
|
||||
"company_id": self.company.id,
|
||||
}
|
||||
)
|
||||
|
||||
def test_project_timesheet(self):
|
||||
self._create_analytic_line(self.project, self.task, "2020-01-01", False, 3)
|
||||
self._create_analytic_line(False, False, "2020-01-01", False, 1)
|
||||
invoice = self._contract_invoicing(self.contract)
|
||||
invoice = self.contract._recurring_create_invoice()
|
||||
self.assertEqual(len(invoice.invoice_line_ids), 1)
|
||||
self.assertAlmostEqual(invoice.invoice_line_ids.quantity, 3)
|
||||
|
||||
def test_task_timesheet(self):
|
||||
self.contract_line.qty_formula_id = self.env.ref(
|
||||
"contract_variable_qty_timesheet."
|
||||
"contract_line_qty_formula_task_timesheet"
|
||||
"contract_variable_qty_timesheet.contract_line_qty_formula_task_timesheet"
|
||||
).id
|
||||
self._create_analytic_line(self.project, self.task, "2020-01-01", False, 3)
|
||||
self._create_analytic_line(self.project, False, "2020-01-01", False, 1)
|
||||
invoice = self._contract_invoicing(self.contract)
|
||||
invoice = self.contract._recurring_create_invoice()
|
||||
self.assertEqual(len(invoice.invoice_line_ids), 1)
|
||||
self.assertAlmostEqual(invoice.invoice_line_ids.quantity, 3)
|
||||
|
||||
def test_same_product(self):
|
||||
self.contract_line.qty_formula_id = self.env.ref(
|
||||
"contract_variable_qty_timesheet."
|
||||
"contract_line_qty_formula_analytic_same_product"
|
||||
"contract_variable_qty_timesheet.contract_line_qty_formula_analytic_same_product"
|
||||
).id
|
||||
self._create_analytic_line(False, False, "2020-01-01", self.product, 3)
|
||||
self._create_analytic_line(self.project, False, "2020-01-01", False, 1)
|
||||
invoice = self._contract_invoicing(self.contract)
|
||||
invoice = self.contract._recurring_create_invoice()
|
||||
self.assertEqual(len(invoice.invoice_line_ids), 1)
|
||||
self.assertAlmostEqual(invoice.invoice_line_ids.quantity, 3)
|
||||
|
||||
Reference in New Issue
Block a user