diff --git a/product_contract/README.rst b/product_contract/README.rst new file mode 100644 index 000000000..6319dcf55 --- /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 000000000..44db863b6 --- /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 000000000..e1d4d8ac6 --- /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 000000000..3b62b5447 --- /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 000000000..a89a0a122 --- /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 000000000..1efcaf7ce --- /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 000000000..7f2b4f8c1 --- /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 000000000..922d93fb1 --- /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 000000000..982bdf76c --- /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 000000000..4c309a250 --- /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 000000000..592c6aaec --- /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 000000000..5bcb2f7ed --- /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 000000000..388717d23 --- /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 000000000..fd7e00d4c --- /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 000000000..45f2eec77 --- /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 000000000..c76c10595 --- /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 000000000..e5fbe249a --- /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 000000000..2938cc7f9 --- /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 000000000..7ca4c0999 --- /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 000000000..46c2e05c5 --- /dev/null +++ b/product_contract/views/product_template_view.xml @@ -0,0 +1,29 @@ + + + + + + + + account.invoice.select.contract + product.template + + + +
+ +
+
+ + + +
+
+ +