From 627e08d58d402af95b319ec29f09a68a19765875 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Fri, 22 Nov 2019 00:42:02 +0100 Subject: [PATCH] [MIG] contract_variable_qty_timesheet: Migration to 12.0 * Standard procedure * README by fragments * Promoted to Production/Stable and declared maintainers * Code adapted to v12 * Tests added --- contract_variable_qty_timesheet/README.rst | 83 +++- .../__manifest__.py | 5 +- .../data/contract_line_qty_formula_data.xml | 19 +- .../readme/CONTRIBUTORS.rst | 4 + .../readme/DESCRIPTION.rst | 3 + .../readme/USAGE.rst | 8 + .../static/description/index.html | 440 ++++++++++++++++++ .../tests/__init__.py | 3 + .../test_contract_variable_qty_timesheet.py | 96 ++++ 9 files changed, 626 insertions(+), 35 deletions(-) create mode 100644 contract_variable_qty_timesheet/readme/CONTRIBUTORS.rst create mode 100644 contract_variable_qty_timesheet/readme/DESCRIPTION.rst create mode 100644 contract_variable_qty_timesheet/readme/USAGE.rst create mode 100644 contract_variable_qty_timesheet/static/description/index.html create mode 100644 contract_variable_qty_timesheet/tests/__init__.py create mode 100644 contract_variable_qty_timesheet/tests/test_contract_variable_qty_timesheet.py diff --git a/contract_variable_qty_timesheet/README.rst b/contract_variable_qty_timesheet/README.rst index 4206a323..8acf44fb 100644 --- a/contract_variable_qty_timesheet/README.rst +++ b/contract_variable_qty_timesheet/README.rst @@ -1,14 +1,38 @@ -.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png - :target: https://www.gnu.org/licenses/agpl - :alt: License: AGPL-3 - =============================== Contract Variable Qty Timesheet =============================== +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png + :target: https://odoo-community.org/page/development-status + :alt: Production/Stable +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :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/12.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-12-0/contract-12-0-contract_variable_qty_timesheet + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/110/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + This module extends the functionality of contract_variable_quantity adding several variable quantity formulas to allow to invoice lines from Timesheet -(Analytic Lines) +(Analytic Lines). + +**Table of contents** + +.. contents:: + :local: Usage ===== @@ -22,47 +46,56 @@ To use this module, you need to: #. Select "Project Timesheets", "Tasks Timesheets" or "Analytic Same Product" depending on your need. - -.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas - :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/110/11.0 - - 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 smash it by providing detailed and welcomed feedback. +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. Credits ======= -Images ------- +Authors +~~~~~~~ -* Odoo Community Association: `Icon `_. +* Tecnativa Contributors ------------- +~~~~~~~~~~~~ * `Tecnativa `_: + * Carlos Dauden + * Pedro M. Baeza -Do not contact contributors directly about support or help with technical issues. +Maintainers +~~~~~~~~~~~ -Maintainer ----------- +This module is maintained by the OCA. .. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association :target: https://odoo-community.org -This module is maintained by the OCA. - OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -To contribute to this module, please visit https://odoo-community.org. +.. |maintainer-carlosdauden| image:: https://github.com/carlosdauden.png?size=40px + :target: https://github.com/carlosdauden + :alt: carlosdauden +.. |maintainer-pedrobaeza| image:: https://github.com/pedrobaeza.png?size=40px + :target: https://github.com/pedrobaeza + :alt: pedrobaeza + +Current `maintainers `__: + +|maintainer-carlosdauden| |maintainer-pedrobaeza| + +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 1071b7d7..3503e440 100644 --- a/contract_variable_qty_timesheet/__manifest__.py +++ b/contract_variable_qty_timesheet/__manifest__.py @@ -1,15 +1,17 @@ # Copyright 2018 Tecnativa - Carlos Dauden +# Copyright 2019 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { 'name': 'Contract Variable Qty Timesheet', 'summary': 'Add formula to invoice ', - 'version': '11.0.1.0.0', + 'version': '12.0.1.0.0', 'category': 'Contract Management', 'website': 'https://github.com/oca/contract', 'author': 'Tecnativa, ' 'Odoo Community Association (OCA)', 'license': 'AGPL-3', 'installable': True, + 'development_status': 'Production/Stable', 'depends': [ 'contract_variable_quantity', 'hr_timesheet', @@ -17,4 +19,5 @@ 'data': [ 'data/contract_line_qty_formula_data.xml', ], + 'maintainers': ['carlosdauden', 'pedrobaeza'], } 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 0b83b492..213d1074 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 @@ -1,16 +1,17 @@ Project Timesheets group = env['account.analytic.line'].read_group([ - ('account_id', '=', contract.id), + ('account_id', '=', line.analytic_account_id.id), ('product_id', '=', False), ('project_id', '!=', False), - ('date', '>=', line.date_from), - ('date', '<=', line.date_to), + ('date', '>=', period_first_date), + ('date', '<=', period_last_date), ], fields=['unit_amount'], groupby=[]) result = group and group[0]['unit_amount'] or 0.0 @@ -19,11 +20,11 @@ result = group and group[0]['unit_amount'] or 0.0 Task Timesheets group = env['account.analytic.line'].read_group([ - ('account_id', '=', contract.id), + ('account_id', '=', line.analytic_account_id.id), ('product_id', '=', False), ('task_id', '!=', False), - ('date', '>=', line.date_from), - ('date', '<=', line.date_to), + ('date', '>=', period_first_date), + ('date', '<=', period_last_date), ], fields=['unit_amount'], groupby=[]) result = group and group[0]['unit_amount'] or 0.0 @@ -32,10 +33,10 @@ result = group and group[0]['unit_amount'] or 0.0 Analytic Same Product group = env['account.analytic.line'].read_group([ - ('account_id', '=', contract.id), + ('account_id', '=', line.analytic_account_id.id), ('product_id', '=', line.product_id.id), - ('date', '>=', line.date_from), - ('date', '<=', line.date_to), + ('date', '>=', period_first_date), + ('date', '<=', period_last_date), ], fields=['unit_amount'], groupby=[]) result = group and group[0]['unit_amount'] or 0.0 diff --git a/contract_variable_qty_timesheet/readme/CONTRIBUTORS.rst b/contract_variable_qty_timesheet/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..e88bd67d --- /dev/null +++ b/contract_variable_qty_timesheet/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_: + + * Carlos Dauden + * Pedro M. Baeza diff --git a/contract_variable_qty_timesheet/readme/DESCRIPTION.rst b/contract_variable_qty_timesheet/readme/DESCRIPTION.rst new file mode 100644 index 00000000..0b238e9b --- /dev/null +++ b/contract_variable_qty_timesheet/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +This module extends the functionality of contract_variable_quantity adding +several variable quantity formulas to allow to invoice lines from Timesheet +(Analytic Lines). diff --git a/contract_variable_qty_timesheet/readme/USAGE.rst b/contract_variable_qty_timesheet/readme/USAGE.rst new file mode 100644 index 00000000..3ca264dc --- /dev/null +++ b/contract_variable_qty_timesheet/readme/USAGE.rst @@ -0,0 +1,8 @@ +To use this module, you need to: + +#. Go to Invoicing > Sales > 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". +#. Select "Project Timesheets", "Tasks Timesheets" or "Analytic Same Product" + depending on your need. diff --git a/contract_variable_qty_timesheet/static/description/index.html b/contract_variable_qty_timesheet/static/description/index.html new file mode 100644 index 00000000..b65106f8 --- /dev/null +++ b/contract_variable_qty_timesheet/static/description/index.html @@ -0,0 +1,440 @@ + + + + + + +Contract Variable Qty Timesheet + + + +
+

Contract Variable Qty Timesheet

+ + +

Production/Stable License: AGPL-3 OCA/contract Translate me on Weblate Try me on Runbot

+

This module extends the functionality of contract_variable_quantity adding +several variable quantity formulas to allow to invoice lines from Timesheet +(Analytic Lines).

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Invoicing > Sales > Contracts and select or create a new contract.
  2. +
  3. Check Generate recurring invoices automatically.
  4. +
  5. Add a new recurring invoicing line.
  6. +
  7. Select “Variable quantity” in column “Qty. type”.
  8. +
  9. Select “Project Timesheets”, “Tasks Timesheets” or “Analytic Same Product” +depending on your need.
  10. +
+
+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Carlos Dauden
    • +
    • Pedro M. Baeza
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainers:

+

carlosdauden pedrobaeza

+

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/__init__.py b/contract_variable_qty_timesheet/tests/__init__.py new file mode 100644 index 00000000..2bdf0812 --- /dev/null +++ b/contract_variable_qty_timesheet/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_contract_variable_qty_timesheet 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 new file mode 100644 index 00000000..bf08e65e --- /dev/null +++ b/contract_variable_qty_timesheet/tests/test_contract_variable_qty_timesheet.py @@ -0,0 +1,96 @@ +# Copyright 2019 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields +from odoo.tests import common + + +class TestContractVariableQtyTimesheet(common.SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner = cls.env['res.partner'].create({'name': 'Test partner'}) + cls.analytic_account = cls.env['account.analytic.account'].create({ + 'name': 'Test analytic account'}) + cls.contract = cls.env['contract.contract'].create({ + 'name': 'Test contract', + 'partner_id': cls.partner.id}) + cls.product = cls.env['product.product'].create({ + 'name': 'Test product'}) + contract_line_vals = { + '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', + 'qty_formula_id': cls.env.ref( + 'contract_variable_qty_timesheet.' + 'contract_line_qty_formula_project_timesheet').id, + } + 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, + }) + cls.task = cls.env['project.task'].create({ + 'project_id': cls.project.id, + 'name': 'Test task', + }) + + def _contract_invoicing(self, contract): + date_ref = fields.Date.from_string('2020-01-01') + contract._recurring_create_invoice(date_ref) + return contract._get_related_invoices() + + def _create_analytic_line(self, project, task, date, product, unit_amount): + return self.env['account.analytic.line'].create({ + 'account_id': self.analytic_account.id, + 'project_id': project and project.id, + 'task_id': task and task.id, + 'name': 'Test %s %s' % (date, unit_amount), + 'date': date, + 'product_id': product and product.id, + 'unit_amount': unit_amount, + }) + + 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) + 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' + ).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) + 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' + ).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) + self.assertEqual(len(invoice.invoice_line_ids), 1) + self.assertAlmostEqual(invoice.invoice_line_ids.quantity, 3)