diff --git a/contract_variable_qty_timesheet/README.rst b/contract_variable_qty_timesheet/README.rst
index 42af0abd3..a7eb6697c 100644
--- a/contract_variable_qty_timesheet/README.rst
+++ b/contract_variable_qty_timesheet/README.rst
@@ -17,13 +17,13 @@ Contract Variable Qty Timesheet
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github
- :target: https://github.com/OCA/contract/tree/15.0/contract_variable_qty_timesheet
+ :target: https://github.com/OCA/contract/tree/16.0/contract_variable_qty_timesheet
:alt: OCA/contract
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
- :target: https://translation.odoo-community.org/projects/contract-15-0/contract-15-0-contract_variable_qty_timesheet
+ :target: https://translation.odoo-community.org/projects/contract-16-0/contract-16-0-contract_variable_qty_timesheet
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
- :target: https://runboat.odoo-community.org/builds?repo=OCA/contract&target_branch=15.0
+ :target: https://runboat.odoo-community.org/builds?repo=OCA/contract&target_branch=16.0
:alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -55,7 +55,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues `_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
-`feedback `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -80,6 +80,10 @@ Contributors
* Fernando La Chica
+* `Coopdevs Treball `_:
+
+ * Daniel Palomar
+
Maintainers
~~~~~~~~~~~
@@ -99,11 +103,14 @@ 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 `__:
-|maintainer-carlosdauden| |maintainer-pedrobaeza|
+|maintainer-carlosdauden| |maintainer-pedrobaeza| |maintainer-danypr92|
-This module is part of the `OCA/contract `_ project on GitHub.
+This module is part of the `OCA/contract `_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/contract_variable_qty_timesheet/__manifest__.py b/contract_variable_qty_timesheet/__manifest__.py
index 7448dd8cc..431a39eb7 100644
--- a/contract_variable_qty_timesheet/__manifest__.py
+++ b/contract_variable_qty_timesheet/__manifest__.py
@@ -5,7 +5,7 @@
{
"name": "Contract Variable Qty Timesheet",
"summary": "Add formula to invoice ",
- "version": "15.0.1.0.0",
+ "version": "16.0.1.0.0",
"category": "Contract Management",
"website": "https://github.com/OCA/contract",
"author": "Tecnativa, " "Odoo Community Association (OCA)",
@@ -13,5 +13,5 @@
"installable": True,
"depends": ["contract_variable_quantity", "hr_timesheet"],
"data": ["data/contract_line_qty_formula_data.xml"],
- "maintainers": ["carlosdauden", "pedrobaeza"],
+ "maintainers": ["carlosdauden", "pedrobaeza", "danypr92"],
}
diff --git a/contract_variable_qty_timesheet/data/contract_line_qty_formula_data.xml b/contract_variable_qty_timesheet/data/contract_line_qty_formula_data.xml
index 6ee6d1636..6be69b9e9 100644
--- a/contract_variable_qty_timesheet/data/contract_line_qty_formula_data.xml
+++ b/contract_variable_qty_timesheet/data/contract_line_qty_formula_data.xml
@@ -8,8 +8,10 @@
model="contract.line.qty.formula"
>
Project Timesheets
- group = env['account.analytic.line'].read_group([
- ('account_id', '=', line.analytic_account_id.id),
+
+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', '>=', period_first_date),
@@ -23,8 +25,10 @@ result = group and group[0]['unit_amount'] or 0.0
model="contract.line.qty.formula"
>
Task Timesheets
- group = env['account.analytic.line'].read_group([
- ('account_id', '=', line.analytic_account_id.id),
+
+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', '>=', period_first_date),
@@ -38,8 +42,10 @@ result = group and group[0]['unit_amount'] or 0.0
model="contract.line.qty.formula"
>
Analytic Same Product
- group = env['account.analytic.line'].read_group([
- ('account_id', '=', line.analytic_account_id.id),
+
+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', '>=', period_first_date),
('date', '<=', period_last_date),
diff --git a/contract_variable_qty_timesheet/readme/CONTRIBUTORS.rst b/contract_variable_qty_timesheet/readme/CONTRIBUTORS.rst
index e58d51e7b..b87de8df6 100644
--- a/contract_variable_qty_timesheet/readme/CONTRIBUTORS.rst
+++ b/contract_variable_qty_timesheet/readme/CONTRIBUTORS.rst
@@ -7,3 +7,7 @@
* `Guadaltech `_:
* Fernando La Chica
+
+* `Coopdevs Treball `_:
+
+ * Daniel Palomar
diff --git a/contract_variable_qty_timesheet/readme/USAGE.rst b/contract_variable_qty_timesheet/readme/USAGE.rst
index 3ca264dc0..9e73d24c6 100644
--- a/contract_variable_qty_timesheet/readme/USAGE.rst
+++ b/contract_variable_qty_timesheet/readme/USAGE.rst
@@ -1,6 +1,6 @@
To use this module, you need to:
-#. Go to Invoicing > Sales > Contracts and select or create a new contract.
+#. Go to Invoicing > Customers > Customer Contracts and select or create a new contract.
#. Check *Generate recurring invoices automatically*.
#. Add a new recurring invoicing line.
#. Select "Variable quantity" in column "Qty. type".
diff --git a/contract_variable_qty_timesheet/setup/.setuptools-odoo-make-default-ignore b/contract_variable_qty_timesheet/setup/.setuptools-odoo-make-default-ignore
new file mode 100644
index 000000000..207e61533
--- /dev/null
+++ b/contract_variable_qty_timesheet/setup/.setuptools-odoo-make-default-ignore
@@ -0,0 +1,2 @@
+# addons listed in this file are ignored by
+# setuptools-odoo-make-default (one addon per line)
diff --git a/contract_variable_qty_timesheet/setup/README b/contract_variable_qty_timesheet/setup/README
new file mode 100644
index 000000000..a63d633e8
--- /dev/null
+++ b/contract_variable_qty_timesheet/setup/README
@@ -0,0 +1,2 @@
+To learn more about this directory, please visit
+https://pypi.python.org/pypi/setuptools-odoo
diff --git a/contract_variable_qty_timesheet/static/description/index.html b/contract_variable_qty_timesheet/static/description/index.html
index aa81aa59b..ee708dc18 100644
--- a/contract_variable_qty_timesheet/static/description/index.html
+++ b/contract_variable_qty_timesheet/static/description/index.html
@@ -1,4 +1,3 @@
-
@@ -369,7 +368,7 @@ ul.auto-toc {
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e5498feee850c8ae2cc09cbae0c07393069f065c83bca8823127e9eec40bbe1b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-

+

This module extends the functionality of contract_variable_quantity adding
several variable quantity formulas to allow to invoice lines from Timesheet
(Analytic Lines).
@@ -403,7 +402,7 @@ depending on your need.
Bugs are tracked on GitHub Issues.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
-feedback.
+feedback.
Do not contact contributors directly about support or help with technical issues.
@@ -437,8 +440,8 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
mission is to support the collaborative development of Odoo features and
promote its widespread use.
Current maintainers:
-

-
This module is part of the OCA/contract project on GitHub.
+

+
This module is part of the OCA/contract project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/contract_variable_qty_timesheet/tests/test_contract_variable_qty_timesheet.py b/contract_variable_qty_timesheet/tests/test_contract_variable_qty_timesheet.py
index 684a9e406..6f1f68212 100644
--- a/contract_variable_qty_timesheet/tests/test_contract_variable_qty_timesheet.py
+++ b/contract_variable_qty_timesheet/tests/test_contract_variable_qty_timesheet.py
@@ -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)