diff --git a/contract_sale/views/contract.xml b/contract_sale/views/contract.xml index 1bf893b9..98317050 100644 --- a/contract_sale/views/contract.xml +++ b/contract_sale/views/contract.xml @@ -4,7 +4,7 @@ diff --git a/contract_sale_payment_mode/README.rst b/contract_sale_payment_mode/README.rst new file mode 100644 index 00000000..b1a70bc1 --- /dev/null +++ b/contract_sale_payment_mode/README.rst @@ -0,0 +1,73 @@ +========================== +Contract Sale Payment Mode +========================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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_sale_payment_mode + :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_sale_payment_mode + :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 manages the payment mode from sale order to contract. + +**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 +~~~~~~~~~~~~ + +* Thomas Binsfeld + +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_sale_payment_mode/__init__.py b/contract_sale_payment_mode/__init__.py new file mode 100644 index 00000000..0ee8b507 --- /dev/null +++ b/contract_sale_payment_mode/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import tests diff --git a/contract_sale_payment_mode/__manifest__.py b/contract_sale_payment_mode/__manifest__.py new file mode 100644 index 00000000..1aa7187c --- /dev/null +++ b/contract_sale_payment_mode/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Contract Sale Payment Mode', + 'summary': """ + This addon manages payment mode from sale order to contract.""", + 'version': '12.0.1.0.0', + 'license': 'AGPL-3', + 'author': 'ACSONE SA/NV,Odoo Community Association (OCA)', + 'website': 'https://acsone.eu/', + 'depends': [ + # OCA/bank-payment + 'account_payment_sale', + # OCA/contract + 'product_contract', + ], + 'data': [ + ], + 'demo': [ + ], +} diff --git a/contract_sale_payment_mode/models/__init__.py b/contract_sale_payment_mode/models/__init__.py new file mode 100644 index 00000000..6aacb753 --- /dev/null +++ b/contract_sale_payment_mode/models/__init__.py @@ -0,0 +1 @@ +from . import sale_order diff --git a/contract_sale_payment_mode/models/sale_order.py b/contract_sale_payment_mode/models/sale_order.py new file mode 100644 index 00000000..95a4a79b --- /dev/null +++ b/contract_sale_payment_mode/models/sale_order.py @@ -0,0 +1,16 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + @api.multi + def _prepare_contract_value(self, contract_template): + self.ensure_one() + vals = super(SaleOrder, self)._prepare_contract_value( + contract_template) + vals['payment_mode_id'] = self.payment_mode_id.id + return vals diff --git a/contract_sale_payment_mode/readme/CONTRIBUTORS.rst b/contract_sale_payment_mode/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..e90fe382 --- /dev/null +++ b/contract_sale_payment_mode/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Thomas Binsfeld diff --git a/contract_sale_payment_mode/readme/DESCRIPTION.rst b/contract_sale_payment_mode/readme/DESCRIPTION.rst new file mode 100644 index 00000000..3dd53cdb --- /dev/null +++ b/contract_sale_payment_mode/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module manages the payment mode from sale order to contract. diff --git a/contract_sale_payment_mode/static/description/icon.png b/contract_sale_payment_mode/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/contract_sale_payment_mode/static/description/icon.png differ diff --git a/contract_sale_payment_mode/static/description/index.html b/contract_sale_payment_mode/static/description/index.html new file mode 100644 index 00000000..058c25aa --- /dev/null +++ b/contract_sale_payment_mode/static/description/index.html @@ -0,0 +1,419 @@ + + + + + + +Contract Sale Payment Mode + + + +
+

Contract Sale Payment Mode

+ + +

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

+

This module manages the payment mode from sale order to contract.

+

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_sale_payment_mode/tests/__init__.py b/contract_sale_payment_mode/tests/__init__.py new file mode 100644 index 00000000..6f699d0d --- /dev/null +++ b/contract_sale_payment_mode/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_order diff --git a/contract_sale_payment_mode/tests/test_sale_order.py b/contract_sale_payment_mode/tests/test_sale_order.py new file mode 100644 index 00000000..661d8efa --- /dev/null +++ b/contract_sale_payment_mode/tests/test_sale_order.py @@ -0,0 +1,21 @@ +# Copyright 2018 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +from odoo.addons.product_contract.tests.test_sale_order import TestSaleOrder + + +class TestSaleOrderPaymentMode(TestSaleOrder): + def setUp(self): + super(TestSaleOrderPaymentMode, self).setUp() + self.payment_mode = self.env['account.payment.mode'].search( + [], limit=1 + ) + self.sale.payment_mode_id = self.payment_mode + + def test_action_confirm_with_payment_mode(self): + self.test_action_confirm() + self.assertEqual( + self.sale.order_line.mapped('contract_id.payment_mode_id'), + self.payment_mode, + ) diff --git a/product_contract/README.rst b/product_contract/README.rst new file mode 100644 index 00000000..6319dcf5 --- /dev/null +++ b/product_contract/README.rst @@ -0,0 +1,66 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +================ +Product Contract +================ + +This module adds support for products to be linked to contract templates. +It also adds functionality to automatically create a contract, from the template, +when a ``sale.order`` contains a product that implements a contract. + +Usage +===== + +To use this module, you need to: + +#. Go to Sales -> Products and select or create a product. +#. Check "Is a contract" and select the contract template related to the + product + +.. 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/10.0 + +Known issues / Roadmap +====================== + +* None + +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. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Ted Salmon + + +Maintainer +---------- + +.. 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. diff --git a/product_contract/__init__.py b/product_contract/__init__.py new file mode 100644 index 00000000..c6339a00 --- /dev/null +++ b/product_contract/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/product_contract/__manifest__.py b/product_contract/__manifest__.py new file mode 100644 index 00000000..c495c726 --- /dev/null +++ b/product_contract/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2017 LasLabs Inc. +# Copyright 2018 ACSONE SA/NV. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'Recurring - Product Contract', + 'version': '12.0.2.0.0', + 'category': 'Contract Management', + 'license': 'AGPL-3', + 'author': "LasLabs, " + "ACSONE SA/NV, " + "Odoo Community Association (OCA)", + 'website': 'https://github.com/oca/contract', + 'depends': ['product', 'contract_sale'], + 'data': [ + 'views/res_config_settings.xml', + 'views/contract.xml', + 'views/product_template.xml', + 'views/sale_order.xml' + ], + 'installable': True, + 'application': False, + "external_dependencies": {"python": ["dateutil"]}, +} diff --git a/product_contract/i18n/de.po b/product_contract/i18n/de.po new file mode 100644 index 00000000..00697a55 --- /dev/null +++ b/product_contract/i18n/de.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-04-27 02:40+0000\n" +"PO-Revision-Date: 2017-04-27 02:40+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: German (https://www.transifex.com/oca/teams/23907/de/)\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_sale_order_line_contract_id +msgid "Contract" +msgstr "Vertrag" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_contract_template_id +#: model:ir.model.fields,field_description:product_contract.field_product_template_contract_template_id +msgid "Contract Template" +msgstr "" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_is_contract +#: model:ir.model.fields,field_description:product_contract.field_product_template_is_contract +msgid "Is a contract" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_product_template +msgid "Product Template" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order_line +msgid "Sales Order Line" +msgstr "" diff --git a/product_contract/i18n/es.po b/product_contract/i18n/es.po new file mode 100644 index 00000000..1fd8a1a1 --- /dev/null +++ b/product_contract/i18n/es.po @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +# Translators: +# OCA Transbot , 2017 +# enjolras , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-02-10 03:15+0000\n" +"PO-Revision-Date: 2018-02-10 03:15+0000\n" +"Last-Translator: enjolras , 2018\n" +"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_sale_order_line_contract_id +msgid "Contract" +msgstr "Contrato" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_contract_template_id +#: model:ir.model.fields,field_description:product_contract.field_product_template_contract_template_id +msgid "Contract Template" +msgstr "Plantilla de contrato" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_is_contract +#: model:ir.model.fields,field_description:product_contract.field_product_template_is_contract +msgid "Is a contract" +msgstr "Es un contrato" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_product_template +msgid "Product Template" +msgstr "Plantilla de producto" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order +msgid "Sales Order" +msgstr "Pedido de venta" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order_line +msgid "Sales Order Line" +msgstr "Línea de pedido de venta" diff --git a/product_contract/i18n/fi.po b/product_contract/i18n/fi.po new file mode 100644 index 00000000..3467c265 --- /dev/null +++ b/product_contract/i18n/fi.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +# Translators: +# Jarmo Kortetjärvi , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-03-10 01:44+0000\n" +"PO-Revision-Date: 2018-03-10 01:44+0000\n" +"Last-Translator: Jarmo Kortetjärvi , 2018\n" +"Language-Team: Finnish (https://www.transifex.com/oca/teams/23907/fi/)\n" +"Language: fi\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_sale_order_line_contract_id +msgid "Contract" +msgstr "Contract" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_contract_template_id +#: model:ir.model.fields,field_description:product_contract.field_product_template_contract_template_id +msgid "Contract Template" +msgstr "Sopimusmalli" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_is_contract +#: model:ir.model.fields,field_description:product_contract.field_product_template_is_contract +msgid "Is a contract" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_product_template +msgid "Product Template" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order_line +msgid "Sales Order Line" +msgstr "" diff --git a/product_contract/i18n/fr.po b/product_contract/i18n/fr.po new file mode 100644 index 00000000..59f399b3 --- /dev/null +++ b/product_contract/i18n/fr.po @@ -0,0 +1,53 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +# Translators: +# leemannd , 2017 +# David BEAL, 2018 +# Fabien Bourgeois , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-05-19 02:01+0000\n" +"PO-Revision-Date: 2018-05-19 02:01+0000\n" +"Last-Translator: Fabien Bourgeois , 2018\n" +"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_sale_order_line_contract_id +msgid "Contract" +msgstr "Contrat" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_contract_template_id +#: model:ir.model.fields,field_description:product_contract.field_product_template_contract_template_id +msgid "Contract Template" +msgstr "Modèle de contrat" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_is_contract +#: model:ir.model.fields,field_description:product_contract.field_product_template_is_contract +msgid "Is a contract" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_product_template +msgid "Product Template" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order +msgid "Sales Order" +msgstr "Vente" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order_line +msgid "Sales Order Line" +msgstr "" diff --git a/product_contract/i18n/hi_IN.po b/product_contract/i18n/hi_IN.po new file mode 100644 index 00000000..e55f00ea --- /dev/null +++ b/product_contract/i18n/hi_IN.po @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +# Translators: +# Ashish Deshmukh , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-08-17 01:05+0000\n" +"PO-Revision-Date: 2017-08-17 01:05+0000\n" +"Last-Translator: Ashish Deshmukh , 2017\n" +"Language-Team: Hindi (India) (https://www.transifex.com/oca/teams/23907/" +"hi_IN/)\n" +"Language: hi_IN\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_sale_order_line_contract_id +msgid "Contract" +msgstr "अनुबंध" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_contract_template_id +#: model:ir.model.fields,field_description:product_contract.field_product_template_contract_template_id +msgid "Contract Template" +msgstr "अनुबंध टेम्पलेट" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_is_contract +#: model:ir.model.fields,field_description:product_contract.field_product_template_is_contract +msgid "Is a contract" +msgstr "एक अनुबंध है" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_product_template +msgid "Product Template" +msgstr "प्रोडक्ट टेम्पलेट" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order +msgid "Sales Order" +msgstr "बिक्री आदेश" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order_line +msgid "Sales Order Line" +msgstr "बिक्री आदेश पंक्ति" diff --git a/product_contract/i18n/hr.po b/product_contract/i18n/hr.po new file mode 100644 index 00000000..5ac93789 --- /dev/null +++ b/product_contract/i18n/hr.po @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +# Translators: +# Bole , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-02-10 03:15+0000\n" +"PO-Revision-Date: 2018-02-10 03:15+0000\n" +"Last-Translator: Bole , 2017\n" +"Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n" +"Language: hr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_sale_order_line_contract_id +msgid "Contract" +msgstr "Ugovor" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_contract_template_id +#: model:ir.model.fields,field_description:product_contract.field_product_template_contract_template_id +msgid "Contract Template" +msgstr "Predložak ugovora" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_is_contract +#: model:ir.model.fields,field_description:product_contract.field_product_template_is_contract +msgid "Is a contract" +msgstr "Je ugovor" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_product_template +msgid "Product Template" +msgstr "Predložak proizvoda" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order +msgid "Sales Order" +msgstr "Ponuda" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order_line +msgid "Sales Order Line" +msgstr "Stavka ponude" diff --git a/product_contract/i18n/hr_HR.po b/product_contract/i18n/hr_HR.po new file mode 100644 index 00000000..2766a631 --- /dev/null +++ b/product_contract/i18n/hr_HR.po @@ -0,0 +1,54 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +# Translators: +# OCA Transbot , 2017 +# Bole , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-06-17 01:39+0000\n" +"PO-Revision-Date: 2017-06-17 01:39+0000\n" +"Last-Translator: Bole , 2017\n" +"Language-Team: Croatian (Croatia) (https://www.transifex.com/oca/teams/23907/" +"hr_HR/)\n" +"Language: hr_HR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_sale_order_line_contract_id +msgid "Contract" +msgstr "Ugovor" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_contract_template_id +#: model:ir.model.fields,field_description:product_contract.field_product_template_contract_template_id +msgid "Contract Template" +msgstr "Predložak ugovora" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_is_contract +#: model:ir.model.fields,field_description:product_contract.field_product_template_is_contract +msgid "Is a contract" +msgstr "Je ugovor" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_product_template +msgid "Product Template" +msgstr "Predložak proizvoda" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order +msgid "Sales Order" +msgstr "Prodajni nalog" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order_line +msgid "Sales Order Line" +msgstr "Stavka prodajnog naloga" diff --git a/product_contract/i18n/it.po b/product_contract/i18n/it.po new file mode 100644 index 00000000..010897f6 --- /dev/null +++ b/product_contract/i18n/it.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +# Translators: +# Lorenzo Battistini , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-04-27 02:40+0000\n" +"PO-Revision-Date: 2017-04-27 02:40+0000\n" +"Last-Translator: Lorenzo Battistini , 2017\n" +"Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_sale_order_line_contract_id +msgid "Contract" +msgstr "Contratto" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_contract_template_id +#: model:ir.model.fields,field_description:product_contract.field_product_template_contract_template_id +msgid "Contract Template" +msgstr "Template di contratto" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_is_contract +#: model:ir.model.fields,field_description:product_contract.field_product_template_is_contract +msgid "Is a contract" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_product_template +msgid "Product Template" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order_line +msgid "Sales Order Line" +msgstr "" diff --git a/product_contract/i18n/nl.po b/product_contract/i18n/nl.po new file mode 100644 index 00000000..4c8db3eb --- /dev/null +++ b/product_contract/i18n/nl.po @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +# Translators: +# Erwin van der Ploeg , 2017 +# lfreeke , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-06 03:17+0000\n" +"PO-Revision-Date: 2018-01-06 03:17+0000\n" +"Last-Translator: lfreeke , 2018\n" +"Language-Team: Dutch (https://www.transifex.com/oca/teams/23907/nl/)\n" +"Language: nl\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_sale_order_line_contract_id +msgid "Contract" +msgstr "Contract" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_contract_template_id +#: model:ir.model.fields,field_description:product_contract.field_product_template_contract_template_id +msgid "Contract Template" +msgstr "Contractsjabloon" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_is_contract +#: model:ir.model.fields,field_description:product_contract.field_product_template_is_contract +msgid "Is a contract" +msgstr "Is een contract" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_product_template +msgid "Product Template" +msgstr "Productsjabloon" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order +msgid "Sales Order" +msgstr "Verkooporder" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order_line +msgid "Sales Order Line" +msgstr "Verkooporderregel" diff --git a/product_contract/i18n/nl_NL.po b/product_contract/i18n/nl_NL.po new file mode 100644 index 00000000..517781e3 --- /dev/null +++ b/product_contract/i18n/nl_NL.po @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +# Translators: +# Peter Hageman , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-06-09 01:10+0000\n" +"PO-Revision-Date: 2017-06-09 01:10+0000\n" +"Last-Translator: Peter Hageman , 2017\n" +"Language-Team: Dutch (Netherlands) (https://www.transifex.com/oca/" +"teams/23907/nl_NL/)\n" +"Language: nl_NL\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_sale_order_line_contract_id +msgid "Contract" +msgstr "Contract" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_contract_template_id +#: model:ir.model.fields,field_description:product_contract.field_product_template_contract_template_id +msgid "Contract Template" +msgstr "Contractsjabloon" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_is_contract +#: model:ir.model.fields,field_description:product_contract.field_product_template_is_contract +msgid "Is a contract" +msgstr "Is een contract" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_product_template +msgid "Product Template" +msgstr "Productsjabloon" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order +msgid "Sales Order" +msgstr "Verkooporder" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order_line +msgid "Sales Order Line" +msgstr "Verkooporderregel" diff --git a/product_contract/i18n/product_contract.pot b/product_contract/i18n/product_contract.pot new file mode 100644 index 00000000..154aed4d --- /dev/null +++ b/product_contract/i18n/product_contract.pot @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_sale_order_line_contract_id +msgid "Contract" +msgstr "" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_contract_template_id +#: model:ir.model.fields,field_description:product_contract.field_product_template_contract_template_id +msgid "Contract Template" +msgstr "" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_is_contract +#: model:ir.model.fields,field_description:product_contract.field_product_template_is_contract +msgid "Is a contract" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_product_template +msgid "Product Template" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order_line +msgid "Sales Order Line" +msgstr "" + diff --git a/product_contract/i18n/pt.po b/product_contract/i18n/pt.po new file mode 100644 index 00000000..0ca84dea --- /dev/null +++ b/product_contract/i18n/pt.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +# Translators: +# Pedro Castro Silva , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-07-15 01:24+0000\n" +"PO-Revision-Date: 2017-07-15 01:24+0000\n" +"Last-Translator: Pedro Castro Silva , 2017\n" +"Language-Team: Portuguese (https://www.transifex.com/oca/teams/23907/pt/)\n" +"Language: pt\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_sale_order_line_contract_id +msgid "Contract" +msgstr "Contrato" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_contract_template_id +#: model:ir.model.fields,field_description:product_contract.field_product_template_contract_template_id +msgid "Contract Template" +msgstr "Modelo de Contrato" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_is_contract +#: model:ir.model.fields,field_description:product_contract.field_product_template_is_contract +msgid "Is a contract" +msgstr "É um Contrato" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_product_template +msgid "Product Template" +msgstr "Modelo de Produto" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order +msgid "Sales Order" +msgstr "Encomenda de Venda" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order_line +msgid "Sales Order Line" +msgstr "Linha de Encomenda de Venda" diff --git a/product_contract/i18n/pt_BR.po b/product_contract/i18n/pt_BR.po new file mode 100644 index 00000000..75fd5d80 --- /dev/null +++ b/product_contract/i18n/pt_BR.po @@ -0,0 +1,53 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +# Translators: +# OCA Transbot , 2017 +# falexandresilva , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-06-13 02:40+0000\n" +"PO-Revision-Date: 2017-06-13 02:40+0000\n" +"Last-Translator: falexandresilva , 2017\n" +"Language-Team: Portuguese (Brazil) (https://www.transifex.com/oca/" +"teams/23907/pt_BR/)\n" +"Language: pt_BR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_sale_order_line_contract_id +msgid "Contract" +msgstr "Contrato" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_contract_template_id +#: model:ir.model.fields,field_description:product_contract.field_product_template_contract_template_id +msgid "Contract Template" +msgstr "" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_is_contract +#: model:ir.model.fields,field_description:product_contract.field_product_template_is_contract +msgid "Is a contract" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_product_template +msgid "Product Template" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order +msgid "Sales Order" +msgstr "Pedido de compras" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order_line +msgid "Sales Order Line" +msgstr "" diff --git a/product_contract/i18n/ru.po b/product_contract/i18n/ru.po new file mode 100644 index 00000000..bc7bdcbb --- /dev/null +++ b/product_contract/i18n/ru.po @@ -0,0 +1,53 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +# Translators: +# nek, 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-03-17 03:26+0000\n" +"PO-Revision-Date: 2018-03-17 03:26+0000\n" +"Last-Translator: nek, 2018\n" +"Language-Team: Russian (https://www.transifex.com/oca/teams/23907/ru/)\n" +"Language: ru\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n" +"%100>=11 && n%100<=14)? 2 : 3);\n" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_sale_order_line_contract_id +msgid "Contract" +msgstr "Договор" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_contract_template_id +#: model:ir.model.fields,field_description:product_contract.field_product_template_contract_template_id +msgid "Contract Template" +msgstr "Шаблон Договора" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_is_contract +#: model:ir.model.fields,field_description:product_contract.field_product_template_is_contract +msgid "Is a contract" +msgstr "Это Договор" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_product_template +msgid "Product Template" +msgstr "Шаблон Продукта" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order_line +msgid "Sales Order Line" +msgstr "" diff --git a/product_contract/i18n/tr.po b/product_contract/i18n/tr.po new file mode 100644 index 00000000..03f07329 --- /dev/null +++ b/product_contract/i18n/tr.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +# Translators: +# Ediz Duman , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-04-21 01:48+0000\n" +"PO-Revision-Date: 2018-04-21 01:48+0000\n" +"Last-Translator: Ediz Duman , 2017\n" +"Language-Team: Turkish (https://www.transifex.com/oca/teams/23907/tr/)\n" +"Language: tr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_sale_order_line_contract_id +msgid "Contract" +msgstr "Sözleşme" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_contract_template_id +#: model:ir.model.fields,field_description:product_contract.field_product_template_contract_template_id +msgid "Contract Template" +msgstr "Sözleşme Şablonu" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_is_contract +#: model:ir.model.fields,field_description:product_contract.field_product_template_is_contract +msgid "Is a contract" +msgstr "Sözleşmeli" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_product_template +msgid "Product Template" +msgstr "Ürün Şablonu" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order +msgid "Sales Order" +msgstr "Satış Siparişi" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order_line +msgid "Sales Order Line" +msgstr "Satış Sipariş Satırı" diff --git a/product_contract/i18n/tr_TR.po b/product_contract/i18n/tr_TR.po new file mode 100644 index 00000000..7c93e6e4 --- /dev/null +++ b/product_contract/i18n/tr_TR.po @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +# Translators: +# Ediz Duman , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-04-27 02:40+0000\n" +"PO-Revision-Date: 2017-04-27 02:40+0000\n" +"Last-Translator: Ediz Duman , 2017\n" +"Language-Team: Turkish (Turkey) (https://www.transifex.com/oca/teams/23907/" +"tr_TR/)\n" +"Language: tr_TR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_sale_order_line_contract_id +msgid "Contract" +msgstr "Sözleşme" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_contract_template_id +#: model:ir.model.fields,field_description:product_contract.field_product_template_contract_template_id +msgid "Contract Template" +msgstr "" + +#. module: product_contract +#: model:ir.model.fields,field_description:product_contract.field_product_product_is_contract +#: model:ir.model.fields,field_description:product_contract.field_product_template_is_contract +msgid "Is a contract" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_product_template +msgid "Product Template" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: product_contract +#: model:ir.model,name:product_contract.model_sale_order_line +msgid "Sales Order Line" +msgstr "" diff --git a/product_contract/migrations/12.0.2.0.0/pre-migration.py b/product_contract/migrations/12.0.2.0.0/pre-migration.py new file mode 100644 index 00000000..ca2542a4 --- /dev/null +++ b/product_contract/migrations/12.0.2.0.0/pre-migration.py @@ -0,0 +1,18 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import logging + +from openupgradelib import openupgrade + +_logger = logging.getLogger(__name__) + + +def migrate(cr, version): + xmlids_to_rename = [ + ( + 'product_contract.account_analytic_account_recurring_form_form', + 'product_contract.contract_contract_customer_form_view', + ) + ] + openupgrade.rename_xmlids(cr, xmlids_to_rename) diff --git a/product_contract/models/__init__.py b/product_contract/models/__init__.py new file mode 100644 index 00000000..c16c95bb --- /dev/null +++ b/product_contract/models/__init__.py @@ -0,0 +1,11 @@ +# Copyright 2017 LasLabs Inc. +# Copyright 2018 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import contract +from . import contract_line +from . import product_template +from . import sale_order +from . import sale_order_line +from . import res_company +from . import res_config_settings diff --git a/product_contract/models/contract.py b/product_contract/models/contract.py new file mode 100644 index 00000000..e7aeb5b3 --- /dev/null +++ b/product_contract/models/contract.py @@ -0,0 +1,39 @@ +# Copyright 2018 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models +from odoo.exceptions import AccessError +from odoo.tools.translate import _ + + +class ContractContract(models.Model): + _inherit = 'contract.contract' + + sale_order_count = fields.Integer(compute="_compute_sale_order_count") + + @api.depends('contract_line_ids') + def _compute_sale_order_count(self): + for rec in self: + try: + order_count = len( + rec.contract_line_ids.mapped( + 'sale_order_line_id.order_id' + ) + ) + except AccessError: + order_count = 0 + rec.sale_order_count = order_count + + @api.multi + def action_view_sales_orders(self): + self.ensure_one() + orders = self.contract_line_ids.mapped( + 'sale_order_line_id.order_id' + ) + return { + "name": _("Sales Orders"), + "view_mode": "tree,form", + "res_model": "sale.order", + "type": "ir.actions.act_window", + "domain": [("id", "in", orders.ids)], + } diff --git a/product_contract/models/contract_line.py b/product_contract/models/contract_line.py new file mode 100644 index 00000000..2a85f73e --- /dev/null +++ b/product_contract/models/contract_line.py @@ -0,0 +1,64 @@ +# Copyright 2017 LasLabs Inc. +# Copyright 2018 ACSONE SA/NV. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo import api, fields, models + + +class ContractLine(models.Model): + _inherit = 'contract.line' + _rec_name = 'display_name' + + sale_order_line_id = fields.Many2one( + comodel_name="sale.order.line", + string="Sale Order Line", + required=False, + copy=False, + ) + display_name = fields.Char(compute='_compute_display_name_2') + + @api.multi + def _prepare_invoice_line(self, invoice_id=False): + res = super(ContractLine, self)._prepare_invoice_line( + invoice_id=invoice_id + ) + if self.sale_order_line_id and res: + res['sale_line_ids'] = [(6, 0, [self.sale_order_line_id.id])] + return res + + @api.multi + def _get_auto_renew_rule_type(self): + """monthly last day don't make sense for auto_renew_rule_type""" + self.ensure_one() + if self.recurring_rule_type == "monthlylastday": + return "monthly" + return self.recurring_rule_type + + @api.onchange('product_id') + def _onchange_product_id_recurring_info(self): + for rec in self: + rec.date_start = fields.Date.today() + if rec.product_id.is_contract: + rec.recurring_rule_type = rec.product_id.recurring_rule_type + rec.recurring_invoicing_type = ( + rec.product_id.recurring_invoicing_type + ) + rec.recurring_interval = 1 + rec.is_auto_renew = rec.product_id.is_auto_renew + rec.auto_renew_interval = rec.product_id.default_qty + rec.auto_renew_rule_type = rec._get_auto_renew_rule_type() + rec.termination_notice_interval = ( + rec.product_id.termination_notice_interval + ) + rec.termination_notice_rule_type = ( + rec.product_id.termination_notice_rule_type + ) + + @api.depends('name', 'date_start') + def _compute_display_name_2(self): + # FIXME: _compute_display_name depends on rec_name (display_name) + # and this trigger a WARNING : display_name depends on itself; + # please fix its decorator + for rec in self: + rec.display_name = ("%s - %s") % (rec.date_start, rec.name) diff --git a/product_contract/models/product_template.py b/product_contract/models/product_template.py new file mode 100644 index 00000000..1ca3f75e --- /dev/null +++ b/product_contract/models/product_template.py @@ -0,0 +1,59 @@ +# Copyright 2017 LasLabs Inc. +# Copyright 2018 ACSONE SA/NV. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + is_contract = fields.Boolean('Is a contract') + contract_template_id = fields.Many2one( + comodel_name='contract.template', string='Contract Template' + ) + default_qty = fields.Integer(string="Default Quantity", default=1) + recurring_rule_type = fields.Selection( + [ + ('daily', 'Day(s)'), + ('weekly', 'Week(s)'), + ('monthly', 'Month(s)'), + ('monthlylastday', 'Month(s) last day'), + ('yearly', 'Year(s)'), + ], + default='monthly', + string='Invoice Every', + help="Specify Interval for automatic invoice generation.", + ) + recurring_invoicing_type = fields.Selection( + [('pre-paid', 'Pre-paid'), ('post-paid', 'Post-paid')], + default='pre-paid', + string='Invoicing type', + help="Specify if process date is 'from' or 'to' invoicing date", + ) + is_auto_renew = fields.Boolean(string="Auto Renew", default=False) + termination_notice_interval = fields.Integer( + default=1, string='Termination Notice Before' + ) + termination_notice_rule_type = fields.Selection( + [('daily', 'Day(s)'), ('weekly', 'Week(s)'), ('monthly', 'Month(s)')], + default='monthly', + string='Termination Notice type', + ) + + @api.onchange('is_contract') + def _change_is_contract(self): + """ Clear the relation to contract_template_id when downgrading + product from contract + """ + if not self.is_contract: + self.contract_template_id = False + + @api.constrains('is_contract', 'type') + def _check_contract_product_type(self): + """ + Contract product should be service type + """ + if self.is_contract and self.type != 'service': + raise ValidationError(_("Contract product should be service type")) diff --git a/product_contract/models/res_company.py b/product_contract/models/res_company.py new file mode 100644 index 00000000..ab0c760c --- /dev/null +++ b/product_contract/models/res_company.py @@ -0,0 +1,14 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResCompany(models.Model): + + _inherit = 'res.company' + + create_contract_at_sale_order_confirmation = fields.Boolean( + string="Automatically Create Contracts At Sale Order Confirmation", + default=True, + ) diff --git a/product_contract/models/res_config_settings.py b/product_contract/models/res_config_settings.py new file mode 100644 index 00000000..803b095a --- /dev/null +++ b/product_contract/models/res_config_settings.py @@ -0,0 +1,14 @@ +# Copyright 2019 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + + _inherit = 'res.config.settings' + + create_contract_at_sale_order_confirmation = fields.Boolean( + related="company_id.create_contract_at_sale_order_confirmation", + readonly=False + ) diff --git a/product_contract/models/sale_order.py b/product_contract/models/sale_order.py new file mode 100644 index 00000000..58f08249 --- /dev/null +++ b/product_contract/models/sale_order.py @@ -0,0 +1,118 @@ +# Copyright 2017 LasLabs Inc. +# Copyright 2018 ACSONE SA/NV. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, api, models + + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + is_contract = fields.Boolean( + string='Is a contract', compute='_compute_is_contract' + ) + contract_count = fields.Integer(compute='_compute_contract_count') + need_contract_creation = fields.Boolean( + compute='_compute_need_contract_creation' + ) + + @api.depends('order_line.contract_id', 'state') + def _compute_need_contract_creation(self): + for rec in self: + if rec.state in ('sale', 'done'): + line_to_create_contract = rec.order_line.filtered( + lambda r: not r.contract_id and r.product_id.is_contract + ) + line_to_update_contract = rec.order_line.filtered( + lambda r: r.contract_id + and r.product_id.is_contract + and r + not in r.contract_id.contract_line_ids.mapped( + 'sale_order_line_id' + ) + ) + if line_to_create_contract or line_to_update_contract: + rec.need_contract_creation = True + + @api.depends('order_line') + def _compute_is_contract(self): + self.is_contract = any(self.order_line.mapped('is_contract')) + + @api.multi + def _prepare_contract_value(self, contract_template): + self.ensure_one() + return { + 'name': '{template_name}: {sale_name}'.format( + template_name=contract_template.name, sale_name=self.name + ), + 'partner_id': self.partner_id.id, + 'contract_template_id': contract_template.id, + 'user_id': self.user_id.id, + 'payment_term_id': self.payment_term_id.id, + 'fiscal_position_id': self.fiscal_position_id.id, + 'invoice_partner_id': self.partner_invoice_id.id, + } + + @api.multi + def action_create_contract(self): + contract_model = self.env['contract.contract'] + contracts = self.env['contract.contract'] + for rec in self.filtered('is_contract'): + line_to_create_contract = rec.order_line.filtered( + lambda r: not r.contract_id and r.product_id.is_contract + ) + line_to_update_contract = rec.order_line.filtered( + lambda r: r.contract_id + and r.product_id.is_contract + and r + not in r.contract_id.contract_line_ids.mapped( + 'sale_order_line_id' + ) + ) + for contract_template in line_to_create_contract.mapped( + 'product_id.contract_template_id' + ): + order_lines = line_to_create_contract.filtered( + lambda r, template=contract_template: + r.product_id.contract_template_id == template + ) + contract = contract_model.create( + rec._prepare_contract_value(contract_template) + ) + contracts |= contract + contract._onchange_contract_template_id() + order_lines.create_contract_line(contract) + order_lines.write({'contract_id': contract.id}) + for line in line_to_update_contract: + line.create_contract_line(line.contract_id) + return contracts + + @api.multi + def action_confirm(self): + """ If we have a contract in the order, set it up """ + self.filtered( + lambda order: ( + order.company_id.create_contract_at_sale_order_confirmation + ) + ).action_create_contract() + return super(SaleOrder, self).action_confirm() + + @api.multi + @api.depends("order_line") + def _compute_contract_count(self): + for rec in self: + rec.contract_count = len(rec.order_line.mapped('contract_id')) + + @api.multi + def action_show_contracts(self): + self.ensure_one() + action = self.env.ref( + "contract.action_customer_contract" + ).read()[0] + contracts = ( + self.env['contract.line'] + .search([('sale_order_line_id', 'in', self.order_line.ids)]) + .mapped('contract_id') + ) + action["domain"] = [("id", "in", contracts.ids)] + return action diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py new file mode 100644 index 00000000..6f55f5c4 --- /dev/null +++ b/product_contract/models/sale_order_line.py @@ -0,0 +1,248 @@ +# Copyright 2017 LasLabs Inc. +# Copyright 2017 ACSONE SA/NV. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from dateutil.relativedelta import relativedelta +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError + + +class SaleOrderLine(models.Model): + _inherit = 'sale.order.line' + + is_contract = fields.Boolean( + string='Is a contract', related="product_id.is_contract" + ) + contract_id = fields.Many2one( + comodel_name='contract.contract', string='Contract', copy=False + ) + contract_template_id = fields.Many2one( + comodel_name='contract.template', + string='Contract Template', + related='product_id.product_tmpl_id.contract_template_id', + readonly=True, + ) + recurring_rule_type = fields.Selection( + [ + ('daily', 'Day(s)'), + ('weekly', 'Week(s)'), + ('monthly', 'Month(s)'), + ('monthlylastday', 'Month(s) last day'), + ('yearly', 'Year(s)'), + ], + default='monthly', + string='Invoice Every', + copy=False, + ) + recurring_invoicing_type = fields.Selection( + [('pre-paid', 'Pre-paid'), ('post-paid', 'Post-paid')], + default='pre-paid', + string='Invoicing type', + help="Specify if process date is 'from' or 'to' invoicing date", + copy=False, + ) + date_start = fields.Date(string='Date Start') + date_end = fields.Date(string='Date End') + + contract_line_id = fields.Many2one( + comodel_name="contract.line", + string="Contract Line to replace", + required=False, + copy=False, + ) + + @api.multi + def _get_auto_renew_rule_type(self): + """monthly last day don't make sense for auto_renew_rule_type""" + self.ensure_one() + if self.recurring_rule_type == "monthlylastday": + return "monthly" + return self.recurring_rule_type + + @api.onchange('product_id') + def onchange_product(self): + contract_line_model = self.env['contract.line'] + for rec in self: + if rec.product_id.is_contract: + rec.product_uom_qty = rec.product_id.default_qty + rec.recurring_rule_type = rec.product_id.recurring_rule_type + rec.recurring_invoicing_type = ( + rec.product_id.recurring_invoicing_type + ) + rec.date_start = rec.date_start or fields.Date.today() + + rec.date_end = ( + rec.date_start + + contract_line_model.get_relative_delta( + rec._get_auto_renew_rule_type(), + int(rec.product_uom_qty), + ) + - relativedelta(days=1) + ) + + @api.onchange('date_start', 'product_uom_qty', 'recurring_rule_type') + def onchange_date_start(self): + contract_line_model = self.env['contract.line'] + for rec in self.filtered('product_id.is_contract'): + if not rec.date_start: + rec.date_end = False + else: + rec.date_end = ( + rec.date_start + + contract_line_model.get_relative_delta( + rec._get_auto_renew_rule_type(), + int(rec.product_uom_qty), + ) + - relativedelta(days=1) + ) + + @api.multi + def _prepare_contract_line_values( + self, contract, predecessor_contract_line_id=False + ): + """ + :param contract: related contract + :param predecessor_contract_line_id: contract line to replace id + :return: new contract line dict + """ + self.ensure_one() + recurring_next_date = self.env[ + 'contract.line' + ]._compute_first_recurring_next_date( + self.date_start or fields.Date.today(), + self.recurring_invoicing_type, + self.recurring_rule_type, + 1, + ) + termination_notice_interval = ( + self.product_id.termination_notice_interval + ) + termination_notice_rule_type = ( + self.product_id.termination_notice_rule_type + ) + return { + 'sequence': self.sequence, + 'product_id': self.product_id.id, + 'name': self.name, + # The quantity on the generated contract line is 1, as it + # correspond to the most common use cases: + # - quantity on the SO line = number of periods sold and unit + # price the price of one period, so the + # total amount of the SO corresponds to the planned value + # of the contract; in this case the quantity on the contract + # line must be 1 + # - quantity on the SO line = number of hours sold, + # automatic invoicing of the actual hours through a variable + # quantity formula, in which case the quantity on the contract + # line is not used + # Other use cases are easy to implement by overriding this method. + 'quantity': 1.0, + 'uom_id': self.product_uom.id, + 'price_unit': self.price_unit, + 'discount': self.discount, + 'date_end': self.date_end, + 'date_start': self.date_start or fields.Date.today(), + 'recurring_next_date': recurring_next_date, + 'recurring_interval': 1, + 'recurring_invoicing_type': self.recurring_invoicing_type, + 'recurring_rule_type': self.recurring_rule_type, + 'is_auto_renew': self.product_id.is_auto_renew, + 'auto_renew_interval': self.product_uom_qty, + 'auto_renew_rule_type': self._get_auto_renew_rule_type(), + 'termination_notice_interval': termination_notice_interval, + 'termination_notice_rule_type': termination_notice_rule_type, + 'contract_id': contract.id, + 'sale_order_line_id': self.id, + 'predecessor_contract_line_id': predecessor_contract_line_id, + } + + @api.multi + def create_contract_line(self, contract): + contract_line_model = self.env['contract.line'] + contract_line = self.env['contract.line'] + predecessor_contract_line = False + for rec in self: + if rec.contract_line_id: + # If the upsell/downsell line start at the same date or before + # the contract line to replace supposed to start, we cancel + # the one to be replaced. Otherwise we stop it. + if rec.date_start <= rec.contract_line_id.date_start: + # The contract will handel the contract line integrity + # An exception will be raised if we try to cancel an + # invoiced contract line + rec.contract_line_id.cancel() + elif ( + not rec.contract_line_id.date_end + or rec.date_start <= rec.contract_line_id.date_end + ): + rec.contract_line_id.stop( + rec.date_start - relativedelta(days=1) + ) + predecessor_contract_line = rec.contract_line_id + if predecessor_contract_line: + new_contract_line = contract_line_model.create( + rec._prepare_contract_line_values( + contract, predecessor_contract_line.id + ) + ) + predecessor_contract_line.successor_contract_line_id = ( + new_contract_line + ) + else: + new_contract_line = contract_line_model.create( + rec._prepare_contract_line_values(contract) + ) + contract_line |= new_contract_line + return contract_line + + @api.constrains('contract_id') + def _check_contract_sale_partner(self): + for rec in self: + if rec.contract_id: + if rec.order_id.partner_id != rec.contract_id.partner_id: + raise ValidationError( + _( + "Sale Order and contract should be " + "linked to the same partner" + ) + ) + + @api.constrains('product_id', 'contract_id') + def _check_contract_sale_contract_template(self): + for rec in self: + if rec.contract_id: + if ( + rec.contract_id.contract_template_id + and rec.contract_template_id + != rec.contract_id.contract_template_id + ): + raise ValidationError( + _("Contract product has different contract template") + ) + + def _compute_invoice_status(self): + res = super(SaleOrderLine, self)._compute_invoice_status() + for line in self.filtered('contract_id'): + line.invoice_status = 'no' + return res + + @api.multi + def invoice_line_create(self, invoice_id, qty): + return super( + SaleOrderLine, self.filtered(lambda l: not l.contract_id) + ).invoice_line_create(invoice_id, qty) + + @api.depends( + 'qty_invoiced', + 'qty_delivered', + 'product_uom_qty', + 'order_id.state', + 'product_id.is_contract', + ) + def _get_to_invoice_qty(self): + """ + sale line linked to contracts must not be invoiced from sale order + """ + res = super()._get_to_invoice_qty() + self.filtered('product_id.is_contract').update({'qty_to_invoice': 0.0}) + return res diff --git a/product_contract/readme/CONTRIBUTORS.rst b/product_contract/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..2db29075 --- /dev/null +++ b/product_contract/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Ted Salmon +* Souheil Bejaoui diff --git a/product_contract/readme/DESCRIPTION.rst b/product_contract/readme/DESCRIPTION.rst new file mode 100644 index 00000000..e620eb27 --- /dev/null +++ b/product_contract/readme/DESCRIPTION.rst @@ -0,0 +1,5 @@ +This module adds support for products to be linked to contract templates. + +A contract is created on ``sale.order`` confirmation for each different template used in sale order line where recurrence details are set too. + +Contract product are ignored on invoicing process and pass to nothing to invoice directly. diff --git a/product_contract/readme/USAGE.rst b/product_contract/readme/USAGE.rst new file mode 100644 index 00000000..1ed5d471 --- /dev/null +++ b/product_contract/readme/USAGE.rst @@ -0,0 +1,6 @@ +To use this module, you need to: + +#. Go to Sales -> Products and select or create a product. +#. Check "Is a contract" and select the contract template related to the + product +#. Define default recurrence rules diff --git a/product_contract/tests/__init__.py b/product_contract/tests/__init__.py new file mode 100644 index 00000000..9dad07bd --- /dev/null +++ b/product_contract/tests/__init__.py @@ -0,0 +1,6 @@ +# Copyright 2017 LasLabs Inc. +# Copyright 2018 ACSONE SA/NV. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_product +from . import test_sale_order diff --git a/product_contract/tests/test_product.py b/product_contract/tests/test_product.py new file mode 100644 index 00000000..64a125c8 --- /dev/null +++ b/product_contract/tests/test_product.py @@ -0,0 +1,33 @@ +# Copyright 2017 LasLabs Inc. +# Copyright 2018 ACSONE SA/NV. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import TransactionCase +from odoo.exceptions import ValidationError + + +class TestProductTemplate(TransactionCase): + def setUp(self): + super(TestProductTemplate, self).setUp() + self.service_product = self.env.ref('product.product_product_1') + self.consu_product = self.env.ref('product.product_product_5') + self.contract = self.env['contract.template'].create( + {'name': 'Test'} + ) + + def test_change_is_contract(self): + """ It should verify that the contract_template_id is removed + when is_contract is False """ + self.service_product.is_contract = True + self.service_product.contract_template_id = self.contract.id + self.service_product.is_contract = False + self.service_product.product_tmpl_id._change_is_contract() + self.assertEquals(len(self.service_product.contract_template_id), 0) + + def test_check_contract_product_type(self): + """ + It should raise ValidationError on change of is_contract to True + for consu product + """ + with self.assertRaises(ValidationError): + self.consu_product.is_contract = True diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py new file mode 100644 index 00000000..5c163510 --- /dev/null +++ b/product_contract/tests/test_sale_order.py @@ -0,0 +1,315 @@ +# Copyright 2017 LasLabs Inc. +# Copyright 2018 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from dateutil.relativedelta import relativedelta +from odoo.tests.common import TransactionCase +from odoo.exceptions import ValidationError +from odoo.fields import Date + + +class TestSaleOrder(TransactionCase): + def setUp(self): + super(TestSaleOrder, self).setUp() + self.product1 = self.env.ref('product.product_product_1') + self.product2 = self.env.ref('product.product_product_2') + self.sale = self.env.ref('sale.sale_order_2') + self.contract_template1 = self.env['contract.template'].create( + {'name': 'Template 1'} + ) + self.contract_template2 = self.env['contract.template'].create( + { + 'name': 'Template 2', + 'contract_line_ids': [ + ( + 0, + 0, + { + 'product_id': self.product2.id, + 'name': 'Services from #START# to #END#', + 'quantity': 1, + 'uom_id': self.product2.uom_id.id, + 'price_unit': 100, + 'discount': 50, + 'recurring_rule_type': 'yearly', + 'recurring_interval': 1, + }, + ) + ], + } + ) + self.product1.write( + { + 'is_contract': True, + 'default_qty': 12, + 'recurring_rule_type': "monthlylastday", + 'contract_template_id': self.contract_template1.id, + } + ) + self.product2.write( + { + 'is_contract': True, + 'contract_template_id': self.contract_template2.id, + } + ) + self.order_line1 = self.sale.order_line.filtered( + lambda l: l.product_id == self.product1 + ) + self.order_line1.date_start = '2018-01-01' + self.order_line1.product_uom_qty = 12 + pricelist = self.sale.partner_id.property_product_pricelist.id + self.contract = self.env["contract.contract"].create( + { + "name": "Test Contract 2", + "partner_id": self.sale.partner_id.id, + "pricelist_id": pricelist, + "contract_type": "sale", + "contract_template_id": self.contract_template1.id, + "contract_line_ids": [ + ( + 0, + 0, + { + "product_id": self.product1.id, + "name": "Services from #START# to #END#", + "quantity": 1, + "uom_id": self.product1.uom_id.id, + "price_unit": 100, + "discount": 50, + "recurring_rule_type": "monthly", + "recurring_interval": 1, + "date_start": "2016-02-15", + "recurring_next_date": "2016-02-29", + }, + ) + ], + } + ) + self.contract_line = self.contract.contract_line_ids[0] + + def test_compute_is_contract(self): + """Sale Order should have is_contract true if one of its lines is + contract""" + self.assertTrue(self.sale.is_contract) + + def test_action_confirm(self): + """ It should create a contract for each contract template used in + order_line """ + self.order_line1.onchange_product() + self.sale.action_confirm() + contracts = self.sale.order_line.mapped('contract_id') + self.assertEqual(len(contracts), 2) + self.assertEqual( + self.order_line1.contract_id.contract_template_id, + self.contract_template1, + ) + contract_line = self.order_line1.contract_id.contract_line_ids + self.assertEqual(contract_line.date_start, Date.to_date('2018-01-01')) + self.assertEqual(contract_line.date_end, Date.to_date('2018-12-31')) + self.assertEqual( + contract_line.recurring_next_date, Date.to_date('2018-01-31') + ) + + def test_sale_order_invoice_status(self): + """ + sale line linked to contracts must not be invoiced from sale order + """ + self.sale.action_confirm() + self.assertEqual(self.order_line1.invoice_status, 'no') + invoice = self.order_line1.contract_id.recurring_create_invoice() + self.assertTrue(invoice) + self.assertEqual(self.order_line1.invoice_qty, 1) + self.assertEqual(self.order_line1.qty_to_invoice, 0) + + def test_action_confirm_without_contract_creation(self): + """ It should create a contract for each contract template used in + order_line """ + self.sale.company_id.create_contract_at_sale_order_confirmation = False + self.order_line1.onchange_product() + self.sale.action_confirm() + self.assertEqual(len(self.sale.order_line.mapped('contract_id')), 0) + self.assertTrue(self.sale.need_contract_creation) + self.sale.action_create_contract() + self.assertEqual(len(self.sale.order_line.mapped('contract_id')), 2) + self.assertFalse(self.sale.need_contract_creation) + self.assertEqual( + self.order_line1.contract_id.contract_template_id, + self.contract_template1, + ) + contract_line = self.order_line1.contract_id.contract_line_ids + self.assertEqual(contract_line.date_start, Date.to_date('2018-01-01')) + self.assertEqual(contract_line.date_end, Date.to_date('2018-12-31')) + self.assertEqual( + contract_line.recurring_next_date, Date.to_date('2018-01-31') + ) + + def test_sale_contract_count(self): + """It should count contracts as many different contract template used + in order_line""" + self.order_line1.onchange_product() + self.sale.action_confirm() + self.assertEqual(self.sale.contract_count, 2) + + def test_onchange_product(self): + """ It should get recurrence invoicing info to the sale line from + its product """ + self.order_line1.onchange_product() + self.assertEqual( + self.order_line1.recurring_rule_type, + self.product1.recurring_rule_type, + ) + self.assertEqual( + self.order_line1.recurring_invoicing_type, + self.product1.recurring_invoicing_type, + ) + self.assertEqual(self.order_line1.date_end, Date.to_date('2018-12-31')) + + def test_check_contract_sale_partner(self): + """Can't link order line to a partner contract different then the + order one""" + contract2 = self.env['contract.contract'].create( + { + 'name': 'Contract', + 'contract_template_id': self.contract_template2.id, + 'partner_id': self.sale.partner_id.id, + } + ) + with self.assertRaises(ValidationError): + self.order_line1.contract_id = contract2 + + def test_check_contract_sale_contract_template(self): + """Can't link order line to a contract with different contract + template then the product one""" + contract1 = self.env['contract.contract'].create( + { + 'name': 'Contract', + 'partner_id': self.env.user.partner_id.id, + 'contract_template_id': self.contract_template1.id, + } + ) + with self.assertRaises(ValidationError): + self.order_line1.contract_id = contract1 + + def test_no_contract_proudct(self): + """it should create contract for only product contract""" + self.product1.is_contract = False + self.sale.action_confirm() + self.assertFalse(self.order_line1.contract_id) + + def test_sale_order_line_invoice_status(self): + """Sale order line for contract product should have nothing to + invoice as status""" + self.order_line1.onchange_product() + self.sale.action_confirm() + self.assertEqual(self.order_line1.invoice_status, 'no') + + def test_sale_order_invoice_status(self): + """Sale order with only contract product should have nothing to + invoice status directtly""" + self.sale.order_line.filtered( + lambda line: not line.product_id.is_contract + ).unlink() + self.order_line1.onchange_product() + self.sale.action_confirm() + self.assertEqual(self.sale.invoice_status, 'no') + + def test_sale_order_create_invoice(self): + """Should not invoice contract product on sale order create invoice""" + self.product2.is_contract = False + self.product2.invoice_policy = 'order' + self.order_line1.onchange_product() + self.sale.action_confirm() + self.sale.action_invoice_create() + self.assertEqual(len(self.sale.invoice_ids), 1) + invoice_line = self.sale.invoice_ids.invoice_line_ids.filtered( + lambda line: line.product_id.is_contract + ) + self.assertEqual(len(invoice_line), 0) + + def test_link_contract_invoice_to_sale_order(self): + """It should link contract invoice to sale order""" + self.order_line1.onchange_product() + self.sale.action_confirm() + invoice = self.order_line1.contract_id.recurring_create_invoice() + self.assertTrue(invoice in self.sale.invoice_ids) + + def test_contract_upsell(self): + """Should stop contract line at sale order line start date""" + self.order_line1.contract_id = self.contract + self.order_line1.contract_line_id = self.contract_line + self.contract_line.date_end = Date.today() + relativedelta(months=4) + self.contract_line.is_auto_renew = True + self.order_line1.date_start = "2018-06-01" + self.order_line1.onchange_product() + self.sale.action_confirm() + self.assertEqual( + self.contract_line.date_end, Date.to_date("2018-05-31") + ) + self.assertFalse(self.contract_line.is_auto_renew) + new_contract_line = self.env['contract.line'].search( + [('sale_order_line_id', '=', self.order_line1.id)] + ) + self.assertEqual( + self.contract_line.successor_contract_line_id, new_contract_line + ) + self.assertEqual( + new_contract_line.predecessor_contract_line_id, self.contract_line + ) + + def test_contract_upsell_2(self): + """Should stop contract line at sale order line start date""" + self.order_line1.contract_id = self.contract + self.order_line1.contract_line_id = self.contract_line + self.contract_line.write( + { + 'date_start': "2018-06-01", + 'recurring_next_date': "2018-06-01", + 'date_end': False, + } + ) + self.order_line1.date_start = "2018-06-01" + self.order_line1.onchange_product() + self.sale.action_confirm() + self.assertFalse(self.contract_line.date_end) + self.assertTrue(self.contract_line.is_canceled) + + def test_onchange_product_id_recurring_info(self): + self.product2.write( + { + 'recurring_rule_type': 'monthly', + 'recurring_invoicing_type': 'pre-paid', + 'is_auto_renew': True, + 'default_qty': 12, + 'termination_notice_interval': '6', + 'termination_notice_rule_type': 'weekly', + } + ) + self.contract_line.write( + { + 'date_start': Date.today(), + 'date_end': Date.today() + relativedelta(years=1), + 'recurring_next_date': Date.today(), + 'product_id': self.product2.id, + } + ) + self.contract_line._onchange_product_id_recurring_info() + self.assertEqual(self.contract_line.recurring_rule_type, 'monthly') + self.assertEqual( + self.contract_line.recurring_invoicing_type, 'pre-paid' + ) + self.assertEqual(self.contract_line.recurring_interval, 1) + self.assertEqual(self.contract_line.is_auto_renew, True) + self.assertEqual(self.contract_line.auto_renew_interval, 12) + self.assertEqual(self.contract_line.auto_renew_rule_type, 'monthly') + self.assertEqual(self.contract_line.termination_notice_interval, 6) + self.assertEqual( + self.contract_line.termination_notice_rule_type, 'weekly' + ) + + def test_action_show_contracts(self): + self.sale.action_confirm() + action = self.sale.action_show_contracts() + self.assertEqual( + self.env['contract.contract'].search(action['domain']), + self.sale.order_line.mapped('contract_id'), + ) diff --git a/product_contract/views/contract.xml b/product_contract/views/contract.xml new file mode 100644 index 00000000..1762136a --- /dev/null +++ b/product_contract/views/contract.xml @@ -0,0 +1,29 @@ + + + + + + contract.contract + + + + + + + + + diff --git a/product_contract/views/product_template.xml b/product_contract/views/product_template.xml new file mode 100644 index 00000000..400afa99 --- /dev/null +++ b/product_contract/views/product_template.xml @@ -0,0 +1,57 @@ + + + + + + + + account.invoice.select.contract + product.template + + + +
+ +
+
+ + + + + + + + + + + + + + + + + + + +
+
+ +
diff --git a/product_contract/views/res_config_settings.xml b/product_contract/views/res_config_settings.xml new file mode 100644 index 00000000..d73ae8ac --- /dev/null +++ b/product_contract/views/res_config_settings.xml @@ -0,0 +1,31 @@ + + + + + + + res.config.settings.form (in product_contract) + + res.config.settings + + + +
+
+ +
+
+
+
+
+
+
+ + +
diff --git a/product_contract/views/sale_order.xml b/product_contract/views/sale_order.xml new file mode 100644 index 00000000..0428cac6 --- /dev/null +++ b/product_contract/views/sale_order.xml @@ -0,0 +1,87 @@ + + + + + + + + sale.order.form (in product_contract) + sale.order + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/setup/contract_sale_payment_mode/odoo/addons/contract_sale_payment_mode b/setup/contract_sale_payment_mode/odoo/addons/contract_sale_payment_mode new file mode 120000 index 00000000..68f9e65c --- /dev/null +++ b/setup/contract_sale_payment_mode/odoo/addons/contract_sale_payment_mode @@ -0,0 +1 @@ +../../../../contract_sale_payment_mode \ No newline at end of file diff --git a/setup/contract_sale_payment_mode/setup.py b/setup/contract_sale_payment_mode/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/contract_sale_payment_mode/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/setup/product_contract/odoo/addons/product_contract b/setup/product_contract/odoo/addons/product_contract new file mode 120000 index 00000000..8a36744f --- /dev/null +++ b/setup/product_contract/odoo/addons/product_contract @@ -0,0 +1 @@ +../../../../product_contract \ No newline at end of file diff --git a/setup/product_contract/setup.py b/setup/product_contract/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/product_contract/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)