diff --git a/contract_transmit_method/README.rst b/contract_transmit_method/README.rst new file mode 100644 index 000000000..bc8a5890b --- /dev/null +++ b/contract_transmit_method/README.rst @@ -0,0 +1,73 @@ +======================== +Contract Transmit Method +======================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |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_transmit_method + :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_transmit_method + :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| + +Set transmit method (email, post, portal, ...) in contracts and propagate it to invoices. + +**Table of contents** + +.. contents:: + :local: + +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 +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Souheil Bejaoui + +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_transmit_method/__init__.py b/contract_transmit_method/__init__.py new file mode 100644 index 000000000..0ee8b5073 --- /dev/null +++ b/contract_transmit_method/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import tests diff --git a/contract_transmit_method/__manifest__.py b/contract_transmit_method/__manifest__.py new file mode 100644 index 000000000..956997563 --- /dev/null +++ b/contract_transmit_method/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Contract Transmit Method", + "summary": """ + Set transmit method (email, post, portal, ...) in contracts and + propagate it to invoices.""", + "version": "12.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV," + "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/contract", + "depends": ["contract", "account_invoice_transmit_method"], + "data": ["views/contract_template.xml", "views/contract_contract.xml"], +} diff --git a/contract_transmit_method/models/__init__.py b/contract_transmit_method/models/__init__.py new file mode 100644 index 000000000..436ca3c39 --- /dev/null +++ b/contract_transmit_method/models/__init__.py @@ -0,0 +1,2 @@ +from . import contract_abstract +from . import contract_contract diff --git a/contract_transmit_method/models/contract_abstract.py b/contract_transmit_method/models/contract_abstract.py new file mode 100644 index 000000000..da91538f3 --- /dev/null +++ b/contract_transmit_method/models/contract_abstract.py @@ -0,0 +1,30 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ContractAbstractContract(models.AbstractModel): + + _inherit = "contract.abstract.contract" + + transmit_method_id = fields.Many2one( + comodel_name="transmit.method", + string="Transmission Method", + track_visibility="onchange", + ondelete="restrict", + ) + + @api.onchange("partner_id", "company_id") + def onchange_partner_transmit_method(self): + if self.partner_id and self.contract_type: + if self.contract_type == "sale": + self.transmit_method_id = ( + self.partner_id.customer_invoice_transmit_method_id.id + or False + ) + else: + self.transmit_method_id = ( + self.partner_id.supplier_invoice_transmit_method_id.id + or False + ) diff --git a/contract_transmit_method/models/contract_contract.py b/contract_transmit_method/models/contract_contract.py new file mode 100644 index 000000000..afee764fc --- /dev/null +++ b/contract_transmit_method/models/contract_contract.py @@ -0,0 +1,16 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class ContractContract(models.Model): + + _inherit = "contract.contract" + + @api.multi + def _prepare_invoice(self, date_invoice, journal=None): + invoice_vals = super()._prepare_invoice(date_invoice, journal=journal) + if self.transmit_method_id: + invoice_vals["transmit_method_id"] = self.transmit_method_id.id + return invoice_vals diff --git a/contract_transmit_method/readme/CONTRIBUTORS.rst b/contract_transmit_method/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..50e6298db --- /dev/null +++ b/contract_transmit_method/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Souheil Bejaoui diff --git a/contract_transmit_method/readme/DESCRIPTION.rst b/contract_transmit_method/readme/DESCRIPTION.rst new file mode 100644 index 000000000..0083a785c --- /dev/null +++ b/contract_transmit_method/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Set transmit method (email, post, portal, ...) in contracts and propagate it to invoices. diff --git a/contract_transmit_method/static/description/icon.png b/contract_transmit_method/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/contract_transmit_method/static/description/icon.png differ diff --git a/contract_transmit_method/static/description/index.html b/contract_transmit_method/static/description/index.html new file mode 100644 index 000000000..bfb5cfa2b --- /dev/null +++ b/contract_transmit_method/static/description/index.html @@ -0,0 +1,419 @@ + + + + + + +Contract Transmit Method + + + +
+

Contract Transmit Method

+ + +

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

+

Set transmit method (email, post, portal, …) in contracts and propagate it to invoices.

+

Table of contents

+ +
+

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

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

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.

+

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_transmit_method/tests/__init__.py b/contract_transmit_method/tests/__init__.py new file mode 100644 index 000000000..3c02082d6 --- /dev/null +++ b/contract_transmit_method/tests/__init__.py @@ -0,0 +1 @@ +from . import test_contract diff --git a/contract_transmit_method/tests/test_contract.py b/contract_transmit_method/tests/test_contract.py new file mode 100644 index 000000000..42fadb42a --- /dev/null +++ b/contract_transmit_method/tests/test_contract.py @@ -0,0 +1,31 @@ +# Copyright 2020 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.addons.contract.tests.test_contract import TestContractBase + + +class TestContract(TestContractBase): + def setUp(self): + super(TestContract, self).setUp() + self.transmit_method_mail = self.env.ref( + "account_invoice_transmit_method.mail" + ) + self.transmit_method_post = self.env.ref( + "account_invoice_transmit_method.post" + ) + self.contract.partner_id.customer_invoice_transmit_method_id = ( + self.transmit_method_mail + ) + + def test_onchange_partner_transmit_method(self): + self.assertFalse(self.contract.transmit_method_id) + self.contract.onchange_partner_transmit_method() + self.assertEqual( + self.contract.transmit_method_id, self.transmit_method_mail + ) + + def test_create_invoice(self): + self.assertFalse(self.contract.transmit_method_id) + self.contract.transmit_method_id = self.transmit_method_post + invoice = self.contract.recurring_create_invoice() + self.assertEqual(invoice.transmit_method_id, self.transmit_method_post) diff --git a/contract_transmit_method/views/contract_contract.xml b/contract_transmit_method/views/contract_contract.xml new file mode 100644 index 000000000..5c5cd1788 --- /dev/null +++ b/contract_transmit_method/views/contract_contract.xml @@ -0,0 +1,28 @@ + + + + + + + contract.contract + + + + + + + + + + contract.contract + + + + + + + + + + diff --git a/contract_transmit_method/views/contract_template.xml b/contract_transmit_method/views/contract_template.xml new file mode 100644 index 000000000..d9700040f --- /dev/null +++ b/contract_transmit_method/views/contract_template.xml @@ -0,0 +1,19 @@ + + + + + + + contract.template + + + + + + + + + + + diff --git a/oca_dependencies.txt b/oca_dependencies.txt index 49f042306..135c99a42 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -2,3 +2,4 @@ bank-payment queue field-service sale-reporting +account-invoicing diff --git a/setup/contract_transmit_method/odoo/addons/contract_transmit_method b/setup/contract_transmit_method/odoo/addons/contract_transmit_method new file mode 120000 index 000000000..8270ff76f --- /dev/null +++ b/setup/contract_transmit_method/odoo/addons/contract_transmit_method @@ -0,0 +1 @@ +../../../../contract_transmit_method \ No newline at end of file diff --git a/setup/contract_transmit_method/setup.py b/setup/contract_transmit_method/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/contract_transmit_method/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)