Skip to content

Commit

Permalink
[MIG] contract_variable_qty_timesheet: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjosesegui-tecnativa committed Aug 20, 2024
1 parent 691583b commit 1a8d012
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 42 deletions.
13 changes: 10 additions & 3 deletions contract_variable_qty_timesheet/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ Usage

To use this module, you need to:

1. Go to Invoicing > Sales > Contracts and select or create a new
contract.
1. Go to Invoicing > Customers > Customer Contracts and select or create
a new contract.
2. Check *Generate recurring invoices automatically*.
3. Add a new recurring invoicing line.
4. Select "Variable quantity" in column "Qty. type".
Expand Down Expand Up @@ -81,6 +81,10 @@ Contributors

- Fernando La Chica <fernandolachica@gmail.com>

- `Coopdevs Treball <https://coopdevs.coop>`__:

- Daniel Palomar <daniel.palomar@coopdevs.org>

Maintainers
-----------

Expand All @@ -100,10 +104,13 @@ promote its widespread use.
.. |maintainer-pedrobaeza| image:: https://github.com/pedrobaeza.png?size=40px
:target: https://github.com/pedrobaeza
:alt: pedrobaeza
.. |maintainer-danypr92| image:: https://github.com/danypr92.png?size=40px
:target: https://github.com/danypr92
:alt: danypr92

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-carlosdauden| |maintainer-pedrobaeza|
|maintainer-carlosdauden| |maintainer-pedrobaeza| |maintainer-danypr92|

This module is part of the `OCA/contract <https://github.com/OCA/contract/tree/17.0/contract_variable_qty_timesheet>`_ project on GitHub.

Expand Down
4 changes: 2 additions & 2 deletions contract_variable_qty_timesheet/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
{
"name": "Contract Variable Qty Timesheet",
"summary": "Add formula to invoice ",
"version": "15.0.1.0.0",
"version": "17.0.1.0.0",
"category": "Contract Management",
"website": "https://github.com/OCA/contract",
"author": "Tecnativa, " "Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["contract_variable_quantity", "hr_timesheet"],
"data": ["data/contract_line_qty_formula_data.xml"],
"maintainers": ["carlosdauden", "pedrobaeza"],
"maintainers": ["carlosdauden", "pedrobaeza", "danypr92"],
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
model="contract.line.qty.formula"
>
<field name='name'>Project Timesheets</field>
<field name="code">group = env['account.analytic.line'].read_group([
('account_id', '=', line.analytic_account_id.id),
<field name="code">
account_analytic_ids = line.analytic_distribution and [int(_id) for _id in list(line.analytic_distribution.keys())] or []
group = env['account.analytic.line'].read_group([
('account_id', 'in', account_analytic_ids),
('product_id', '=', False),
('project_id', '!=', False),
('date', '&gt;=', period_first_date),
Expand All @@ -23,8 +25,10 @@ result = group and group[0]['unit_amount'] or 0.0
model="contract.line.qty.formula"
>
<field name='name'>Task Timesheets</field>
<field name="code">group = env['account.analytic.line'].read_group([
('account_id', '=', line.analytic_account_id.id),
<field name="code">
account_analytic_ids = line.analytic_distribution and [int(_id) for _id in list(line.analytic_distribution.keys())] or []
group = env['account.analytic.line'].read_group([
('account_id', 'in', account_analytic_ids),
('product_id', '=', False),
('task_id', '!=', False),
('date', '&gt;=', period_first_date),
Expand All @@ -38,8 +42,10 @@ result = group and group[0]['unit_amount'] or 0.0
model="contract.line.qty.formula"
>
<field name='name'>Analytic Same Product</field>
<field name="code">group = env['account.analytic.line'].read_group([
('account_id', '=', line.analytic_account_id.id),
<field name="code">
account_analytic_ids = line.analytic_distribution and [int(_id) for _id in list(line.analytic_distribution.keys())] or []
group = env['account.analytic.line'].read_group([
('account_id', 'in', account_analytic_ids),
('product_id', '=', line.product_id.id),
('date', '&gt;=', period_first_date),
('date', '&lt;=', period_last_date),
Expand Down
2 changes: 2 additions & 0 deletions contract_variable_qty_timesheet/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
- Carolina Fernandez
- [Guadaltech](https://www.guadaltech.es):
- Fernando La Chica \<<fernandolachica@gmail.com>\>
- [Coopdevs Treball](https://coopdevs.coop):
- Daniel Palomar \<<daniel.palomar@coopdevs.org>\>
4 changes: 2 additions & 2 deletions contract_variable_qty_timesheet/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
To use this module, you need to:

1. Go to Invoicing \> Sales \> Contracts and select or create a new
contract.
1. Go to Invoicing \> Customers \> Customer Contracts and select or
create a new contract.
2. Check *Generate recurring invoices automatically*.
3. Add a new recurring invoicing line.
4. Select "Variable quantity" in column "Qty. type".
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# addons listed in this file are ignored by
# setuptools-odoo-make-default (one addon per line)
2 changes: 2 additions & 0 deletions contract_variable_qty_timesheet/setup/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
To learn more about this directory, please visit
https://pypi.python.org/pypi/setuptools-odoo
10 changes: 7 additions & 3 deletions contract_variable_qty_timesheet/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ <h1 class="title">Contract Variable Qty Timesheet</h1>
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<p>To use this module, you need to:</p>
<ol class="arabic simple">
<li>Go to Invoicing &gt; Sales &gt; Contracts and select or create a new
contract.</li>
<li>Go to Invoicing &gt; Customers &gt; Customer Contracts and select or create
a new contract.</li>
<li>Check <em>Generate recurring invoices automatically</em>.</li>
<li>Add a new recurring invoicing line.</li>
<li>Select “Variable quantity” in column “Qty. type”.</li>
Expand Down Expand Up @@ -428,6 +428,10 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Fernando La Chica &lt;<a class="reference external" href="mailto:fernandolachica&#64;gmail.com">fernandolachica&#64;gmail.com</a>&gt;</li>
</ul>
</li>
<li><a class="reference external" href="https://coopdevs.coop">Coopdevs Treball</a>:<ul>
<li>Daniel Palomar &lt;<a class="reference external" href="mailto:daniel.palomar&#64;coopdevs.org">daniel.palomar&#64;coopdevs.org</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -440,7 +444,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/carlosdauden"><img alt="carlosdauden" src="https://github.com/carlosdauden.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/pedrobaeza"><img alt="pedrobaeza" src="https://github.com/pedrobaeza.png?size=40px" /></a></p>
<p><a class="reference external image-reference" href="https://github.com/carlosdauden"><img alt="carlosdauden" src="https://github.com/carlosdauden.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/pedrobaeza"><img alt="pedrobaeza" src="https://github.com/pedrobaeza.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/danypr92"><img alt="danypr92" src="https://github.com/danypr92.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/contract/tree/17.0/contract_variable_qty_timesheet">OCA/contract</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -57,34 +83,34 @@ def _create_analytic_line(self, project, task, date, product, 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)

0 comments on commit 1a8d012

Please sign in to comment.