diff --git a/contract_variable_qty_timesheet/README.rst b/contract_variable_qty_timesheet/README.rst index ba500aa2bb..b04b5cfa7a 100644 --- a/contract_variable_qty_timesheet/README.rst +++ b/contract_variable_qty_timesheet/README.rst @@ -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". @@ -76,11 +76,16 @@ Contributors - Carlos Dauden - Pedro M. Baeza - Carolina Fernandez + - Juan José Seguí - `Guadaltech `__: - Fernando La Chica +- `Coopdevs Treball `__: + + - Daniel Palomar + Maintainers ----------- @@ -100,10 +105,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 `__: -|maintainer-carlosdauden| |maintainer-pedrobaeza| +|maintainer-carlosdauden| |maintainer-pedrobaeza| |maintainer-danypr92| This module is part of the `OCA/contract `_ project on GitHub. diff --git a/contract_variable_qty_timesheet/__manifest__.py b/contract_variable_qty_timesheet/__manifest__.py index 7448dd8cc6..074fdc8f91 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": "17.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 6ee6d1636a..6be69b9e94 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.md b/contract_variable_qty_timesheet/readme/CONTRIBUTORS.md index 4aeeb11c96..54515a8ead 100644 --- a/contract_variable_qty_timesheet/readme/CONTRIBUTORS.md +++ b/contract_variable_qty_timesheet/readme/CONTRIBUTORS.md @@ -2,5 +2,8 @@ - Carlos Dauden - Pedro M. Baeza - Carolina Fernandez + - Juan José Seguí - [Guadaltech](https://www.guadaltech.es): - Fernando La Chica \<\> +- [Coopdevs Treball](https://coopdevs.coop): + - Daniel Palomar \<\> diff --git a/contract_variable_qty_timesheet/readme/USAGE.md b/contract_variable_qty_timesheet/readme/USAGE.md index 219321b1b1..86bfc71949 100644 --- a/contract_variable_qty_timesheet/readme/USAGE.md +++ b/contract_variable_qty_timesheet/readme/USAGE.md @@ -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". 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 0000000000..207e615334 --- /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 0000000000..a63d633e86 --- /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 722e21ef57..0e10a80c3d 100644 --- a/contract_variable_qty_timesheet/static/description/index.html +++ b/contract_variable_qty_timesheet/static/description/index.html @@ -390,8 +390,8 @@

Contract Variable Qty Timesheet

Usage

To use this module, you need to:

    -
  1. Go to Invoicing > Sales > Contracts and select or create a new -contract.
  2. +
  3. Go to Invoicing > Customers > Customer Contracts and select or create +a new contract.
  4. Check Generate recurring invoices automatically.
  5. Add a new recurring invoicing line.
  6. Select “Variable quantity” in column “Qty. type”.
  7. @@ -422,12 +422,17 @@

    Contributors

  8. Carlos Dauden
  9. Pedro M. Baeza
  10. Carolina Fernandez
  11. +
  12. Juan José Seguí
  13. Guadaltech:
  14. +
  15. Coopdevs Treball: +
  16. @@ -440,7 +445,7 @@

    Maintainers

    mission is to support the collaborative development of Odoo features and promote its widespread use.

    Current maintainers:

    -

    carlosdauden pedrobaeza

    +

    carlosdauden pedrobaeza danypr92

    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 1a5ce3a2e2..6f1f682123 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): @@ -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)