From 9a890b3a242bf6a08d2d4ce9da84956be40e721e Mon Sep 17 00:00:00 2001 From: Ted Salmon Date: Thu, 12 Jan 2017 13:16:25 -0800 Subject: [PATCH 001/170] [ADD] product_contract: Create module * Add contract functionality to `product.templates` * Add logic to create contracts from `sale.order` that contains contract products. --- product_contract/README.rst | 66 +++++++++++++++++++ product_contract/__init__.py | 5 ++ product_contract/__manifest__.py | 23 +++++++ product_contract/i18n/de.po | 51 ++++++++++++++ product_contract/i18n/es.po | 51 ++++++++++++++ product_contract/i18n/fr.po | 51 ++++++++++++++ product_contract/i18n/hr.po | 51 ++++++++++++++ product_contract/i18n/hr_HR.po | 52 +++++++++++++++ product_contract/i18n/it.po | 51 ++++++++++++++ product_contract/i18n/nl.po | 51 ++++++++++++++ product_contract/i18n/pt_BR.po | 51 ++++++++++++++ product_contract/i18n/tr_TR.po | 51 ++++++++++++++ product_contract/models/__init__.py | 7 ++ product_contract/models/product_template.py | 23 +++++++ product_contract/models/sale_order.py | 27 ++++++++ product_contract/models/sale_order_line.py | 14 ++++ product_contract/tests/__init__.py | 6 ++ .../tests/test_product_template.py | 31 +++++++++ product_contract/tests/test_sale_order.py | 34 ++++++++++ .../views/product_template_view.xml | 29 ++++++++ 20 files changed, 725 insertions(+) create mode 100644 product_contract/README.rst create mode 100644 product_contract/__init__.py create mode 100644 product_contract/__manifest__.py create mode 100644 product_contract/i18n/de.po create mode 100644 product_contract/i18n/es.po create mode 100644 product_contract/i18n/fr.po create mode 100644 product_contract/i18n/hr.po create mode 100644 product_contract/i18n/hr_HR.po create mode 100644 product_contract/i18n/it.po create mode 100644 product_contract/i18n/nl.po create mode 100644 product_contract/i18n/pt_BR.po create mode 100644 product_contract/i18n/tr_TR.po create mode 100644 product_contract/models/__init__.py create mode 100644 product_contract/models/product_template.py create mode 100644 product_contract/models/sale_order.py create mode 100644 product_contract/models/sale_order_line.py create mode 100644 product_contract/tests/__init__.py create mode 100644 product_contract/tests/test_product_template.py create mode 100644 product_contract/tests/test_sale_order.py create mode 100644 product_contract/views/product_template_view.xml diff --git a/product_contract/README.rst b/product_contract/README.rst new file mode 100644 index 0000000000..6319dcf55a --- /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 0000000000..44db863b6e --- /dev/null +++ b/product_contract/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# 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 0000000000..e1d4d8ac65 --- /dev/null +++ b/product_contract/__manifest__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'Product Contract', + 'version': '10.0.1.0.0', + 'category': 'Contract Management', + 'license': 'AGPL-3', + 'author': "LasLabs, " + "Odoo Community Association (OCA)", + 'website': 'https://laslabs.com', + 'depends': [ + 'contract', + 'product', + 'sale', + ], + 'data': [ + 'views/product_template_view.xml', + ], + 'installable': True, + 'application': False, +} diff --git a/product_contract/i18n/de.po b/product_contract/i18n/de.po new file mode 100644 index 0000000000..3b62b5447b --- /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" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: de\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 0000000000..a89a0a1226 --- /dev/null +++ b/product_contract/i18n/es.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: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: es\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 "" + +#. 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 0000000000..1efcaf7ce5 --- /dev/null +++ b/product_contract/i18n/fr.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +# Translators: +# leemannd , 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: leemannd , 2017\n" +"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: fr\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 "" + +#. 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 0000000000..7f2b4f8c1e --- /dev/null +++ b/product_contract/i18n/hr.po @@ -0,0 +1,51 @@ +# 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: 2017-04-27 02:40+0000\n" +"PO-Revision-Date: 2017-04-27 02:40+0000\n" +"Last-Translator: Bole , 2017\n" +"Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: hr\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 "" + +#. 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_HR.po b/product_contract/i18n/hr_HR.po new file mode 100644 index 0000000000..922d93fb16 --- /dev/null +++ b/product_contract/i18n/hr_HR.po @@ -0,0 +1,52 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +# Translators: +# Bole , 2017 +# 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: Croatian (Croatia) (https://www.transifex.com/oca/teams/23907/hr_HR/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: hr_HR\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 "" + +#. 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/it.po b/product_contract/i18n/it.po new file mode 100644 index 0000000000..982bdf76c5 --- /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" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: it\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 0000000000..4c309a2502 --- /dev/null +++ b/product_contract/i18n/nl.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +# Translators: +# Erwin van der Ploeg , 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: Erwin van der Ploeg , 2017\n" +"Language-Team: Dutch (https://www.transifex.com/oca/teams/23907/nl/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: nl\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 "" + +#. 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_BR.po b/product_contract/i18n/pt_BR.po new file mode 100644 index 0000000000..592c6aaecb --- /dev/null +++ b/product_contract/i18n/pt_BR.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_contract +# +# Translators: +# Albert Vonpupp , 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: Albert Vonpupp , 2017\n" +"Language-Team: Portuguese (Brazil) (https://www.transifex.com/oca/teams/23907/pt_BR/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: pt_BR\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 "" + +#. 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_TR.po b/product_contract/i18n/tr_TR.po new file mode 100644 index 0000000000..5bcb2f7edd --- /dev/null +++ b/product_contract/i18n/tr_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: 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" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: tr_TR\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/models/__init__.py b/product_contract/models/__init__.py new file mode 100644 index 0000000000..388717d23f --- /dev/null +++ b/product_contract/models/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import product_template +from . import sale_order +from . import sale_order_line diff --git a/product_contract/models/product_template.py b/product_contract/models/product_template.py new file mode 100644 index 0000000000..fd7e00d4c8 --- /dev/null +++ b/product_contract/models/product_template.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + is_contract = fields.Boolean('Is a contract') + contract_template_id = fields.Many2one( + comodel_name='account.analytic.contract', + string='Contract Template', + ) + + @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 diff --git a/product_contract/models/sale_order.py b/product_contract/models/sale_order.py new file mode 100644 index 0000000000..45f2eec77d --- /dev/null +++ b/product_contract/models/sale_order.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + @api.multi + def action_confirm(self): + """ If we have a contract in the order, set it up """ + for rec in self: + order_lines = self.mapped('order_line').filtered( + lambda r: r.product_id.is_contract + ) + for line in order_lines: + contract_tmpl = line.product_id.contract_template_id + contract = self.env['account.analytic.account'].create({ + 'name': '%s Contract' % rec.name, + 'partner_id': rec.partner_id.id, + 'contract_template_id': contract_tmpl.id, + }) + line.contract_id = contract.id + contract.recurring_create_invoice() + return super(SaleOrder, self).action_confirm() diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py new file mode 100644 index 0000000000..c76c10595b --- /dev/null +++ b/product_contract/models/sale_order_line.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class SaleOrderLine(models.Model): + _inherit = 'sale.order.line' + + contract_id = fields.Many2one( + comodel_name='account.analytic.account', + string='Contract' + ) diff --git a/product_contract/tests/__init__.py b/product_contract/tests/__init__.py new file mode 100644 index 0000000000..e5fbe249ab --- /dev/null +++ b/product_contract/tests/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_product_template +from . import test_sale_order diff --git a/product_contract/tests/test_product_template.py b/product_contract/tests/test_product_template.py new file mode 100644 index 0000000000..2938cc7f9f --- /dev/null +++ b/product_contract/tests/test_product_template.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import TransactionCase + + +class TestProductTemplate(TransactionCase): + + def setUp(self): + super(TestProductTemplate, self).setUp() + self.product = self.env.ref( + 'product.product_product_4_product_template' + ) + self.contract = self.env['account.analytic.contract'].create({ + 'name': 'Test', + 'recurring_rule_type': 'yearly', + 'recurring_interval': 12345, + }) + + def test_change_is_contract(self): + """ It should verify that the contract_template_id is removed + when is_contract is False """ + self.product.is_contract = True + self.product.contract_template_id = self.contract.id + self.product.is_contract = False + self.product._change_is_contract() + self.assertEquals( + len(self.product.contract_template_id), + 0 + ) diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py new file mode 100644 index 0000000000..7ca4c09990 --- /dev/null +++ b/product_contract/tests/test_sale_order.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from mock import MagicMock +from odoo.tests.common import TransactionCase + + +class TestSaleOrder(TransactionCase): + + def setUp(self): + super(TestSaleOrder, self).setUp() + self.product = self.env.ref('product.product_product_1') + self.sale = self.env.ref('sale.sale_order_2') + self.contract = self.env['account.analytic.contract'].create({ + 'name': 'Test', + 'recurring_rule_type': 'yearly', + 'recurring_interval': 12345, + }) + self.product.product_tmpl_id.is_contract = True + self.product.product_tmpl_id.contract_template_id = self.contract.id + + def test_action_done(self): + """ It should create a contract when the sale for a contract is set + to done for the first time """ + self.env['account.analytic.account']._patch_method( + 'create', MagicMock() + ) + self.sale.action_confirm() + self.env['account.analytic.account'].create.assert_called_once_with({ + 'name': '%s Contract' % self.sale.name, + 'partner_id': self.sale.partner_id.id, + 'contract_template_id': self.contract.id, + }) diff --git a/product_contract/views/product_template_view.xml b/product_contract/views/product_template_view.xml new file mode 100644 index 0000000000..46c2e05c52 --- /dev/null +++ b/product_contract/views/product_template_view.xml @@ -0,0 +1,29 @@ + + + + + + + + account.invoice.select.contract + product.template + + + +
+ +
+
+ + + +
+
+ +
From d97e5e5bf5926e2e0d0c05ea77fcda118cf9e374 Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Thu, 25 May 2017 17:51:46 -0700 Subject: [PATCH 002/170] [FIX] product_contract: Fix mock usage in tests --- product_contract/i18n/es.po | 17 ++++---- product_contract/i18n/fi.po | 51 +++++++++++++++++++++++ product_contract/i18n/hi_IN.po | 51 +++++++++++++++++++++++ product_contract/i18n/hr.po | 14 +++---- product_contract/i18n/hr_HR.po | 16 +++---- product_contract/i18n/nl.po | 17 ++++---- product_contract/i18n/nl_NL.po | 51 +++++++++++++++++++++++ product_contract/i18n/pt.po | 51 +++++++++++++++++++++++ product_contract/i18n/pt_BR.po | 11 ++--- product_contract/i18n/ru.po | 51 +++++++++++++++++++++++ product_contract/i18n/tr.po | 51 +++++++++++++++++++++++ product_contract/tests/test_sale_order.py | 5 +++ 12 files changed, 350 insertions(+), 36 deletions(-) create mode 100644 product_contract/i18n/fi.po create mode 100644 product_contract/i18n/hi_IN.po create mode 100644 product_contract/i18n/nl_NL.po create mode 100644 product_contract/i18n/pt.po create mode 100644 product_contract/i18n/ru.po create mode 100644 product_contract/i18n/tr.po diff --git a/product_contract/i18n/es.po b/product_contract/i18n/es.po index a89a0a1226..d712dd0e0a 100644 --- a/product_contract/i18n/es.po +++ b/product_contract/i18n/es.po @@ -4,13 +4,14 @@ # # Translators: # OCA Transbot , 2017 +# enjolras , 2018 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" +"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" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -27,25 +28,25 @@ msgstr "Contrato" #: 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 "" +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 "" +msgstr "Es un contrato" #. module: product_contract #: model:ir.model,name:product_contract.model_product_template msgid "Product Template" -msgstr "" +msgstr "Plantilla de producto" #. module: product_contract #: model:ir.model,name:product_contract.model_sale_order msgid "Sales Order" -msgstr "" +msgstr "Pedido de venta" #. module: product_contract #: model:ir.model,name:product_contract.model_sale_order_line msgid "Sales Order Line" -msgstr "" +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 0000000000..9daef38d79 --- /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" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: fi\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/hi_IN.po b/product_contract/i18n/hi_IN.po new file mode 100644 index 0000000000..fe5f0e87df --- /dev/null +++ b/product_contract/i18n/hi_IN.po @@ -0,0 +1,51 @@ +# 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" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: hi_IN\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 index 7f2b4f8c1e..2cfaafaeff 100644 --- a/product_contract/i18n/hr.po +++ b/product_contract/i18n/hr.po @@ -8,8 +8,8 @@ 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" +"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" "MIME-Version: 1.0\n" @@ -27,25 +27,25 @@ msgstr "Ugovor" #: 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 "" +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 "" +msgstr "Je ugovor" #. module: product_contract #: model:ir.model,name:product_contract.model_product_template msgid "Product Template" -msgstr "" +msgstr "Predložak proizvoda" #. module: product_contract #: model:ir.model,name:product_contract.model_sale_order msgid "Sales Order" -msgstr "" +msgstr "Ponuda" #. module: product_contract #: model:ir.model,name:product_contract.model_sale_order_line msgid "Sales Order Line" -msgstr "" +msgstr "Stavka ponude" diff --git a/product_contract/i18n/hr_HR.po b/product_contract/i18n/hr_HR.po index 922d93fb16..1248f3f275 100644 --- a/product_contract/i18n/hr_HR.po +++ b/product_contract/i18n/hr_HR.po @@ -3,15 +3,15 @@ # * product_contract # # Translators: -# Bole , 2017 # OCA Transbot , 2017 +# Bole , 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" +"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" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -34,19 +34,19 @@ msgstr "Predložak ugovora" #: 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 "" +msgstr "Je ugovor" #. module: product_contract #: model:ir.model,name:product_contract.model_product_template msgid "Product Template" -msgstr "" +msgstr "Predložak proizvoda" #. module: product_contract #: model:ir.model,name:product_contract.model_sale_order msgid "Sales Order" -msgstr "" +msgstr "Prodajni nalog" #. module: product_contract #: model:ir.model,name:product_contract.model_sale_order_line msgid "Sales Order Line" -msgstr "" +msgstr "Stavka prodajnog naloga" diff --git a/product_contract/i18n/nl.po b/product_contract/i18n/nl.po index 4c309a2502..bdc4ca24b9 100644 --- a/product_contract/i18n/nl.po +++ b/product_contract/i18n/nl.po @@ -4,13 +4,14 @@ # # 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: 2017-04-27 02:40+0000\n" -"PO-Revision-Date: 2017-04-27 02:40+0000\n" -"Last-Translator: Erwin van der Ploeg , 2017\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" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -27,25 +28,25 @@ msgstr "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 "" +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 "" +msgstr "Is een contract" #. module: product_contract #: model:ir.model,name:product_contract.model_product_template msgid "Product Template" -msgstr "" +msgstr "Productsjabloon" #. module: product_contract #: model:ir.model,name:product_contract.model_sale_order msgid "Sales Order" -msgstr "" +msgstr "Verkooporder" #. module: product_contract #: model:ir.model,name:product_contract.model_sale_order_line msgid "Sales Order Line" -msgstr "" +msgstr "Verkooporderregel" diff --git a/product_contract/i18n/nl_NL.po b/product_contract/i18n/nl_NL.po new file mode 100644 index 0000000000..31a87e0924 --- /dev/null +++ b/product_contract/i18n/nl_NL.po @@ -0,0 +1,51 @@ +# 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" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: nl_NL\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/pt.po b/product_contract/i18n/pt.po new file mode 100644 index 0000000000..edcf09df85 --- /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" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: pt\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 index 592c6aaecb..cbe238852c 100644 --- a/product_contract/i18n/pt_BR.po +++ b/product_contract/i18n/pt_BR.po @@ -3,14 +3,15 @@ # * product_contract # # Translators: -# Albert Vonpupp , 2017 +# OCA Transbot , 2017 +# falexandresilva , 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: Albert Vonpupp , 2017\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" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -43,7 +44,7 @@ msgstr "" #. module: product_contract #: model:ir.model,name:product_contract.model_sale_order msgid "Sales Order" -msgstr "" +msgstr "Pedido de compras" #. module: product_contract #: model:ir.model,name:product_contract.model_sale_order_line diff --git a/product_contract/i18n/ru.po b/product_contract/i18n/ru.po new file mode 100644 index 0000000000..f78f50ad95 --- /dev/null +++ b/product_contract/i18n/ru.po @@ -0,0 +1,51 @@ +# 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" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: ru\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 0000000000..9887463f68 --- /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: 2017-05-13 09:15+0000\n" +"PO-Revision-Date: 2017-05-13 09:15+0000\n" +"Last-Translator: Ediz Duman , 2017\n" +"Language-Team: Turkish (https://www.transifex.com/oca/teams/23907/tr/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: tr\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 "" + +#. 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/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index 7ca4c09990..98b174ff53 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -20,6 +20,11 @@ def setUp(self): self.product.product_tmpl_id.is_contract = True self.product.product_tmpl_id.contract_template_id = self.contract.id + def tearDown(self): + self.env['account.analytic.account']._revert_method( + 'create', + ) + def test_action_done(self): """ It should create a contract when the sale for a contract is set to done for the first time """ From cc886fc3906a165d8def315327cae6bd9ba791cd Mon Sep 17 00:00:00 2001 From: Florent THOMAS Date: Sun, 1 Apr 2018 19:21:52 +0200 Subject: [PATCH 003/170] [FIX] contract_sale_generation: it doesn't create sales (#141) * Change the method called in the view * Complete the create_invoice method * Bump version + authoring * Correct bad call of method Small Documentation * Add super call in python test * FIX bad field names causing bad quantities in sale.order.line --- product_contract/i18n/de.po | 4 +- product_contract/i18n/es.po | 4 +- product_contract/i18n/fi.po | 4 +- product_contract/i18n/fr.po | 16 ++++---- product_contract/i18n/hi_IN.po | 7 ++-- product_contract/i18n/hr.po | 7 ++-- product_contract/i18n/hr_HR.po | 10 +++-- product_contract/i18n/it.po | 4 +- product_contract/i18n/nl.po | 4 +- product_contract/i18n/nl_NL.po | 7 ++-- product_contract/i18n/product_contract.pot | 47 ++++++++++++++++++++++ product_contract/i18n/pt.po | 4 +- product_contract/i18n/pt_BR.po | 7 ++-- product_contract/i18n/ru.po | 8 ++-- product_contract/i18n/tr.po | 16 ++++---- product_contract/i18n/tr_TR.po | 7 ++-- product_contract/tests/test_sale_order.py | 1 + 17 files changed, 108 insertions(+), 49 deletions(-) create mode 100644 product_contract/i18n/product_contract.pot diff --git a/product_contract/i18n/de.po b/product_contract/i18n/de.po index 3b62b5447b..00697a55d7 100644 --- a/product_contract/i18n/de.po +++ b/product_contract/i18n/de.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * product_contract -# +# # Translators: # OCA Transbot , 2017 msgid "" @@ -12,10 +12,10 @@ msgstr "" "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" -"Language: de\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" #. module: product_contract diff --git a/product_contract/i18n/es.po b/product_contract/i18n/es.po index d712dd0e0a..1fd8a1a181 100644 --- a/product_contract/i18n/es.po +++ b/product_contract/i18n/es.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * product_contract -# +# # Translators: # OCA Transbot , 2017 # enjolras , 2018 @@ -13,10 +13,10 @@ msgstr "" "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" -"Language: es\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" #. module: product_contract diff --git a/product_contract/i18n/fi.po b/product_contract/i18n/fi.po index 9daef38d79..3467c265a7 100644 --- a/product_contract/i18n/fi.po +++ b/product_contract/i18n/fi.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * product_contract -# +# # Translators: # Jarmo Kortetjärvi , 2018 msgid "" @@ -12,10 +12,10 @@ msgstr "" "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" -"Language: fi\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" #. module: product_contract diff --git a/product_contract/i18n/fr.po b/product_contract/i18n/fr.po index 1efcaf7ce5..59f399b345 100644 --- a/product_contract/i18n/fr.po +++ b/product_contract/i18n/fr.po @@ -1,21 +1,23 @@ # 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: 2017-04-27 02:40+0000\n" -"PO-Revision-Date: 2017-04-27 02:40+0000\n" -"Last-Translator: leemannd , 2017\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" -"Language: fr\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" #. module: product_contract @@ -27,7 +29,7 @@ msgstr "Contrat" #: 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 "" +msgstr "Modèle de contrat" #. module: product_contract #: model:ir.model.fields,field_description:product_contract.field_product_product_is_contract @@ -43,7 +45,7 @@ msgstr "" #. module: product_contract #: model:ir.model,name:product_contract.model_sale_order msgid "Sales Order" -msgstr "" +msgstr "Vente" #. module: product_contract #: model:ir.model,name:product_contract.model_sale_order_line diff --git a/product_contract/i18n/hi_IN.po b/product_contract/i18n/hi_IN.po index fe5f0e87df..e55f00ea69 100644 --- a/product_contract/i18n/hi_IN.po +++ b/product_contract/i18n/hi_IN.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * product_contract -# +# # Translators: # Ashish Deshmukh , 2017 msgid "" @@ -11,11 +11,12 @@ msgstr "" "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-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" -"Language: hi_IN\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" #. module: product_contract diff --git a/product_contract/i18n/hr.po b/product_contract/i18n/hr.po index 2cfaafaeff..5ac9378959 100644 --- a/product_contract/i18n/hr.po +++ b/product_contract/i18n/hr.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * product_contract -# +# # Translators: # Bole , 2017 msgid "" @@ -12,11 +12,12 @@ msgstr "" "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" -"Language: hr\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" +"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 diff --git a/product_contract/i18n/hr_HR.po b/product_contract/i18n/hr_HR.po index 1248f3f275..2766a63166 100644 --- a/product_contract/i18n/hr_HR.po +++ b/product_contract/i18n/hr_HR.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * product_contract -# +# # Translators: # OCA Transbot , 2017 # Bole , 2017 @@ -12,12 +12,14 @@ msgstr "" "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-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" -"Language: hr_HR\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" +"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 diff --git a/product_contract/i18n/it.po b/product_contract/i18n/it.po index 982bdf76c5..010897f63b 100644 --- a/product_contract/i18n/it.po +++ b/product_contract/i18n/it.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * product_contract -# +# # Translators: # Lorenzo Battistini , 2017 msgid "" @@ -12,10 +12,10 @@ msgstr "" "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" -"Language: it\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" #. module: product_contract diff --git a/product_contract/i18n/nl.po b/product_contract/i18n/nl.po index bdc4ca24b9..4c8db3eb93 100644 --- a/product_contract/i18n/nl.po +++ b/product_contract/i18n/nl.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * product_contract -# +# # Translators: # Erwin van der Ploeg , 2017 # lfreeke , 2018 @@ -13,10 +13,10 @@ msgstr "" "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" -"Language: nl\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" #. module: product_contract diff --git a/product_contract/i18n/nl_NL.po b/product_contract/i18n/nl_NL.po index 31a87e0924..517781e3ed 100644 --- a/product_contract/i18n/nl_NL.po +++ b/product_contract/i18n/nl_NL.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * product_contract -# +# # Translators: # Peter Hageman , 2017 msgid "" @@ -11,11 +11,12 @@ msgstr "" "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-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" -"Language: nl_NL\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" #. module: product_contract diff --git a/product_contract/i18n/product_contract.pot b/product_contract/i18n/product_contract.pot new file mode 100644 index 0000000000..154aed4dc6 --- /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 index edcf09df85..0ca84dea84 100644 --- a/product_contract/i18n/pt.po +++ b/product_contract/i18n/pt.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * product_contract -# +# # Translators: # Pedro Castro Silva , 2017 msgid "" @@ -12,10 +12,10 @@ msgstr "" "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" -"Language: pt\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" #. module: product_contract diff --git a/product_contract/i18n/pt_BR.po b/product_contract/i18n/pt_BR.po index cbe238852c..75fd5d80e4 100644 --- a/product_contract/i18n/pt_BR.po +++ b/product_contract/i18n/pt_BR.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * product_contract -# +# # Translators: # OCA Transbot , 2017 # falexandresilva , 2017 @@ -12,11 +12,12 @@ msgstr "" "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-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" -"Language: pt_BR\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" #. module: product_contract diff --git a/product_contract/i18n/ru.po b/product_contract/i18n/ru.po index f78f50ad95..bc7bdcbb6c 100644 --- a/product_contract/i18n/ru.po +++ b/product_contract/i18n/ru.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * product_contract -# +# # Translators: # nek, 2018 msgid "" @@ -12,11 +12,13 @@ msgstr "" "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" -"Language: ru\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" +"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 diff --git a/product_contract/i18n/tr.po b/product_contract/i18n/tr.po index 9887463f68..03f07329f4 100644 --- a/product_contract/i18n/tr.po +++ b/product_contract/i18n/tr.po @@ -1,21 +1,21 @@ # 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-05-13 09:15+0000\n" -"PO-Revision-Date: 2017-05-13 09:15+0000\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" -"Language: tr\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" #. module: product_contract @@ -33,19 +33,19 @@ msgstr "Sözleşme Şablonu" #: 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 "" +msgstr "Sözleşmeli" #. module: product_contract #: model:ir.model,name:product_contract.model_product_template msgid "Product Template" -msgstr "" +msgstr "Ürün Şablonu" #. module: product_contract #: model:ir.model,name:product_contract.model_sale_order msgid "Sales Order" -msgstr "" +msgstr "Satış Siparişi" #. module: product_contract #: model:ir.model,name:product_contract.model_sale_order_line msgid "Sales Order Line" -msgstr "" +msgstr "Satış Sipariş Satırı" diff --git a/product_contract/i18n/tr_TR.po b/product_contract/i18n/tr_TR.po index 5bcb2f7edd..7c93e6e4f9 100644 --- a/product_contract/i18n/tr_TR.po +++ b/product_contract/i18n/tr_TR.po @@ -1,7 +1,7 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: # * product_contract -# +# # Translators: # Ediz Duman , 2017 msgid "" @@ -11,11 +11,12 @@ msgstr "" "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-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" -"Language: tr_TR\n" "Plural-Forms: nplurals=1; plural=0;\n" #. module: product_contract diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index 98b174ff53..61f33858c2 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -24,6 +24,7 @@ def tearDown(self): self.env['account.analytic.account']._revert_method( 'create', ) + super(TestSaleOrder, self).tearDown() def test_action_done(self): """ It should create a contract when the sale for a contract is set From 5666cf3accebeaabe3adec14b15473a88ba3d25b Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Wed, 31 Oct 2018 16:21:51 +0100 Subject: [PATCH 004/170] [MIG] - Product Contract Migration to 12.0 --- product_contract/__manifest__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/product_contract/__manifest__.py b/product_contract/__manifest__.py index e1d4d8ac65..b5b5cac556 100644 --- a/product_contract/__manifest__.py +++ b/product_contract/__manifest__.py @@ -1,13 +1,15 @@ # -*- coding: utf-8 -*- # Copyright 2017 LasLabs Inc. +# Copyright 2018 ACSONE SA/NV. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'Product Contract', - 'version': '10.0.1.0.0', + 'version': '12.0.1.0.0', 'category': 'Contract Management', 'license': 'AGPL-3', 'author': "LasLabs, " + "ACSONE SA/NV, " "Odoo Community Association (OCA)", 'website': 'https://laslabs.com', 'depends': [ From feddc38c5ad0f689fed8b6781be263a019dae9dc Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Wed, 31 Oct 2018 16:23:34 +0100 Subject: [PATCH 005/170] [IMP] - Product with is_contract can be only of type service --- product_contract/models/product_template.py | 15 ++++++-- product_contract/tests/__init__.py | 2 +- product_contract/tests/test_product.py | 34 +++++++++++++++++++ .../tests/test_product_template.py | 31 ----------------- product_contract/tests/test_sale_order.py | 2 -- 5 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 product_contract/tests/test_product.py delete mode 100644 product_contract/tests/test_product_template.py diff --git a/product_contract/models/product_template.py b/product_contract/models/product_template.py index fd7e00d4c8..1016c60c87 100644 --- a/product_contract/models/product_template.py +++ b/product_contract/models/product_template.py @@ -1,8 +1,10 @@ # -*- coding: utf-8 -*- # 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 import api, fields, models, _ +from odoo.exceptions import ValidationError class ProductTemplate(models.Model): @@ -10,8 +12,7 @@ class ProductTemplate(models.Model): is_contract = fields.Boolean('Is a contract') contract_template_id = fields.Many2one( - comodel_name='account.analytic.contract', - string='Contract Template', + comodel_name='account.analytic.contract', string='Contract Template' ) @api.onchange('is_contract') @@ -21,3 +22,11 @@ def _change_is_contract(self): """ 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/tests/__init__.py b/product_contract/tests/__init__.py index e5fbe249ab..b4af49c0af 100644 --- a/product_contract/tests/__init__.py +++ b/product_contract/tests/__init__.py @@ -2,5 +2,5 @@ # Copyright 2017 LasLabs Inc. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from . import test_product_template +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 0000000000..3676dc057c --- /dev/null +++ b/product_contract/tests/test_product.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# 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['account.analytic.contract'].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_product_template.py b/product_contract/tests/test_product_template.py deleted file mode 100644 index 2938cc7f9f..0000000000 --- a/product_contract/tests/test_product_template.py +++ /dev/null @@ -1,31 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2017 LasLabs Inc. -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from odoo.tests.common import TransactionCase - - -class TestProductTemplate(TransactionCase): - - def setUp(self): - super(TestProductTemplate, self).setUp() - self.product = self.env.ref( - 'product.product_product_4_product_template' - ) - self.contract = self.env['account.analytic.contract'].create({ - 'name': 'Test', - 'recurring_rule_type': 'yearly', - 'recurring_interval': 12345, - }) - - def test_change_is_contract(self): - """ It should verify that the contract_template_id is removed - when is_contract is False """ - self.product.is_contract = True - self.product.contract_template_id = self.contract.id - self.product.is_contract = False - self.product._change_is_contract() - self.assertEquals( - len(self.product.contract_template_id), - 0 - ) diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index 61f33858c2..f8a90e3489 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -14,8 +14,6 @@ def setUp(self): self.sale = self.env.ref('sale.sale_order_2') self.contract = self.env['account.analytic.contract'].create({ 'name': 'Test', - 'recurring_rule_type': 'yearly', - 'recurring_interval': 12345, }) self.product.product_tmpl_id.is_contract = True self.product.product_tmpl_id.contract_template_id = self.contract.id From ca03bc694d7e2e02999fa9a4d30fcc3fd100e4ff Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Wed, 31 Oct 2018 17:07:47 +0100 Subject: [PATCH 006/170] [IMP] - Change dependencies to contract_sale --- product_contract/__manifest__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/product_contract/__manifest__.py b/product_contract/__manifest__.py index b5b5cac556..970265ff3a 100644 --- a/product_contract/__manifest__.py +++ b/product_contract/__manifest__.py @@ -13,9 +13,8 @@ "Odoo Community Association (OCA)", 'website': 'https://laslabs.com', 'depends': [ - 'contract', 'product', - 'sale', + 'contract_sale', ], 'data': [ 'views/product_template_view.xml', From dcf06d2fd5dade09efad0237b374a47914459517 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Wed, 31 Oct 2018 18:10:08 +0100 Subject: [PATCH 007/170] [IMP] - Add recurrence fields to product template and sale order line --- product_contract/__manifest__.py | 3 +- product_contract/models/product_template.py | 24 +++++++ product_contract/models/sale_order.py | 12 +++- product_contract/models/sale_order_line.py | 49 ++++++++++++++- product_contract/tests/__init__.py | 2 + product_contract/tests/test_sale_order.py | 2 + .../tests/test_sale_order_line.py | 37 +++++++++++ product_contract/views/product_template.xml | 44 +++++++++++++ .../views/product_template_view.xml | 29 --------- product_contract/views/sale_order.xml | 63 +++++++++++++++++++ 10 files changed, 231 insertions(+), 34 deletions(-) create mode 100644 product_contract/tests/test_sale_order_line.py create mode 100644 product_contract/views/product_template.xml delete mode 100644 product_contract/views/product_template_view.xml create mode 100644 product_contract/views/sale_order.xml diff --git a/product_contract/__manifest__.py b/product_contract/__manifest__.py index 970265ff3a..f369b8251f 100644 --- a/product_contract/__manifest__.py +++ b/product_contract/__manifest__.py @@ -17,7 +17,8 @@ 'contract_sale', ], 'data': [ - 'views/product_template_view.xml', + 'views/product_template.xml', + 'views/sale_order.xml', ], 'installable': True, 'application': False, diff --git a/product_contract/models/product_template.py b/product_contract/models/product_template.py index 1016c60c87..1d25620197 100644 --- a/product_contract/models/product_template.py +++ b/product_contract/models/product_template.py @@ -15,6 +15,30 @@ class ProductTemplate(models.Model): comodel_name='account.analytic.contract', string='Contract Template' ) + 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='Recurrence', + 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", + ) + recurring_interval = fields.Integer( + default=1, + string='Repeat Every', + help="Repeat every (Days/Week/Month/Year)", + ) + @api.onchange('is_contract') def _change_is_contract(self): """ Clear the relation to contract_template_id when downgrading diff --git a/product_contract/models/sale_order.py b/product_contract/models/sale_order.py index 45f2eec77d..443eaaff72 100644 --- a/product_contract/models/sale_order.py +++ b/product_contract/models/sale_order.py @@ -2,12 +2,22 @@ # Copyright 2017 LasLabs Inc. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import api, models +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" + ) + + @api.depends('order_line') + def _compute_is_contract(self): + self.is_contract = any( + self.order_line.mapped('is_contract') + ) + @api.multi def action_confirm(self): """ If we have a contract in the order, set it up """ diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index c76c10595b..23da9c1c9c 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -1,14 +1,57 @@ # -*- coding: utf-8 -*- # Copyright 2017 LasLabs Inc. +# Copyright 2017 ACSONE SA/NV. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import fields, models +from odoo import api, fields, models 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='account.analytic.account', - string='Contract' + comodel_name='account.analytic.account', string='Contract' + ) + 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='Recurrence', + help="Specify Interval for automatic invoice generation.", + 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, ) + recurring_interval = fields.Integer( + default=1, + string='Repeat Every', + help="Repeat every (Days/Week/Month/Year)", + copy=False, + ) + date_start = fields.Date(string='Date Start', default=fields.Date.today()) + date_end = fields.Date(string='Date End', index=True) + recurring_next_date = fields.Date( + default=fields.Date.today(), copy=False, string='Date of Next Invoice' + ) + + @api.onchange('product_id') + def onchange_product(self): + if self.product_id.is_contract: + self.recurring_rule_type = self.product_id.recurring_rule_type + self.recurring_invoicing_type = ( + self.product_id.recurring_invoicing_type + ) + self.recurring_interval = self.product_id.recurring_interval diff --git a/product_contract/tests/__init__.py b/product_contract/tests/__init__.py index b4af49c0af..4766d5eabe 100644 --- a/product_contract/tests/__init__.py +++ b/product_contract/tests/__init__.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # 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 +from . import test_sale_order_line diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index f8a90e3489..e8f666020f 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -27,6 +27,8 @@ def tearDown(self): def test_action_done(self): """ It should create a contract when the sale for a contract is set to done for the first time """ + + self.assertTrue(self.sale.is_contract) self.env['account.analytic.account']._patch_method( 'create', MagicMock() ) diff --git a/product_contract/tests/test_sale_order_line.py b/product_contract/tests/test_sale_order_line.py new file mode 100644 index 0000000000..1f10905990 --- /dev/null +++ b/product_contract/tests/test_sale_order_line.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 ACSONE SA/NV. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from mock import MagicMock +from odoo.tests.common import TransactionCase + + +class TestSaleOrder(TransactionCase): + + def setUp(self): + super(TestSaleOrder, self).setUp() + self.product = self.env.ref('product.product_product_1') + self.sale = self.env.ref('sale.sale_order_2') + self.contract = self.env['account.analytic.contract'].create({ + 'name': 'Test', + }) + self.product.product_tmpl_id.is_contract = True + self.sale_order_line = self.sale.order_line.filtered( + lambda l: l.product_id == self.product + ) + + def test_onchange_product(self): + """ It should get recurrence invoicing info to the sale line from + its product """ + self.assertEqual( + self.sale_order_line.recurring_rule_type, + self.product.recurring_rule_type + ) + self.assertEqual( + self.sale_order_line.recurring_interval, + self.product.recurring_interval + ) + self.assertEqual( + self.sale_order_line.recurring_invoicing_type, + self.product.recurring_invoicing_type + ) diff --git a/product_contract/views/product_template.xml b/product_contract/views/product_template.xml new file mode 100644 index 0000000000..9eb3b38fc8 --- /dev/null +++ b/product_contract/views/product_template.xml @@ -0,0 +1,44 @@ + + + + + + + + account.invoice.select.contract + product.template + + + +
+ +
+
+ + + + + +
+
+ +
diff --git a/product_contract/views/product_template_view.xml b/product_contract/views/product_template_view.xml deleted file mode 100644 index 46c2e05c52..0000000000 --- a/product_contract/views/product_template_view.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - account.invoice.select.contract - product.template - - - -
- -
-
- - - -
-
- -
diff --git a/product_contract/views/sale_order.xml b/product_contract/views/sale_order.xml new file mode 100644 index 0000000000..f27c40250b --- /dev/null +++ b/product_contract/views/sale_order.xml @@ -0,0 +1,63 @@ + + + + + + + + sale.order.form (in product_contract) + sale.order + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 382caabe5608188e8d93c19313238ab8195dd269 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Fri, 2 Nov 2018 14:34:05 +0100 Subject: [PATCH 008/170] [IMP] - Create contract on sale order confirmation - On Sale Order confirmation, a contract is created for each contract template used on sale order lines - A not finished contract can be mentioned on sale order line - A sale order line linked to a contract will update it and don't create a new one if it had the same template --- product_contract/models/sale_order.py | 65 ++++++++--- product_contract/models/sale_order_line.py | 62 ++++++++++- product_contract/tests/__init__.py | 1 - product_contract/tests/test_sale_order.py | 102 +++++++++++++----- .../tests/test_sale_order_line.py | 37 ------- product_contract/views/sale_order.xml | 18 ++++ 6 files changed, 205 insertions(+), 80 deletions(-) delete mode 100644 product_contract/tests/test_sale_order_line.py diff --git a/product_contract/models/sale_order.py b/product_contract/models/sale_order.py index 443eaaff72..4b356f320e 100644 --- a/product_contract/models/sale_order.py +++ b/product_contract/models/sale_order.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # 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 @@ -9,29 +10,61 @@ class SaleOrder(models.Model): _inherit = 'sale.order' is_contract = fields.Boolean( - string='Is a contract', compute="_compute_is_contract" + string='Is a contract', compute='_compute_is_contract' ) + contract_count = fields.Integer(compute='_compute_contract_count') @api.depends('order_line') def _compute_is_contract(self): - self.is_contract = any( - self.order_line.mapped('is_contract') - ) + self.is_contract = any(self.order_line.mapped('is_contract')) @api.multi def action_confirm(self): """ If we have a contract in the order, set it up """ - for rec in self: - order_lines = self.mapped('order_line').filtered( - lambda r: r.product_id.is_contract + contract_env = self.env['account.analytic.account'] + for rec in self.filtered('is_contract'): + line_to_create_contract = rec.order_line.filtered( + lambda r: not r.contract_id ) - for line in order_lines: - contract_tmpl = line.product_id.contract_template_id - contract = self.env['account.analytic.account'].create({ - 'name': '%s Contract' % rec.name, - 'partner_id': rec.partner_id.id, - 'contract_template_id': contract_tmpl.id, - }) - line.contract_id = contract.id - contract.recurring_create_invoice() + for contract_template in line_to_create_contract.mapped( + 'product_id.contract_template_id' + ): + order_lines = line_to_create_contract.filtered( + lambda r: r.product_id.contract_template_id + == contract_template + ) + contract = contract_env.create( + { + 'name': '{template_name}: {sale_name}'.format( + template_name=contract_template.name, + sale_name=rec.name, + ), + 'partner_id': rec.partner_id.id, + 'recurring_invoices': True, + 'contract_template_id': contract_template.id, + } + ) + contract._onchange_contract_template_id() + order_lines.create_contract_line(contract) + order_lines.write({'contract_id': contract.id}) + line_to_update_contract = rec.order_line.filtered('contract_id') + for line in line_to_update_contract: + line.create_contract_line(line.contract_id) 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_account_analytic_sale_overdue_all" + ).read()[0] + action["domain"] = [ + ("id", "in", self.order_line.mapped('contract_id').ids) + ] + return action diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index 23da9c1c9c..b275e67e9b 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -3,7 +3,8 @@ # Copyright 2017 ACSONE SA/NV. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import api, fields, models +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError class SaleOrderLine(models.Model): @@ -13,7 +14,13 @@ class SaleOrderLine(models.Model): string='Is a contract', related="product_id.is_contract" ) contract_id = fields.Many2one( - comodel_name='account.analytic.account', string='Contract' + comodel_name='account.analytic.account', string='Contract', copy=False + ) + contract_template_id = fields.Many2one( + comodel_name='account.analytic.contract', + string='Contract Template', + related='product_id.product_tmpl_id.contract_template_id', + readonly=True ) recurring_rule_type = fields.Selection( [ @@ -55,3 +62,54 @@ def onchange_product(self): self.product_id.recurring_invoicing_type ) self.recurring_interval = self.product_id.recurring_interval + + @api.multi + def _prepare_contract_line_values(self, contract): + self.ensure_one() + return { + 'sequence': self.sequence, + 'product_id': self.product_id.id, + 'name': self.name, + 'quantity': self.product_uom_qty, + 'uom_id': self.product_uom.id, + 'price_unit': self.price_unit, + 'discount': self.discount, + 'recurring_next_date': self.recurring_next_date + or fields.Date.today(), + 'date_end': self.date_end, + 'date_start': self.date_start or fields.Date.today(), + 'recurring_interval': self.recurring_interval, + 'recurring_invoicing_type': self.recurring_invoicing_type, + 'recurring_rule_type': self.recurring_rule_type, + 'contract_id': contract.id, + } + + @api.multi + def create_contract_line(self, contract): + contract_line = self.env['account.analytic.invoice.line'] + for rec in self: + contract_line.create(rec._prepare_contract_line_values(contract)) + + @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_template_id + != rec.contract_id.contract_template_id + ): + raise ValidationError( + _("Contract product has different contract template") + ) diff --git a/product_contract/tests/__init__.py b/product_contract/tests/__init__.py index 4766d5eabe..9d85581f33 100644 --- a/product_contract/tests/__init__.py +++ b/product_contract/tests/__init__.py @@ -5,4 +5,3 @@ from . import test_product from . import test_sale_order -from . import test_sale_order_line diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index e8f666020f..36e690b1c0 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -2,39 +2,93 @@ # Copyright 2017 LasLabs Inc. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from mock import MagicMock from odoo.tests.common import TransactionCase +from odoo.exceptions import ValidationError class TestSaleOrder(TransactionCase): - def setUp(self): super(TestSaleOrder, self).setUp() - self.product = self.env.ref('product.product_product_1') + 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 = self.env['account.analytic.contract'].create({ - 'name': 'Test', - }) - self.product.product_tmpl_id.is_contract = True - self.product.product_tmpl_id.contract_template_id = self.contract.id - - def tearDown(self): - self.env['account.analytic.account']._revert_method( - 'create', + self.contract_template1 = self.env['account.analytic.contract'].create( + {'name': 'Template 1'} + ) + self.contract_template2 = self.env['account.analytic.contract'].create( + {'name': 'Template 2'} + ) + self.product1.write( + { + 'is_contract': True, + '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 ) - super(TestSaleOrder, self).tearDown() - - def test_action_done(self): - """ It should create a contract when the sale for a contract is set - to done for the first time """ + 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) - self.env['account.analytic.account']._patch_method( - 'create', MagicMock() + + def test_action_confirm(self): + """ It should create a contract for each contract template used in + order_line """ + 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, ) + + def test_sale_contract_count(self): + """It should count contracts as many different contract template used + in order_line""" self.sale.action_confirm() - self.env['account.analytic.account'].create.assert_called_once_with({ - 'name': '%s Contract' % self.sale.name, - 'partner_id': self.sale.partner_id.id, - 'contract_template_id': self.contract.id, - }) + 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.assertEqual( + self.order_line1.recurring_rule_type, + self.product1.recurring_rule_type, + ) + self.assertEqual( + self.order_line1.recurring_interval, + self.product1.recurring_interval, + ) + self.assertEqual( + self.order_line1.recurring_invoicing_type, + self.product1.recurring_invoicing_type, + ) + + def test_check_contract_sale_partner(self): + contract2 = self.env['account.analytic.account'].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): + contract1 = self.env['account.analytic.account'].create( + { + 'name': 'Contract', + 'contract_template_id': self.contract_template1.id, + } + ) + with self.assertRaises(ValidationError): + self.order_line1.contract_id = contract1 diff --git a/product_contract/tests/test_sale_order_line.py b/product_contract/tests/test_sale_order_line.py deleted file mode 100644 index 1f10905990..0000000000 --- a/product_contract/tests/test_sale_order_line.py +++ /dev/null @@ -1,37 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright 2018 ACSONE SA/NV. -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from mock import MagicMock -from odoo.tests.common import TransactionCase - - -class TestSaleOrder(TransactionCase): - - def setUp(self): - super(TestSaleOrder, self).setUp() - self.product = self.env.ref('product.product_product_1') - self.sale = self.env.ref('sale.sale_order_2') - self.contract = self.env['account.analytic.contract'].create({ - 'name': 'Test', - }) - self.product.product_tmpl_id.is_contract = True - self.sale_order_line = self.sale.order_line.filtered( - lambda l: l.product_id == self.product - ) - - def test_onchange_product(self): - """ It should get recurrence invoicing info to the sale line from - its product """ - self.assertEqual( - self.sale_order_line.recurring_rule_type, - self.product.recurring_rule_type - ) - self.assertEqual( - self.sale_order_line.recurring_interval, - self.product.recurring_interval - ) - self.assertEqual( - self.sale_order_line.recurring_invoicing_type, - self.product.recurring_invoicing_type - ) diff --git a/product_contract/views/sale_order.xml b/product_contract/views/sale_order.xml index f27c40250b..70397c32ea 100644 --- a/product_contract/views/sale_order.xml +++ b/product_contract/views/sale_order.xml @@ -12,9 +12,27 @@ sale.order + + + + + + + Date: Fri, 2 Nov 2018 16:26:51 +0100 Subject: [PATCH 009/170] [IMP] - Link contract line to sale order line --- product_contract/models/__init__.py | 1 + product_contract/models/contract_line.py | 16 ++++++++++++++++ product_contract/models/sale_order.py | 5 ++++- product_contract/models/sale_order_line.py | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 product_contract/models/contract_line.py diff --git a/product_contract/models/__init__.py b/product_contract/models/__init__.py index 388717d23f..a275fa2175 100644 --- a/product_contract/models/__init__.py +++ b/product_contract/models/__init__.py @@ -2,6 +2,7 @@ # Copyright 2017 LasLabs Inc. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import contract_line from . import product_template from . import sale_order from . import sale_order_line diff --git a/product_contract/models/contract_line.py b/product_contract/models/contract_line.py new file mode 100644 index 0000000000..998da169cc --- /dev/null +++ b/product_contract/models/contract_line.py @@ -0,0 +1,16 @@ +# Copyright 2017 LasLabs Inc. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo import api, fields, models, _ + + +class AccountAnalyticInvoiceLine(models.Model): + _inherit = 'account.analytic.invoice.line' + + sale_order_line_id = fields.Many2one( + comodel_name="sale.order.line", + string="Sale Order Line", + required=False, + copy=False, + ) diff --git a/product_contract/models/sale_order.py b/product_contract/models/sale_order.py index 4b356f320e..a2e8487d43 100644 --- a/product_contract/models/sale_order.py +++ b/product_contract/models/sale_order.py @@ -64,7 +64,10 @@ def action_show_contracts(self): action = self.env.ref( "contract.action_account_analytic_sale_overdue_all" ).read()[0] + contracts = self.env['account.analytic.invoice.line'].search([ + ('sale_order_line', 'in', self.order_line.ids) + ]).mapped('contract_id') action["domain"] = [ - ("id", "in", self.order_line.mapped('contract_id').ids) + ("id", "in", contracts.ids) ] return action diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index b275e67e9b..1c13fdad5e 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -82,6 +82,7 @@ def _prepare_contract_line_values(self, contract): 'recurring_invoicing_type': self.recurring_invoicing_type, 'recurring_rule_type': self.recurring_rule_type, 'contract_id': contract.id, + 'sale_order_line_id': self.id, } @api.multi From 971a9b085d320849c691497bc7681fbb601fd041 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Fri, 2 Nov 2018 17:13:36 +0100 Subject: [PATCH 010/170] [FIX] - Remove recurring_next_date from sale order line recurring_next_date should be computed by contract line to get default value --- product_contract/models/contract_line.py | 2 +- product_contract/models/sale_order.py | 14 +++++++------- product_contract/models/sale_order_line.py | 13 ++++++------- product_contract/views/sale_order.xml | 3 --- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/product_contract/models/contract_line.py b/product_contract/models/contract_line.py index 998da169cc..101e544cd3 100644 --- a/product_contract/models/contract_line.py +++ b/product_contract/models/contract_line.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, fields, models, _ +from odoo import fields, models class AccountAnalyticInvoiceLine(models.Model): diff --git a/product_contract/models/sale_order.py b/product_contract/models/sale_order.py index a2e8487d43..e53fbb9189 100644 --- a/product_contract/models/sale_order.py +++ b/product_contract/models/sale_order.py @@ -26,6 +26,7 @@ def action_confirm(self): line_to_create_contract = rec.order_line.filtered( lambda r: not r.contract_id ) + line_to_update_contract = rec.order_line.filtered('contract_id') for contract_template in line_to_create_contract.mapped( 'product_id.contract_template_id' ): @@ -47,7 +48,6 @@ def action_confirm(self): contract._onchange_contract_template_id() order_lines.create_contract_line(contract) order_lines.write({'contract_id': contract.id}) - line_to_update_contract = rec.order_line.filtered('contract_id') for line in line_to_update_contract: line.create_contract_line(line.contract_id) return super(SaleOrder, self).action_confirm() @@ -64,10 +64,10 @@ def action_show_contracts(self): action = self.env.ref( "contract.action_account_analytic_sale_overdue_all" ).read()[0] - contracts = self.env['account.analytic.invoice.line'].search([ - ('sale_order_line', 'in', self.order_line.ids) - ]).mapped('contract_id') - action["domain"] = [ - ("id", "in", contracts.ids) - ] + contracts = ( + self.env['account.analytic.invoice.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 index 1c13fdad5e..70e868c4f5 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -20,7 +20,7 @@ class SaleOrderLine(models.Model): comodel_name='account.analytic.contract', string='Contract Template', related='product_id.product_tmpl_id.contract_template_id', - readonly=True + readonly=True, ) recurring_rule_type = fields.Selection( [ @@ -50,9 +50,6 @@ class SaleOrderLine(models.Model): ) date_start = fields.Date(string='Date Start', default=fields.Date.today()) date_end = fields.Date(string='Date End', index=True) - recurring_next_date = fields.Date( - default=fields.Date.today(), copy=False, string='Date of Next Invoice' - ) @api.onchange('product_id') def onchange_product(self): @@ -74,8 +71,6 @@ def _prepare_contract_line_values(self, contract): 'uom_id': self.product_uom.id, 'price_unit': self.price_unit, 'discount': self.discount, - 'recurring_next_date': self.recurring_next_date - or fields.Date.today(), 'date_end': self.date_end, 'date_start': self.date_start or fields.Date.today(), 'recurring_interval': self.recurring_interval, @@ -87,9 +82,13 @@ def _prepare_contract_line_values(self, contract): @api.multi def create_contract_line(self, contract): + contract_line_env = self.env['account.analytic.invoice.line'] contract_line = self.env['account.analytic.invoice.line'] for rec in self: - contract_line.create(rec._prepare_contract_line_values(contract)) + contract_line |= contract_line_env.create( + rec._prepare_contract_line_values(contract) + ) + contract_line._onchange_date_start() @api.constrains('contract_id') def _check_contract_sale_partner(self): diff --git a/product_contract/views/sale_order.xml b/product_contract/views/sale_order.xml index 70397c32ea..4443c39d86 100644 --- a/product_contract/views/sale_order.xml +++ b/product_contract/views/sale_order.xml @@ -56,7 +56,6 @@ - @@ -68,8 +67,6 @@ attrs="{'column_invisible': [('parent.is_contract', '=', False)]}"/> - From ac02850d02a5846766e9cfc4869b9b934365ed98 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Mon, 5 Nov 2018 11:40:58 +0100 Subject: [PATCH 011/170] [IMP] - Contract product are ignored on invoicing process - Sale order line for contract product pass to nothing to invoice on order confirmation - Contract Invoices are linked to sale order line --- product_contract/models/contract_line.py | 11 +++++- product_contract/models/sale_order.py | 6 ++- product_contract/models/sale_order_line.py | 11 ++++++ product_contract/tests/test_sale_order.py | 43 ++++++++++++++++++++++ 4 files changed, 68 insertions(+), 3 deletions(-) diff --git a/product_contract/models/contract_line.py b/product_contract/models/contract_line.py index 101e544cd3..23fcb30687 100644 --- a/product_contract/models/contract_line.py +++ b/product_contract/models/contract_line.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import fields, models +from odoo import api, fields, models class AccountAnalyticInvoiceLine(models.Model): @@ -14,3 +14,12 @@ class AccountAnalyticInvoiceLine(models.Model): required=False, copy=False, ) + + @api.multi + def _prepare_invoice_line(self, invoice_id): + res = super(AccountAnalyticInvoiceLine, self)._prepare_invoice_line( + invoice_id + ) + if self.sale_order_line_id: + res['sale_line_ids'] = [(6, 0, [self.sale_order_line_id.id])] + return res diff --git a/product_contract/models/sale_order.py b/product_contract/models/sale_order.py index e53fbb9189..3a38c1160d 100644 --- a/product_contract/models/sale_order.py +++ b/product_contract/models/sale_order.py @@ -24,9 +24,11 @@ def action_confirm(self): contract_env = self.env['account.analytic.account'] for rec in self.filtered('is_contract'): line_to_create_contract = rec.order_line.filtered( - lambda r: not r.contract_id + 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 ) - line_to_update_contract = rec.order_line.filtered('contract_id') for contract_template in line_to_create_contract.mapped( 'product_id.contract_template_id' ): diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index 70e868c4f5..6b0dc1f872 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -113,3 +113,14 @@ def _check_contract_sale_contract_template(self): raise ValidationError( _("Contract product has different contract template") ) + + def _compute_invoice_status(self): + super(SaleOrderLine, self)._compute_invoice_status() + for line in self.filtered('contract_id'): + line.invoice_status = 'no' + + @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) diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index 36e690b1c0..b3b505e8e5 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -73,6 +73,8 @@ def test_onchange_product(self): ) def test_check_contract_sale_partner(self): + """Can't link order line to a partner contract different then the + order one""" contract2 = self.env['account.analytic.account'].create( { 'name': 'Contract', @@ -84,6 +86,8 @@ def test_check_contract_sale_partner(self): 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['account.analytic.account'].create( { 'name': 'Contract', @@ -92,3 +96,42 @@ def test_check_contract_sale_contract_template(self): ) 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.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.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.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.sale.action_confirm() + invoice = self.order_line1.contract_id.recurring_create_invoice() + self.assertTrue(invoice in self.sale.invoice_ids) From 2f2329fe34614813542c70cd0bf4a2daebbdc540 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Mon, 5 Nov 2018 11:44:46 +0100 Subject: [PATCH 012/170] [FIX] - Default value for date_start applied on product change --- product_contract/models/sale_order_line.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index 6b0dc1f872..b0d14ee233 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -48,7 +48,7 @@ class SaleOrderLine(models.Model): help="Repeat every (Days/Week/Month/Year)", copy=False, ) - date_start = fields.Date(string='Date Start', default=fields.Date.today()) + date_start = fields.Date(string='Date Start') date_end = fields.Date(string='Date End', index=True) @api.onchange('product_id') @@ -59,6 +59,7 @@ def onchange_product(self): self.product_id.recurring_invoicing_type ) self.recurring_interval = self.product_id.recurring_interval + self.date_start = fields.Date.today() @api.multi def _prepare_contract_line_values(self, contract): From 99a270a08eef26a4051a70e8d9934e6e3dbc1a04 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Mon, 5 Nov 2018 14:35:38 +0100 Subject: [PATCH 013/170] [ADD] - Add readme directory --- product_contract/readme/CONTRIBUTORS.rst | 2 ++ product_contract/readme/DESCRIPTION.rst | 5 +++++ product_contract/readme/USAGE.rst | 6 ++++++ 3 files changed, 13 insertions(+) create mode 100644 product_contract/readme/CONTRIBUTORS.rst create mode 100644 product_contract/readme/DESCRIPTION.rst create mode 100644 product_contract/readme/USAGE.rst diff --git a/product_contract/readme/CONTRIBUTORS.rst b/product_contract/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..2db29075ba --- /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 0000000000..e620eb278e --- /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 0000000000..e1380d0f3d --- /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 \ No newline at end of file From 028a277fa383026ee4eb381737eb45efd8bc3612 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Mon, 5 Nov 2018 16:04:53 +0100 Subject: [PATCH 014/170] [IMP] - Onchange contract product on contract contract and contract template --- product_contract/models/__init__.py | 1 + .../models/abstract_contract_line.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 product_contract/models/abstract_contract_line.py diff --git a/product_contract/models/__init__.py b/product_contract/models/__init__.py index a275fa2175..4d43b3eac4 100644 --- a/product_contract/models/__init__.py +++ b/product_contract/models/__init__.py @@ -2,6 +2,7 @@ # Copyright 2017 LasLabs Inc. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import abstract_contract_line from . import contract_line from . import product_template from . import sale_order diff --git a/product_contract/models/abstract_contract_line.py b/product_contract/models/abstract_contract_line.py new file mode 100644 index 0000000000..1bfe4c8c89 --- /dev/null +++ b/product_contract/models/abstract_contract_line.py @@ -0,0 +1,18 @@ +# Copyright 2018 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models, fields + + +class AccountAbstractAnalyticContractLine(models.AbstractModel): + _inherit = 'account.abstract.analytic.contract.line' + + @api.onchange('product_id') + def onchange_product(self): + if self.product_id.is_contract: + self.recurring_rule_type = self.product_id.recurring_rule_type + self.recurring_invoicing_type = ( + self.product_id.recurring_invoicing_type + ) + self.recurring_interval = self.product_id.recurring_interval + self.date_start = fields.Date.today() From df588e19b85bbdfa78c01cd015c3bd0e9caf9625 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Mon, 5 Nov 2018 16:19:03 +0100 Subject: [PATCH 015/170] [FIX] - Change website to OCA repository url and prefix module name with Recurring --- product_contract/__manifest__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/product_contract/__manifest__.py b/product_contract/__manifest__.py index f369b8251f..097690917e 100644 --- a/product_contract/__manifest__.py +++ b/product_contract/__manifest__.py @@ -4,14 +4,14 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { - 'name': 'Product Contract', + 'name': 'Recurring - Product Contract', 'version': '12.0.1.0.0', 'category': 'Contract Management', 'license': 'AGPL-3', 'author': "LasLabs, " "ACSONE SA/NV, " "Odoo Community Association (OCA)", - 'website': 'https://laslabs.com', + 'website': 'https://github.com/oca/contract', 'depends': [ 'product', 'contract_sale', From f89da849b0a619c767d389305fd6643abc857910 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Mon, 5 Nov 2018 18:05:53 +0100 Subject: [PATCH 016/170] [FIX] - Compute recurring_next_date before create contract line --- product_contract/models/sale_order_line.py | 10 +++++++++- product_contract/tests/test_sale_order.py | 20 +++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index b0d14ee233..2284a33ac5 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -64,6 +64,7 @@ def onchange_product(self): @api.multi def _prepare_contract_line_values(self, contract): self.ensure_one() + contract_line_env = self.env['account.analytic.invoice.line'] return { 'sequence': self.sequence, 'product_id': self.product_id.id, @@ -74,6 +75,13 @@ def _prepare_contract_line_values(self, contract): 'discount': self.discount, 'date_end': self.date_end, 'date_start': self.date_start or fields.Date.today(), + 'recurring_next_date': + contract_line_env._compute_first_recurring_next_date( + self.date_start or fields.Date.today(), + self.recurring_invoicing_type, + self.recurring_rule_type, + self.recurring_interval, + ), 'recurring_interval': self.recurring_interval, 'recurring_invoicing_type': self.recurring_invoicing_type, 'recurring_rule_type': self.recurring_rule_type, @@ -89,7 +97,7 @@ def create_contract_line(self, contract): contract_line |= contract_line_env.create( rec._prepare_contract_line_values(contract) ) - contract_line._onchange_date_start() + return contract_line @api.constrains('contract_id') def _check_contract_sale_partner(self): diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index b3b505e8e5..e60cffff98 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -16,7 +16,25 @@ def setUp(self): {'name': 'Template 1'} ) self.contract_template2 = self.env['account.analytic.contract'].create( - {'name': 'Template 2'} + { + 'name': 'Template 2', + 'recurring_invoice_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( { From 22c4c4db105d7bb9e43c6696701165b12be9ac1d Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Thu, 15 Nov 2018 11:53:01 +0100 Subject: [PATCH 017/170] [IMP] - Upsell/Downsell contract from sale order --- product_contract/__manifest__.py | 6 +-- product_contract/models/product_template.py | 1 - product_contract/models/sale_order.py | 1 - product_contract/models/sale_order_line.py | 9 ++++- product_contract/tests/test_product.py | 1 - product_contract/tests/test_sale_order.py | 43 ++++++++++++++++++++- product_contract/views/sale_order.xml | 17 ++++---- 7 files changed, 61 insertions(+), 17 deletions(-) diff --git a/product_contract/__manifest__.py b/product_contract/__manifest__.py index 097690917e..fc85782116 100644 --- a/product_contract/__manifest__.py +++ b/product_contract/__manifest__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 LasLabs Inc. # Copyright 2018 ACSONE SA/NV. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). @@ -12,10 +11,7 @@ "ACSONE SA/NV, " "Odoo Community Association (OCA)", 'website': 'https://github.com/oca/contract', - 'depends': [ - 'product', - 'contract_sale', - ], + 'depends': ['product', 'contract_sale'], 'data': [ 'views/product_template.xml', 'views/sale_order.xml', diff --git a/product_contract/models/product_template.py b/product_contract/models/product_template.py index 1d25620197..b10ef3de87 100644 --- a/product_contract/models/product_template.py +++ b/product_contract/models/product_template.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 LasLabs Inc. # Copyright 2018 ACSONE SA/NV. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/product_contract/models/sale_order.py b/product_contract/models/sale_order.py index 3a38c1160d..ad6f969024 100644 --- a/product_contract/models/sale_order.py +++ b/product_contract/models/sale_order.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 LasLabs Inc. # Copyright 2018 ACSONE SA/NV. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index 2284a33ac5..b04345405b 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 LasLabs Inc. # Copyright 2017 ACSONE SA/NV. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). @@ -51,6 +50,13 @@ class SaleOrderLine(models.Model): date_start = fields.Date(string='Date Start') date_end = fields.Date(string='Date End', index=True) + contract_line_id = fields.Many2one( + comodel_name="account.analytic.invoice.line", + string="Contract Line to replace", + required=False, + copy=False, + ) + @api.onchange('product_id') def onchange_product(self): if self.product_id.is_contract: @@ -97,6 +103,7 @@ def create_contract_line(self, contract): contract_line |= contract_line_env.create( rec._prepare_contract_line_values(contract) ) + rec.contract_line_id.stop(rec.date_start) return contract_line @api.constrains('contract_id') diff --git a/product_contract/tests/test_product.py b/product_contract/tests/test_product.py index 3676dc057c..76d1aef842 100644 --- a/product_contract/tests/test_product.py +++ b/product_contract/tests/test_product.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 LasLabs Inc. # Copyright 2018 ACSONE SA/NV. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index e60cffff98..37feb78bfe 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -1,9 +1,10 @@ -# -*- coding: utf-8 -*- # 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 +from odoo.fields import Date class TestSaleOrder(TransactionCase): @@ -51,6 +52,36 @@ def setUp(self): self.order_line1 = self.sale.order_line.filtered( lambda l: l.product_id == self.product1 ) + self.contract = self.env["account.analytic.account"].create( + { + "name": "Test Contract 2", + "partner_id": self.sale.partner_id.id, + "pricelist_id": + self.sale.partner_id.property_product_pricelist.id, + "recurring_invoices": True, + "contract_type": "purchase", + "contract_template_id": self.contract_template1.id, + "recurring_invoice_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.recurring_invoice_line_ids[0] def test_compute_is_contract(self): """Sale Order should have is_contract true if one of its lines is @@ -153,3 +184,13 @@ def test_link_contract_invoice_to_sale_order(self): 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.order_line1.date_start = "2018-01-01" + self.sale.action_confirm() + self.assertEqual( + self.contract_line.date_end, Date.to_date("2018-01-01") + ) diff --git a/product_contract/views/sale_order.xml b/product_contract/views/sale_order.xml index 4443c39d86..b24f7fe6db 100644 --- a/product_contract/views/sale_order.xml +++ b/product_contract/views/sale_order.xml @@ -25,14 +25,17 @@ - - - - + + + + + Date: Mon, 19 Nov 2018 16:00:48 +0100 Subject: [PATCH 018/170] [ADD] - Add renewal process with termination notice --- .../models/abstract_contract_line.py | 9 ++++ product_contract/models/product_template.py | 20 +++++++ product_contract/models/sale_order_line.py | 25 +++++++-- product_contract/tests/test_sale_order.py | 27 +++++++++- product_contract/views/product_template.xml | 53 +++++++++++++------ product_contract/views/sale_order.xml | 6 ++- 6 files changed, 117 insertions(+), 23 deletions(-) diff --git a/product_contract/models/abstract_contract_line.py b/product_contract/models/abstract_contract_line.py index 1bfe4c8c89..2013cc155b 100644 --- a/product_contract/models/abstract_contract_line.py +++ b/product_contract/models/abstract_contract_line.py @@ -16,3 +16,12 @@ def onchange_product(self): ) self.recurring_interval = self.product_id.recurring_interval self.date_start = fields.Date.today() + self.is_auto_renew = self.product_id.is_auto_renew + self.auto_renew_interval = self.product_id.auto_renew_interval + self.auto_renew_rule_type = self.product_id.auto_renew_rule_type + self.termination_notice_interval = ( + self.product_id.termination_notice_interval + ) + self.termination_notice_rule_type = ( + self.product_id.termination_notice_rule_type + ) diff --git a/product_contract/models/product_template.py b/product_contract/models/product_template.py index b10ef3de87..d3fd0b5592 100644 --- a/product_contract/models/product_template.py +++ b/product_contract/models/product_template.py @@ -37,6 +37,26 @@ class ProductTemplate(models.Model): string='Repeat Every', help="Repeat every (Days/Week/Month/Year)", ) + is_auto_renew = fields.Boolean(string="Auto Renew", default=False) + auto_renew_interval = fields.Integer( + default=1, + string='Renew Every', + help="Renew every (Days/Week/Month/Year)", + ) + auto_renew_rule_type = fields.Selection( + [('monthly', 'Month(s)'), ('yearly', 'Year(s)')], + default='yearly', + string='Renewal type', + help="Specify Interval for automatic renewal.", + ) + 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): diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index b04345405b..7caaf7a3d2 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -47,8 +47,8 @@ class SaleOrderLine(models.Model): help="Repeat every (Days/Week/Month/Year)", copy=False, ) - date_start = fields.Date(string='Date Start') - date_end = fields.Date(string='Date End', index=True) + date_start = fields.Date(string='Date Start',) + date_end = fields.Date(string='Date End',) contract_line_id = fields.Many2one( comodel_name="account.analytic.invoice.line", @@ -56,6 +56,11 @@ class SaleOrderLine(models.Model): required=False, copy=False, ) + is_auto_renew = fields.Boolean( + string="Auto Renew", + related="product_id.is_auto_renew", + readonly=True, + ) @api.onchange('product_id') def onchange_product(self): @@ -65,7 +70,14 @@ def onchange_product(self): self.product_id.recurring_invoicing_type ) self.recurring_interval = self.product_id.recurring_interval - self.date_start = fields.Date.today() + self.date_start = self.date_start or fields.Date.today() + if self.product_id.is_auto_renew: + self.date_end = self.date_start + self.env[ + 'account.analytic.invoice.line' + ].get_relative_delta( + self.product_id.auto_renew_rule_type, + self.product_id.auto_renew_interval, + ) @api.multi def _prepare_contract_line_values(self, contract): @@ -91,6 +103,13 @@ def _prepare_contract_line_values(self, contract): 'recurring_interval': self.recurring_interval, '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_id.auto_renew_interval, + 'auto_renew_rule_type': self.product_id.auto_renew_rule_type, + 'termination_notice_interval': + self.product_id.termination_notice_interval, + 'termination_notice_rule_type': + self.product_id.termination_notice_rule_type, 'contract_id': contract.id, 'sale_order_line_id': self.id, } diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index 37feb78bfe..09f9d9a913 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -40,6 +40,7 @@ def setUp(self): self.product1.write( { 'is_contract': True, + 'is_auto_renew': True, 'contract_template_id': self.contract_template1.id, } ) @@ -52,6 +53,7 @@ def setUp(self): self.order_line1 = self.sale.order_line.filtered( lambda l: l.product_id == self.product1 ) + self.order_line1.date_start = '2018-01-01' self.contract = self.env["account.analytic.account"].create( { "name": "Test Contract 2", @@ -88,9 +90,14 @@ def test_compute_is_contract(self): contract""" self.assertTrue(self.sale.is_contract) + def test_action_confirm_auto_renew_without_date_end(self): + with self.assertRaises(ValidationError): + self.sale.action_confirm() + 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) @@ -102,12 +109,14 @@ def test_action_confirm(self): 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, @@ -120,6 +129,10 @@ def test_onchange_product(self): self.order_line1.recurring_invoicing_type, self.product1.recurring_invoicing_type, ) + self.assertEqual( + self.order_line1.date_end, + Date.to_date('2019-01-01'), + ) def test_check_contract_sale_partner(self): """Can't link order line to a partner contract different then the @@ -155,6 +168,7 @@ def test_no_contract_proudct(self): 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') @@ -164,6 +178,7 @@ def test_sale_order_invoice_status(self): 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') @@ -171,6 +186,7 @@ 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) @@ -181,6 +197,7 @@ def test_sale_order_create_invoice(self): 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) @@ -189,8 +206,14 @@ 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.order_line1.date_start = "2018-01-01" + self.contract_line.date_end = "2019-01-01" + self.contract_line.is_auto_renew = "2019-01-01" + 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-01-01") + self.contract_line.date_end, Date.to_date("2018-06-01") + ) + self.assertFalse( + self.contract_line.is_auto_renew ) diff --git a/product_contract/views/product_template.xml b/product_contract/views/product_template.xml index 9eb3b38fc8..0ff9f33fcc 100644 --- a/product_contract/views/product_template.xml +++ b/product_contract/views/product_template.xml @@ -19,24 +19,45 @@ - - - + + + + + - + + + + diff --git a/product_contract/views/sale_order.xml b/product_contract/views/sale_order.xml index b24f7fe6db..8493716d45 100644 --- a/product_contract/views/sale_order.xml +++ b/product_contract/views/sale_order.xml @@ -34,6 +34,8 @@ + - + - + Date: Mon, 19 Nov 2018 16:53:35 +0100 Subject: [PATCH 019/170] [IMP] - compute date end onchange date start for auto-renew sale order lines --- product_contract/models/sale_order_line.py | 16 +++++++++++++++- product_contract/views/product_template.xml | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index 7caaf7a3d2..3bef2d8584 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -71,7 +71,7 @@ def onchange_product(self): ) self.recurring_interval = self.product_id.recurring_interval self.date_start = self.date_start or fields.Date.today() - if self.product_id.is_auto_renew: + if self.is_auto_renew: self.date_end = self.date_start + self.env[ 'account.analytic.invoice.line' ].get_relative_delta( @@ -79,6 +79,20 @@ def onchange_product(self): self.product_id.auto_renew_interval, ) + @api.onchange('date_start') + def onchange_date_start(self): + for rec in self: + if rec.is_auto_renew: + if not self.date_start: + rec.date_end = False + else: + self.date_end = self.date_start + self.env[ + 'account.analytic.invoice.line' + ].get_relative_delta( + self.product_id.auto_renew_rule_type, + self.product_id.auto_renew_interval, + ) + @api.multi def _prepare_contract_line_values(self, contract): self.ensure_one() diff --git a/product_contract/views/product_template.xml b/product_contract/views/product_template.xml index 0ff9f33fcc..92bac211d9 100644 --- a/product_contract/views/product_template.xml +++ b/product_contract/views/product_template.xml @@ -21,6 +21,7 @@ Date: Mon, 26 Nov 2018 15:17:24 +0100 Subject: [PATCH 020/170] [IMP] - link contract line and its successor in upsel case --- product_contract/models/sale_order_line.py | 39 ++++++++++++---------- product_contract/tests/test_sale_order.py | 19 ++++++----- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index 3bef2d8584..4a41c2a6d5 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -47,8 +47,8 @@ class SaleOrderLine(models.Model): help="Repeat every (Days/Week/Month/Year)", copy=False, ) - date_start = fields.Date(string='Date Start',) - date_end = fields.Date(string='Date End',) + date_start = fields.Date(string='Date Start') + date_end = fields.Date(string='Date End') contract_line_id = fields.Many2one( comodel_name="account.analytic.invoice.line", @@ -57,9 +57,7 @@ class SaleOrderLine(models.Model): copy=False, ) is_auto_renew = fields.Boolean( - string="Auto Renew", - related="product_id.is_auto_renew", - readonly=True, + string="Auto Renew", related="product_id.is_auto_renew", readonly=True ) @api.onchange('product_id') @@ -107,23 +105,20 @@ def _prepare_contract_line_values(self, contract): 'discount': self.discount, 'date_end': self.date_end, 'date_start': self.date_start or fields.Date.today(), - 'recurring_next_date': - contract_line_env._compute_first_recurring_next_date( - self.date_start or fields.Date.today(), - self.recurring_invoicing_type, - self.recurring_rule_type, - self.recurring_interval, - ), + 'recurring_next_date': contract_line_env._compute_first_recurring_next_date( + self.date_start or fields.Date.today(), + self.recurring_invoicing_type, + self.recurring_rule_type, + self.recurring_interval, + ), 'recurring_interval': self.recurring_interval, '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_id.auto_renew_interval, 'auto_renew_rule_type': self.product_id.auto_renew_rule_type, - 'termination_notice_interval': - self.product_id.termination_notice_interval, - 'termination_notice_rule_type': - self.product_id.termination_notice_rule_type, + 'termination_notice_interval': self.product_id.termination_notice_interval, + 'termination_notice_rule_type': self.product_id.termination_notice_rule_type, 'contract_id': contract.id, 'sale_order_line_id': self.id, } @@ -133,10 +128,18 @@ def create_contract_line(self, contract): contract_line_env = self.env['account.analytic.invoice.line'] contract_line = self.env['account.analytic.invoice.line'] for rec in self: - contract_line |= contract_line_env.create( + new_contract_line = contract_line_env.create( rec._prepare_contract_line_values(contract) ) - rec.contract_line_id.stop(rec.date_start) + contract_line |= new_contract_line + if rec.contract_line_id: + rec.contract_line_id.stop(rec.date_start) + rec.contract_line_id.successor_contract_line_id = ( + new_contract_line + ) + new_contract_line.predecessor_contract_line_id = ( + self.contract_line_id.id + ) return contract_line @api.constrains('contract_id') diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index 09f9d9a913..de46f93cdf 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -58,8 +58,7 @@ def setUp(self): { "name": "Test Contract 2", "partner_id": self.sale.partner_id.id, - "pricelist_id": - self.sale.partner_id.property_product_pricelist.id, + "pricelist_id": self.sale.partner_id.property_product_pricelist.id, "recurring_invoices": True, "contract_type": "purchase", "contract_template_id": self.contract_template1.id, @@ -129,10 +128,7 @@ def test_onchange_product(self): self.order_line1.recurring_invoicing_type, self.product1.recurring_invoicing_type, ) - self.assertEqual( - self.order_line1.date_end, - Date.to_date('2019-01-01'), - ) + self.assertEqual(self.order_line1.date_end, Date.to_date('2019-01-01')) def test_check_contract_sale_partner(self): """Can't link order line to a partner contract different then the @@ -214,6 +210,13 @@ def test_contract_upsell(self): self.assertEqual( self.contract_line.date_end, Date.to_date("2018-06-01") ) - self.assertFalse( - self.contract_line.is_auto_renew + self.assertFalse(self.contract_line.is_auto_renew) + new_contract_line = self.env['account.analytic.invoice.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 ) From dbf6867a425ebfab7e9ee74cd5ba859529e24312 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Wed, 28 Nov 2018 18:37:31 +0100 Subject: [PATCH 021/170] [FIX] - on upsel, contract line should stop day - 1 --- product_contract/__manifest__.py | 9 ++------ product_contract/models/sale_order_line.py | 24 ++++++++++++++-------- product_contract/tests/test_sale_order.py | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/product_contract/__manifest__.py b/product_contract/__manifest__.py index fc85782116..d1dc37ee1b 100644 --- a/product_contract/__manifest__.py +++ b/product_contract/__manifest__.py @@ -7,15 +7,10 @@ 'version': '12.0.1.0.0', 'category': 'Contract Management', 'license': 'AGPL-3', - 'author': "LasLabs, " - "ACSONE SA/NV, " - "Odoo Community Association (OCA)", + 'author': "LasLabs, " "ACSONE SA/NV, " "Odoo Community Association (OCA)", 'website': 'https://github.com/oca/contract', 'depends': ['product', 'contract_sale'], - 'data': [ - 'views/product_template.xml', - 'views/sale_order.xml', - ], + 'data': ['views/product_template.xml', 'views/sale_order.xml'], 'installable': True, 'application': False, } diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index 4a41c2a6d5..07195dcc7a 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -2,6 +2,7 @@ # 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 @@ -105,20 +106,23 @@ def _prepare_contract_line_values(self, contract): 'discount': self.discount, 'date_end': self.date_end, 'date_start': self.date_start or fields.Date.today(), - 'recurring_next_date': contract_line_env._compute_first_recurring_next_date( - self.date_start or fields.Date.today(), - self.recurring_invoicing_type, - self.recurring_rule_type, - self.recurring_interval, - ), + 'recurring_next_date': + contract_line_env._compute_first_recurring_next_date( + self.date_start or fields.Date.today(), + self.recurring_invoicing_type, + self.recurring_rule_type, + self.recurring_interval, + ), 'recurring_interval': self.recurring_interval, '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_id.auto_renew_interval, 'auto_renew_rule_type': self.product_id.auto_renew_rule_type, - 'termination_notice_interval': self.product_id.termination_notice_interval, - 'termination_notice_rule_type': self.product_id.termination_notice_rule_type, + 'termination_notice_interval': + self.product_id.termination_notice_interval, + 'termination_notice_rule_type': + self.product_id.termination_notice_rule_type, 'contract_id': contract.id, 'sale_order_line_id': self.id, } @@ -133,7 +137,9 @@ def create_contract_line(self, contract): ) contract_line |= new_contract_line if rec.contract_line_id: - rec.contract_line_id.stop(rec.date_start) + rec.contract_line_id.stop( + rec.date_start - relativedelta(days=1) + ) rec.contract_line_id.successor_contract_line_id = ( new_contract_line ) diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index de46f93cdf..5409ebc392 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -208,7 +208,7 @@ def test_contract_upsell(self): self.order_line1.onchange_product() self.sale.action_confirm() self.assertEqual( - self.contract_line.date_end, Date.to_date("2018-06-01") + self.contract_line.date_end, Date.to_date("2018-05-31") ) self.assertFalse(self.contract_line.is_auto_renew) new_contract_line = self.env['account.analytic.invoice.line'].search( From d776f9743aabba0a15a57fb03ccde9cfe9a3f32a Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Thu, 29 Nov 2018 12:09:04 +0100 Subject: [PATCH 022/170] [FIX] - fix onchange --- product_contract/models/sale_order_line.py | 66 ++++++++++++---------- product_contract/tests/test_sale_order.py | 3 +- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index 07195dcc7a..836f993782 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -63,39 +63,55 @@ class SaleOrderLine(models.Model): @api.onchange('product_id') def onchange_product(self): - if self.product_id.is_contract: - self.recurring_rule_type = self.product_id.recurring_rule_type - self.recurring_invoicing_type = ( - self.product_id.recurring_invoicing_type - ) - self.recurring_interval = self.product_id.recurring_interval - self.date_start = self.date_start or fields.Date.today() - if self.is_auto_renew: - self.date_end = self.date_start + self.env[ - 'account.analytic.invoice.line' - ].get_relative_delta( - self.product_id.auto_renew_rule_type, - self.product_id.auto_renew_interval, + contract_line_env = self.env['account.analytic.invoice.line'] + for rec in self: + 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 = rec.product_id.recurring_interval + rec.date_start = rec.date_start or fields.Date.today() + if rec.is_auto_renew: + rec.date_end = ( + rec.date_start + + contract_line_env.get_relative_delta( + rec.product_id.auto_renew_rule_type, + rec.product_id.auto_renew_interval, + ) + ) @api.onchange('date_start') def onchange_date_start(self): for rec in self: if rec.is_auto_renew: - if not self.date_start: + if not rec.date_start: rec.date_end = False else: - self.date_end = self.date_start + self.env[ + rec.date_end = rec.date_start + self.env[ 'account.analytic.invoice.line' ].get_relative_delta( - self.product_id.auto_renew_rule_type, - self.product_id.auto_renew_interval, + rec.product_id.auto_renew_rule_type, + rec.product_id.auto_renew_interval, ) @api.multi def _prepare_contract_line_values(self, contract): self.ensure_one() - contract_line_env = self.env['account.analytic.invoice.line'] + recurring_next_date = self.env[ + 'account.analytic.invoice.line' + ]._compute_first_recurring_next_date( + self.date_start or fields.Date.today(), + self.recurring_invoicing_type, + self.recurring_rule_type, + self.recurring_interval, + ) + 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, @@ -106,23 +122,15 @@ def _prepare_contract_line_values(self, contract): 'discount': self.discount, 'date_end': self.date_end, 'date_start': self.date_start or fields.Date.today(), - 'recurring_next_date': - contract_line_env._compute_first_recurring_next_date( - self.date_start or fields.Date.today(), - self.recurring_invoicing_type, - self.recurring_rule_type, - self.recurring_interval, - ), + 'recurring_next_date': recurring_next_date, 'recurring_interval': self.recurring_interval, '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_id.auto_renew_interval, 'auto_renew_rule_type': self.product_id.auto_renew_rule_type, - 'termination_notice_interval': - self.product_id.termination_notice_interval, - 'termination_notice_rule_type': - self.product_id.termination_notice_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, } diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index 5409ebc392..73715d1201 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -54,11 +54,12 @@ def setUp(self): lambda l: l.product_id == self.product1 ) self.order_line1.date_start = '2018-01-01' + pricelist = self.sale.partner_id.property_product_pricelist.id self.contract = self.env["account.analytic.account"].create( { "name": "Test Contract 2", "partner_id": self.sale.partner_id.id, - "pricelist_id": self.sale.partner_id.property_product_pricelist.id, + "pricelist_id": pricelist, "recurring_invoices": True, "contract_type": "purchase", "contract_template_id": self.contract_template1.id, From d0d830655dfa9bce9a2edd4b8a1aa0b65f9d1e49 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Thu, 29 Nov 2018 12:32:22 +0100 Subject: [PATCH 023/170] [IMP] - hide recurring_invoicing_type if recurring_rule_type is monthlylastday for the monthlylastday case, pre-paid is logicly impossible, if monthlylastday is set, we consider only post-paid case --- product_contract/views/product_template.xml | 25 ++++++++++++--------- product_contract/views/sale_order.xml | 24 ++++++++++---------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/product_contract/views/product_template.xml b/product_contract/views/product_template.xml index 92bac211d9..dcc54caedb 100644 --- a/product_contract/views/product_template.xml +++ b/product_contract/views/product_template.xml @@ -26,16 +26,21 @@ - - - + + + + + + diff --git a/product_contract/views/sale_order.xml b/product_contract/views/sale_order.xml index 8493716d45..d5a75d0273 100644 --- a/product_contract/views/sale_order.xml +++ b/product_contract/views/sale_order.xml @@ -40,30 +40,30 @@ + - - - - + - + + + + - + Date: Fri, 30 Nov 2018 17:16:55 +0100 Subject: [PATCH 024/170] [FIX] - include date_end in the period if the product is_autorenew --- product_contract/models/sale_order_line.py | 15 ++++++++++----- product_contract/tests/test_sale_order.py | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index 836f993782..af93f9bf01 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -79,6 +79,7 @@ def onchange_product(self): rec.product_id.auto_renew_rule_type, rec.product_id.auto_renew_interval, ) + - relativedelta(days=1) ) @api.onchange('date_start') @@ -88,11 +89,15 @@ def onchange_date_start(self): if not rec.date_start: rec.date_end = False else: - rec.date_end = rec.date_start + self.env[ - 'account.analytic.invoice.line' - ].get_relative_delta( - rec.product_id.auto_renew_rule_type, - rec.product_id.auto_renew_interval, + rec.date_end = ( + rec.date_start + + self.env[ + 'account.analytic.invoice.line' + ].get_relative_delta( + rec.product_id.auto_renew_rule_type, + rec.product_id.auto_renew_interval, + ) + - relativedelta(days=1) ) @api.multi diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index 73715d1201..721059998b 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -129,7 +129,7 @@ def test_onchange_product(self): self.order_line1.recurring_invoicing_type, self.product1.recurring_invoicing_type, ) - self.assertEqual(self.order_line1.date_end, Date.to_date('2019-01-01')) + 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 From ede3512cdb70e4a185d873c67b36a6f08694d860 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Mon, 3 Dec 2018 13:13:10 +0100 Subject: [PATCH 025/170] [IMP] - _prepare_contract_value for sale order confirm --- product_contract/models/sale_order.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/product_contract/models/sale_order.py b/product_contract/models/sale_order.py index ad6f969024..2ae9b4e42f 100644 --- a/product_contract/models/sale_order.py +++ b/product_contract/models/sale_order.py @@ -17,6 +17,18 @@ class SaleOrder(models.Model): 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, + 'recurring_invoices': True, + 'contract_template_id': contract_template.id, + } + @api.multi def action_confirm(self): """ If we have a contract in the order, set it up """ @@ -36,15 +48,7 @@ def action_confirm(self): == contract_template ) contract = contract_env.create( - { - 'name': '{template_name}: {sale_name}'.format( - template_name=contract_template.name, - sale_name=rec.name, - ), - 'partner_id': rec.partner_id.id, - 'recurring_invoices': True, - 'contract_template_id': contract_template.id, - } + rec._prepare_contract_value(contract_template) ) contract._onchange_contract_template_id() order_lines.create_contract_line(contract) From b5c50e487251791891bf781da0d7c198a81d5fe7 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Tue, 4 Dec 2018 12:57:13 +0100 Subject: [PATCH 026/170] [REM] - Remove unused method --- product_contract/models/__init__.py | 1 - .../models/abstract_contract_line.py | 27 ------------------- product_contract/models/sale_order_line.py | 4 +-- 3 files changed, 2 insertions(+), 30 deletions(-) delete mode 100644 product_contract/models/abstract_contract_line.py diff --git a/product_contract/models/__init__.py b/product_contract/models/__init__.py index 4d43b3eac4..a275fa2175 100644 --- a/product_contract/models/__init__.py +++ b/product_contract/models/__init__.py @@ -2,7 +2,6 @@ # Copyright 2017 LasLabs Inc. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from . import abstract_contract_line from . import contract_line from . import product_template from . import sale_order diff --git a/product_contract/models/abstract_contract_line.py b/product_contract/models/abstract_contract_line.py deleted file mode 100644 index 2013cc155b..0000000000 --- a/product_contract/models/abstract_contract_line.py +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2018 ACSONE SA/NV -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from odoo import api, models, fields - - -class AccountAbstractAnalyticContractLine(models.AbstractModel): - _inherit = 'account.abstract.analytic.contract.line' - - @api.onchange('product_id') - def onchange_product(self): - if self.product_id.is_contract: - self.recurring_rule_type = self.product_id.recurring_rule_type - self.recurring_invoicing_type = ( - self.product_id.recurring_invoicing_type - ) - self.recurring_interval = self.product_id.recurring_interval - self.date_start = fields.Date.today() - self.is_auto_renew = self.product_id.is_auto_renew - self.auto_renew_interval = self.product_id.auto_renew_interval - self.auto_renew_rule_type = self.product_id.auto_renew_rule_type - self.termination_notice_interval = ( - self.product_id.termination_notice_interval - ) - self.termination_notice_rule_type = ( - self.product_id.termination_notice_rule_type - ) diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index af93f9bf01..61094b2be6 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -72,7 +72,7 @@ def onchange_product(self): ) rec.recurring_interval = rec.product_id.recurring_interval rec.date_start = rec.date_start or fields.Date.today() - if rec.is_auto_renew: + if rec.product_id.is_auto_renew: rec.date_end = ( rec.date_start + contract_line_env.get_relative_delta( @@ -85,7 +85,7 @@ def onchange_product(self): @api.onchange('date_start') def onchange_date_start(self): for rec in self: - if rec.is_auto_renew: + if rec.product_id.is_auto_renew: if not rec.date_start: rec.date_end = False else: From 6961e9a8915933ec7d55246fa2ea696d81ca5282 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Thu, 13 Dec 2018 21:46:11 +0100 Subject: [PATCH 027/170] [IMP] - get contract user from sale order user --- product_contract/models/sale_order.py | 1 + 1 file changed, 1 insertion(+) diff --git a/product_contract/models/sale_order.py b/product_contract/models/sale_order.py index 2ae9b4e42f..5a7bfd188f 100644 --- a/product_contract/models/sale_order.py +++ b/product_contract/models/sale_order.py @@ -27,6 +27,7 @@ def _prepare_contract_value(self, contract_template): 'partner_id': self.partner_id.id, 'recurring_invoices': True, 'contract_template_id': contract_template.id, + 'user_id': self.user_id.id, } @api.multi From cc5f64a96279e7fd98f2a852add0c396f6b1eaca Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Fri, 14 Dec 2018 15:55:12 +0100 Subject: [PATCH 028/170] [IMP] - show related sale orders in contract form --- product_contract/__manifest__.py | 6 ++++- product_contract/models/__init__.py | 1 + product_contract/models/contract.py | 35 +++++++++++++++++++++++++++++ product_contract/views/contract.xml | 29 ++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 product_contract/models/contract.py create mode 100644 product_contract/views/contract.xml diff --git a/product_contract/__manifest__.py b/product_contract/__manifest__.py index d1dc37ee1b..aa0f3b742f 100644 --- a/product_contract/__manifest__.py +++ b/product_contract/__manifest__.py @@ -10,7 +10,11 @@ 'author': "LasLabs, " "ACSONE SA/NV, " "Odoo Community Association (OCA)", 'website': 'https://github.com/oca/contract', 'depends': ['product', 'contract_sale'], - 'data': ['views/product_template.xml', 'views/sale_order.xml'], + 'data': [ + 'views/contract.xml', + 'views/product_template.xml', + 'views/sale_order.xml' + ], 'installable': True, 'application': False, } diff --git a/product_contract/models/__init__.py b/product_contract/models/__init__.py index a275fa2175..6ec5fa0304 100644 --- a/product_contract/models/__init__.py +++ b/product_contract/models/__init__.py @@ -2,6 +2,7 @@ # Copyright 2017 LasLabs Inc. # 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 diff --git a/product_contract/models/contract.py b/product_contract/models/contract.py new file mode 100644 index 0000000000..56279cef0d --- /dev/null +++ b/product_contract/models/contract.py @@ -0,0 +1,35 @@ +# 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.tools.translate import _ + + +class AccountAnalyticAccount(models.Model): + _name = 'account.analytic.account' + _inherit = 'account.analytic.account' + + sale_order_count = fields.Integer(compute="_compute_sale_order_count") + + @api.depends('recurring_invoice_line_ids') + def _compute_sale_order_count(self): + for rec in self: + rec.sale_order_count = len( + rec.recurring_invoice_line_ids.mapped( + 'sale_order_line_id.order_id' + ) + ) + + @api.multi + def action_view_sales_orders(self): + self.ensure_one() + orders = self.recurring_invoice_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/views/contract.xml b/product_contract/views/contract.xml new file mode 100644 index 0000000000..abf53e6e7c --- /dev/null +++ b/product_contract/views/contract.xml @@ -0,0 +1,29 @@ + + + + + + account.analytic.account + + + + + + + + + From 22c7282d4497f95cb873d8a5a18ae71c51ff6ae9 Mon Sep 17 00:00:00 2001 From: Thomas Binsfeld Date: Tue, 18 Dec 2018 14:08:31 +0100 Subject: [PATCH 029/170] [REF] Contract Product: invoice in prepare_invoice_line is optional --- product_contract/models/contract_line.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/product_contract/models/contract_line.py b/product_contract/models/contract_line.py index 23fcb30687..e067929d80 100644 --- a/product_contract/models/contract_line.py +++ b/product_contract/models/contract_line.py @@ -16,9 +16,9 @@ class AccountAnalyticInvoiceLine(models.Model): ) @api.multi - def _prepare_invoice_line(self, invoice_id): + def _prepare_invoice_line(self, invoice_id=False): res = super(AccountAnalyticInvoiceLine, self)._prepare_invoice_line( - invoice_id + invoice_id=invoice_id ) if self.sale_order_line_id: res['sale_line_ids'] = [(6, 0, [self.sale_order_line_id.id])] From a339a034f0346a61cace91bea2b57462117e6b51 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Thu, 20 Dec 2018 22:57:15 +0100 Subject: [PATCH 030/170] [FIX] - fix flake8 --- product_contract/__init__.py | 1 - product_contract/readme/USAGE.rst | 2 +- product_contract/tests/__init__.py | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/product_contract/__init__.py b/product_contract/__init__.py index 44db863b6e..c6339a004a 100644 --- a/product_contract/__init__.py +++ b/product_contract/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 LasLabs Inc. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/product_contract/readme/USAGE.rst b/product_contract/readme/USAGE.rst index e1380d0f3d..1ed5d47186 100644 --- a/product_contract/readme/USAGE.rst +++ b/product_contract/readme/USAGE.rst @@ -3,4 +3,4 @@ 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 \ No newline at end of file +#. Define default recurrence rules diff --git a/product_contract/tests/__init__.py b/product_contract/tests/__init__.py index 9d85581f33..9dad07bdb2 100644 --- a/product_contract/tests/__init__.py +++ b/product_contract/tests/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2017 LasLabs Inc. # Copyright 2018 ACSONE SA/NV. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). From ee6adbf87b63465e24d3e5cdf8f212080cbc9d33 Mon Sep 17 00:00:00 2001 From: Thomas Binsfeld Date: Fri, 21 Dec 2018 16:07:40 +0100 Subject: [PATCH 031/170] [ADD] Product Contract: payment term --- product_contract/models/sale_order.py | 1 + 1 file changed, 1 insertion(+) diff --git a/product_contract/models/sale_order.py b/product_contract/models/sale_order.py index 5a7bfd188f..6c92feefe0 100644 --- a/product_contract/models/sale_order.py +++ b/product_contract/models/sale_order.py @@ -28,6 +28,7 @@ def _prepare_contract_value(self, contract_template): 'recurring_invoices': True, 'contract_template_id': contract_template.id, 'user_id': self.user_id.id, + 'payment_term_id': self.payment_term_id.id, } @api.multi From cae7829d78ddbf8abddbc92797ac661fba36b824 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Fri, 28 Dec 2018 12:36:19 +0100 Subject: [PATCH 032/170] [IMP] - update invoice_line vals only if it is not null --- product_contract/models/contract_line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/product_contract/models/contract_line.py b/product_contract/models/contract_line.py index e067929d80..0a7a4015ab 100644 --- a/product_contract/models/contract_line.py +++ b/product_contract/models/contract_line.py @@ -20,6 +20,6 @@ def _prepare_invoice_line(self, invoice_id=False): res = super(AccountAnalyticInvoiceLine, self)._prepare_invoice_line( invoice_id=invoice_id ) - if self.sale_order_line_id: + if self.sale_order_line_id and res: res['sale_line_ids'] = [(6, 0, [self.sale_order_line_id.id])] return res From 82c5906436078043d243d0c354d522c737cec8ef Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Thu, 3 Jan 2019 11:51:44 +0100 Subject: [PATCH 033/170] [FIX] - fix unit tests --- product_contract/tests/test_sale_order.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index 721059998b..d3c29572ce 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -2,6 +2,7 @@ # 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 @@ -61,7 +62,7 @@ def setUp(self): "partner_id": self.sale.partner_id.id, "pricelist_id": pricelist, "recurring_invoices": True, - "contract_type": "purchase", + "contract_type": "sale", "contract_template_id": self.contract_template1.id, "recurring_invoice_line_ids": [ ( @@ -203,8 +204,8 @@ 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 = "2019-01-01" - self.contract_line.is_auto_renew = "2019-01-01" + 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() From c4bcab43b84aeacf19c385acd3b8f6ae2ec13783 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Thu, 10 Jan 2019 17:03:30 +0100 Subject: [PATCH 034/170] [IMP] - Add unit test --- product_contract/models/contract_line.py | 20 +++++++++++++ product_contract/tests/test_sale_order.py | 35 +++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/product_contract/models/contract_line.py b/product_contract/models/contract_line.py index 0a7a4015ab..ca5cd9a5c9 100644 --- a/product_contract/models/contract_line.py +++ b/product_contract/models/contract_line.py @@ -23,3 +23,23 @@ def _prepare_invoice_line(self, invoice_id=False): if self.sale_order_line_id and res: res['sale_line_ids'] = [(6, 0, [self.sale_order_line_id.id])] return res + + @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 = rec.product_id.recurring_interval + rec.is_auto_renew = rec.product_id.is_auto_renew + rec.auto_renew_interval = rec.product_id.auto_renew_interval + rec.auto_renew_rule_type = rec.product_id.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 + ) diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index d3c29572ce..a13aa121d2 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -222,3 +222,38 @@ def test_contract_upsell(self): self.assertEqual( new_contract_line.predecessor_contract_line_id, self.contract_line ) + + def test_onchange_product_id_recurring_info(self): + self.product2.write( + { + 'recurring_rule_type': 'monthly', + 'recurring_invoicing_type': 'pre-paid', + 'recurring_interval': '2', + 'is_auto_renew': True, + 'auto_renew_interval': '6', + 'auto_renew_rule_type': 'monthly', + '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, 2) + self.assertEqual(self.contract_line.is_auto_renew, True) + self.assertEqual(self.contract_line.auto_renew_interval, 6) + 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' + ) From a35d38f08b5321ea6052e50cea4f1f1139d31e8d Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Tue, 15 Jan 2019 13:37:17 +0100 Subject: [PATCH 035/170] [REF] - predecessor_contract_line set in create process --- product_contract/models/sale_order_line.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index 61094b2be6..a99f96d3d7 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -101,7 +101,9 @@ def onchange_date_start(self): ) @api.multi - def _prepare_contract_line_values(self, contract): + def _prepare_contract_line_values( + self, contract, predecessor_contract_line + ): self.ensure_one() recurring_next_date = self.env[ 'account.analytic.invoice.line' @@ -138,6 +140,7 @@ def _prepare_contract_line_values(self, contract): '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 @@ -145,20 +148,19 @@ def create_contract_line(self, contract): contract_line_env = self.env['account.analytic.invoice.line'] contract_line = self.env['account.analytic.invoice.line'] for rec in self: - new_contract_line = contract_line_env.create( - rec._prepare_contract_line_values(contract) - ) - contract_line |= new_contract_line if rec.contract_line_id: rec.contract_line_id.stop( rec.date_start - relativedelta(days=1) ) + new_contract_line = contract_line_env.create( + rec._prepare_contract_line_values(contract, + rec.contract_line_id) + ) + if rec.contract_line_id: rec.contract_line_id.successor_contract_line_id = ( new_contract_line ) - new_contract_line.predecessor_contract_line_id = ( - self.contract_line_id.id - ) + contract_line |= new_contract_line return contract_line @api.constrains('contract_id') From 15b02c3bf7b04d46585f04d34dfe0203d6f31a58 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Mon, 21 Jan 2019 19:02:48 +0100 Subject: [PATCH 036/170] [IMP] - Simplify sale order line creation for contract product --- product_contract/__manifest__.py | 4 +- product_contract/models/contract_line.py | 6 +- product_contract/models/product_template.py | 20 +---- product_contract/models/sale_order_line.py | 82 ++++++++++----------- product_contract/tests/test_sale_order.py | 19 ++--- product_contract/views/product_template.xml | 18 +---- product_contract/views/sale_order.xml | 14 +--- 7 files changed, 59 insertions(+), 104 deletions(-) diff --git a/product_contract/__manifest__.py b/product_contract/__manifest__.py index aa0f3b742f..5f11289426 100644 --- a/product_contract/__manifest__.py +++ b/product_contract/__manifest__.py @@ -7,7 +7,9 @@ 'version': '12.0.1.0.0', 'category': 'Contract Management', 'license': 'AGPL-3', - 'author': "LasLabs, " "ACSONE SA/NV, " "Odoo Community Association (OCA)", + 'author': "LasLabs, " + "ACSONE SA/NV, " + "Odoo Community Association (OCA)", 'website': 'https://github.com/oca/contract', 'depends': ['product', 'contract_sale'], 'data': [ diff --git a/product_contract/models/contract_line.py b/product_contract/models/contract_line.py index ca5cd9a5c9..1e0cd4fef5 100644 --- a/product_contract/models/contract_line.py +++ b/product_contract/models/contract_line.py @@ -33,10 +33,10 @@ def _onchange_product_id_recurring_info(self): rec.recurring_invoicing_type = ( rec.product_id.recurring_invoicing_type ) - rec.recurring_interval = rec.product_id.recurring_interval + rec.recurring_interval = 1 rec.is_auto_renew = rec.product_id.is_auto_renew - rec.auto_renew_interval = rec.product_id.auto_renew_interval - rec.auto_renew_rule_type = rec.product_id.auto_renew_rule_type + rec.auto_renew_interval = rec.product_id.default_qty + rec.auto_renew_rule_type = rec.product_id.recurring_rule_type rec.termination_notice_interval = ( rec.product_id.termination_notice_interval ) diff --git a/product_contract/models/product_template.py b/product_contract/models/product_template.py index d3fd0b5592..f73cc3afdf 100644 --- a/product_contract/models/product_template.py +++ b/product_contract/models/product_template.py @@ -13,7 +13,7 @@ class ProductTemplate(models.Model): contract_template_id = fields.Many2one( comodel_name='account.analytic.contract', string='Contract Template' ) - + default_qty = fields.Integer(string="Default Quantity") recurring_rule_type = fields.Selection( [ ('daily', 'Day(s)'), @@ -23,7 +23,7 @@ class ProductTemplate(models.Model): ('yearly', 'Year(s)'), ], default='monthly', - string='Recurrence', + string='Invoice Every', help="Specify Interval for automatic invoice generation.", ) recurring_invoicing_type = fields.Selection( @@ -32,23 +32,7 @@ class ProductTemplate(models.Model): string='Invoicing type', help="Specify if process date is 'from' or 'to' invoicing date", ) - recurring_interval = fields.Integer( - default=1, - string='Repeat Every', - help="Repeat every (Days/Week/Month/Year)", - ) is_auto_renew = fields.Boolean(string="Auto Renew", default=False) - auto_renew_interval = fields.Integer( - default=1, - string='Renew Every', - help="Renew every (Days/Week/Month/Year)", - ) - auto_renew_rule_type = fields.Selection( - [('monthly', 'Month(s)'), ('yearly', 'Year(s)')], - default='yearly', - string='Renewal type', - help="Specify Interval for automatic renewal.", - ) termination_notice_interval = fields.Integer( default=1, string='Termination Notice Before' ) diff --git a/product_contract/models/sale_order_line.py b/product_contract/models/sale_order_line.py index a99f96d3d7..049f778c13 100644 --- a/product_contract/models/sale_order_line.py +++ b/product_contract/models/sale_order_line.py @@ -31,8 +31,7 @@ class SaleOrderLine(models.Model): ('yearly', 'Year(s)'), ], default='monthly', - string='Recurrence', - help="Specify Interval for automatic invoice generation.", + string='Invoice Every', copy=False, ) recurring_invoicing_type = fields.Selection( @@ -42,12 +41,6 @@ class SaleOrderLine(models.Model): help="Specify if process date is 'from' or 'to' invoicing date", copy=False, ) - recurring_interval = fields.Integer( - default=1, - string='Repeat Every', - help="Repeat every (Days/Week/Month/Year)", - copy=False, - ) date_start = fields.Date(string='Date Start') date_end = fields.Date(string='Date End') @@ -57,48 +50,42 @@ class SaleOrderLine(models.Model): required=False, copy=False, ) - is_auto_renew = fields.Boolean( - string="Auto Renew", related="product_id.is_auto_renew", readonly=True - ) @api.onchange('product_id') def onchange_product(self): contract_line_env = self.env['account.analytic.invoice.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.recurring_interval = rec.product_id.recurring_interval rec.date_start = rec.date_start or fields.Date.today() - if rec.product_id.is_auto_renew: - rec.date_end = ( - rec.date_start - + contract_line_env.get_relative_delta( - rec.product_id.auto_renew_rule_type, - rec.product_id.auto_renew_interval, - ) - - relativedelta(days=1) + rec.date_end = ( + rec.date_start + + contract_line_env.get_relative_delta( + rec.product_id.recurring_rule_type, + int(rec.product_uom_qty), ) + - relativedelta(days=1) + ) - @api.onchange('date_start') + @api.onchange('date_start', 'product_uom_qty', 'recurring_rule_type') def onchange_date_start(self): for rec in self: - if rec.product_id.is_auto_renew: - if not rec.date_start: - rec.date_end = False - else: - rec.date_end = ( - rec.date_start - + self.env[ - 'account.analytic.invoice.line' - ].get_relative_delta( - rec.product_id.auto_renew_rule_type, - rec.product_id.auto_renew_interval, - ) - - relativedelta(days=1) + if not rec.date_start: + rec.date_end = False + else: + rec.date_end = ( + rec.date_start + + self.env[ + 'account.analytic.invoice.line' + ].get_relative_delta( + rec.recurring_rule_type, int(rec.product_uom_qty) ) + - relativedelta(days=1) + ) @api.multi def _prepare_contract_line_values( @@ -111,7 +98,7 @@ def _prepare_contract_line_values( self.date_start or fields.Date.today(), self.recurring_invoicing_type, self.recurring_rule_type, - self.recurring_interval, + int(self.product_uom_qty), ) termination_notice_interval = ( self.product_id.termination_notice_interval @@ -123,19 +110,31 @@ def _prepare_contract_line_values( 'sequence': self.sequence, 'product_id': self.product_id.id, 'name': self.name, - 'quantity': self.product_uom_qty, + # 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': self.recurring_interval, + '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_id.auto_renew_interval, - 'auto_renew_rule_type': self.product_id.auto_renew_rule_type, + 'auto_renew_interval': self.product_uom_qty, + 'auto_renew_rule_type': self.product_id.recurring_rule_type, 'termination_notice_interval': termination_notice_interval, 'termination_notice_rule_type': termination_notice_rule_type, 'contract_id': contract.id, @@ -153,8 +152,9 @@ def create_contract_line(self, contract): rec.date_start - relativedelta(days=1) ) new_contract_line = contract_line_env.create( - rec._prepare_contract_line_values(contract, - rec.contract_line_id) + rec._prepare_contract_line_values( + contract, rec.contract_line_id + ) ) if rec.contract_line_id: rec.contract_line_id.successor_contract_line_id = ( diff --git a/product_contract/tests/test_sale_order.py b/product_contract/tests/test_sale_order.py index a13aa121d2..3318065933 100644 --- a/product_contract/tests/test_sale_order.py +++ b/product_contract/tests/test_sale_order.py @@ -41,7 +41,7 @@ def setUp(self): self.product1.write( { 'is_contract': True, - 'is_auto_renew': True, + 'default_qty': 12, 'contract_template_id': self.contract_template1.id, } ) @@ -55,6 +55,7 @@ def setUp(self): 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["account.analytic.account"].create( { @@ -91,10 +92,6 @@ def test_compute_is_contract(self): contract""" self.assertTrue(self.sale.is_contract) - def test_action_confirm_auto_renew_without_date_end(self): - with self.assertRaises(ValidationError): - self.sale.action_confirm() - def test_action_confirm(self): """ It should create a contract for each contract template used in order_line """ @@ -122,10 +119,6 @@ def test_onchange_product(self): self.order_line1.recurring_rule_type, self.product1.recurring_rule_type, ) - self.assertEqual( - self.order_line1.recurring_interval, - self.product1.recurring_interval, - ) self.assertEqual( self.order_line1.recurring_invoicing_type, self.product1.recurring_invoicing_type, @@ -228,10 +221,8 @@ def test_onchange_product_id_recurring_info(self): { 'recurring_rule_type': 'monthly', 'recurring_invoicing_type': 'pre-paid', - 'recurring_interval': '2', 'is_auto_renew': True, - 'auto_renew_interval': '6', - 'auto_renew_rule_type': 'monthly', + 'default_qty': 12, 'termination_notice_interval': '6', 'termination_notice_rule_type': 'weekly', } @@ -249,9 +240,9 @@ def test_onchange_product_id_recurring_info(self): self.assertEqual( self.contract_line.recurring_invoicing_type, 'pre-paid' ) - self.assertEqual(self.contract_line.recurring_interval, 2) + 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, 6) + 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( diff --git a/product_contract/views/product_template.xml b/product_contract/views/product_template.xml index dcc54caedb..fd26d5555b 100644 --- a/product_contract/views/product_template.xml +++ b/product_contract/views/product_template.xml @@ -29,30 +29,16 @@ - + -