From d1eb4bc29f2eb4a7099dc11a03c3cb17ab0e7af1 Mon Sep 17 00:00:00 2001 From: Roel Adriaans Date: Wed, 22 Aug 2018 18:56:34 +0200 Subject: [PATCH] [ADD] Contract section module (#177) --- contract_section/README.rst | 76 +++++++++++++++++++ contract_section/__init__.py | 1 + contract_section/__manifest__.py | 22 ++++++ contract_section/models/__init__.py | 4 + .../models/account_analytic_account.py | 17 +++++ .../models/account_analytic_contract_line.py | 11 +++ contract_section/readme/CONTRIBUTORS.rst | 1 + contract_section/readme/DESCRIPTION.rst | 1 + contract_section/readme/USAGE.rst | 2 + contract_section/tests/__init__.py | 4 + contract_section/tests/test_contract.py | 31 ++++++++ .../views/account_analytic_account.xml | 14 ++++ .../views/account_analytic_contract.xml | 14 ++++ 13 files changed, 198 insertions(+) create mode 100644 contract_section/README.rst create mode 100644 contract_section/__init__.py create mode 100644 contract_section/__manifest__.py create mode 100644 contract_section/models/__init__.py create mode 100644 contract_section/models/account_analytic_account.py create mode 100644 contract_section/models/account_analytic_contract_line.py create mode 100644 contract_section/readme/CONTRIBUTORS.rst create mode 100644 contract_section/readme/DESCRIPTION.rst create mode 100644 contract_section/readme/USAGE.rst create mode 100644 contract_section/tests/__init__.py create mode 100644 contract_section/tests/test_contract.py create mode 100644 contract_section/views/account_analytic_account.xml create mode 100644 contract_section/views/account_analytic_contract.xml diff --git a/contract_section/README.rst b/contract_section/README.rst new file mode 100644 index 00000000..18a6bf17 --- /dev/null +++ b/contract_section/README.rst @@ -0,0 +1,76 @@ +=================================================== +Contracts Management - Add section to invoice lines +=================================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| 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 +.. |badge2| image:: https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github + :target: https://github.com/OCA/contract/tree/11.0/contract_section + :alt: OCA/contract +.. |badge3| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/contract-11-0/contract-11-0-contract_section + :alt: Translate me on Weblate +.. |badge4| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/110/11.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| + +Enable the use of sections on the contract. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Create a contract with sections. When the invoice is created, the sections are +transfered to the invoice. + +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 +~~~~~~~ + +* Road-Support + +Contributors +~~~~~~~~~~~~ + +* Roel Adriaans + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +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_section/__init__.py b/contract_section/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/contract_section/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/contract_section/__manifest__.py b/contract_section/__manifest__.py new file mode 100644 index 00000000..1e1bd234 --- /dev/null +++ b/contract_section/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2018 Road-Support - Roel Adriaans +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Contracts Management - Add section to invoice lines', + 'version': '11.0.1.0.0', + 'category': 'Contract Management', + 'license': 'AGPL-3', + 'author': "Road-Support, " + "Odoo Community Association (OCA)", + 'website': 'https://github.com/oca/contract', + 'depends': [ + 'contract', + 'sale' + ], + 'data': [ + 'views/account_analytic_account.xml', + 'views/account_analytic_contract.xml', + ], + 'development_status': 'alpha', + 'installable': True, +} diff --git a/contract_section/models/__init__.py b/contract_section/models/__init__.py new file mode 100644 index 00000000..26d4f1ae --- /dev/null +++ b/contract_section/models/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import account_analytic_account +from . import account_analytic_contract_line diff --git a/contract_section/models/account_analytic_account.py b/contract_section/models/account_analytic_account.py new file mode 100644 index 00000000..348fd596 --- /dev/null +++ b/contract_section/models/account_analytic_account.py @@ -0,0 +1,17 @@ +# Copyright 2018 Road-Support - Roel Adriaans +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class AccountAnalyticAccount(models.Model): + _inherit = 'account.analytic.account' + + @api.model + def _prepare_invoice_line(self, line, invoice_id): + invoice_line_vals = super(AccountAnalyticAccount, self). \ + _prepare_invoice_line(line, invoice_id) + invoice_line_vals.update({ + 'layout_category_id': line.layout_category_id.id, + }) + return invoice_line_vals diff --git a/contract_section/models/account_analytic_contract_line.py b/contract_section/models/account_analytic_contract_line.py new file mode 100644 index 00000000..f1c2fc61 --- /dev/null +++ b/contract_section/models/account_analytic_contract_line.py @@ -0,0 +1,11 @@ +# Copyright 2018 Road-Support - Roel Adriaans +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class AccountAnalyticContractLine(models.Model): + _inherit = 'account.analytic.contract.line' + + layout_category_id = fields.Many2one('sale.layout_category', + string='Section') diff --git a/contract_section/readme/CONTRIBUTORS.rst b/contract_section/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..dd5b1e49 --- /dev/null +++ b/contract_section/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Roel Adriaans diff --git a/contract_section/readme/DESCRIPTION.rst b/contract_section/readme/DESCRIPTION.rst new file mode 100644 index 00000000..c6fe8a5b --- /dev/null +++ b/contract_section/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Enable the use of sections on the contract and the contract template. diff --git a/contract_section/readme/USAGE.rst b/contract_section/readme/USAGE.rst new file mode 100644 index 00000000..e89e70f4 --- /dev/null +++ b/contract_section/readme/USAGE.rst @@ -0,0 +1,2 @@ +Create a contract with sections. When the invoice is created, the sections are +transferred to the invoice. \ No newline at end of file diff --git a/contract_section/tests/__init__.py b/contract_section/tests/__init__.py new file mode 100644 index 00000000..a2982fdc --- /dev/null +++ b/contract_section/tests/__init__.py @@ -0,0 +1,4 @@ +# © 2016 Carlos Dauden +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_contract diff --git a/contract_section/tests/test_contract.py b/contract_section/tests/test_contract.py new file mode 100644 index 00000000..eab0d10c --- /dev/null +++ b/contract_section/tests/test_contract.py @@ -0,0 +1,31 @@ +# Copyright 2016 Tecnativa - Carlos Dauden +# Copyright 2017 Tecnativa - Pedro M. Baeza +# Copyright 2018 Roel Adriaans - roel@road-support.nl +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.addons.contract.tests.test_contract import TestContractBase + + +class TestContract(TestContractBase): + @classmethod + def setUpClass(cls): + # Reuse the tests from the contract module, but replace the + # contract line + super(TestContract, cls).setUpClass() + cls.acct_line.unlink() + cls.section = cls.env.ref('sale.sale_layout_cat_2') + cls.line_vals.update({ + 'layout_category_id': cls.section.id, + }) + cls.acct_line = cls.env['account.analytic.invoice.line'].create( + cls.line_vals, + ) + + def test_create_invoice(self): + """ Create contract with section""" + self.assertTrue(self.acct_line.layout_category_id) + self.contract.recurring_create_invoice() + invoice_id = self.env['account.invoice'].search( + [('contract_id', '=', self.contract.id)]) + self.assertEqual(invoice_id.invoice_line_ids.layout_category_id.id, + self.line_vals['layout_category_id']) diff --git a/contract_section/views/account_analytic_account.xml b/contract_section/views/account_analytic_account.xml new file mode 100644 index 00000000..4b6bdff1 --- /dev/null +++ b/contract_section/views/account_analytic_account.xml @@ -0,0 +1,14 @@ + + + + Account Analytic account Form View + account.analytic.account + + + + + + + + diff --git a/contract_section/views/account_analytic_contract.xml b/contract_section/views/account_analytic_contract.xml new file mode 100644 index 00000000..f998743e --- /dev/null +++ b/contract_section/views/account_analytic_contract.xml @@ -0,0 +1,14 @@ + + + + Account Analytic contract Form View + account.analytic.contract + + + + + + + +