diff --git a/contract_purchase/README.rst b/contract_purchase/README.rst new file mode 100644 index 00000000..170698c3 --- /dev/null +++ b/contract_purchase/README.rst @@ -0,0 +1,63 @@ +.. 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 + +================= +Contract Purchase +================= + +This module is an add on to the odoo contract module (v9). It applies contract functions for purchases. + +Usage +===== + +To use this module, you need to: + +#. Go to Purchases -> Contracts and select or create a new contract. +#. Define type purchase contract + +------------------from here on everything applies like in the contract module------------------ + +.. 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/9.0 + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 + +Known issues / Roadmap +====================== +PLACEHOLDER + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback +`here `_. + +Credits +======= + +Contributors +------------ + +* Stefan Becker + + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://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 http://odoo-community.org. diff --git a/contract_purchase/__init__.py b/contract_purchase/__init__.py new file mode 100644 index 00000000..a0fdc10f --- /dev/null +++ b/contract_purchase/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import models diff --git a/contract_purchase/__openerp__.py b/contract_purchase/__openerp__.py new file mode 100644 index 00000000..8392f8de --- /dev/null +++ b/contract_purchase/__openerp__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# © Stefan Becker +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Purchase Contract', + 'summary': 'Create purchase contract', + 'version': '9.0.1.0.0', + 'author': "humanilog, " + "Odoo Community Association (OCA)", + 'website': 'http://www.humanilog.org/', + 'depends': ['contract', 'purchase'], + 'category': 'Purchase Management', + 'license': 'AGPL-3', + 'data': [ + 'views/contract_view.xml', + ], + 'installable': True, +} diff --git a/contract_purchase/models/__init__.py b/contract_purchase/models/__init__.py new file mode 100644 index 00000000..d90384df --- /dev/null +++ b/contract_purchase/models/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import account diff --git a/contract_purchase/models/account.py b/contract_purchase/models/account.py new file mode 100644 index 00000000..eb9b9d7f --- /dev/null +++ b/contract_purchase/models/account.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +# © 2015 Angel Moya +# © 2016 Carlos Dauden +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import api, fields, models, _ + + +class AccountAnalyticAccount(models.Model): + _inherit = 'account.analytic.account' + + type = fields.Selection(selection_add=[ + ('purchase', _('Purchase')) + ]) + + @api.multi + def _prepare_invoice(self): + self.ensure_one() + + if self.type == 'purchase': + journal = self.env['account.journal'].search([ + ('type', '=', 'purchase'), + ('company_id', '=', self.company_id.id) + ], limit=1) + + res = super( + AccountAnalyticAccount, + self.with_context( + contract_journal=journal + ) + )._prepare_invoice() + + res.update({ + 'journal_id': journal.id, + 'type': 'in_invoice' + }) + + return res + else: + return super(AccountAnalyticAccount, self)._prepare_invoice() + + return res + + def fields_get( + self, cr, user, allfields=None, context=None, write_access=True, + attributes=None + ): + if not context: + context = {} + + res = super(AccountAnalyticAccount, self).fields_get( + cr, user, allfields, context, write_access, attributes) + if all(( + 'partner_id' in res, + context.get('default_type') == 'contract_purchase' + )): + res['partner_id']['string'] = _("Vendor") + return res + + @api.onchange('type') + def onchange_type(self): + if self.type == 'purchase': + self.journal_id = self.env['account.journal'].search([ + ('type', '=', 'purchase'), + ('company_id', '=', self.company_id.id) + ], limit=1) + + super(AccountAnalyticAccount, self)._onchange_type() diff --git a/contract_purchase/views/contract_view.xml b/contract_purchase/views/contract_view.xml new file mode 100644 index 00000000..1f05aac5 --- /dev/null +++ b/contract_purchase/views/contract_view.xml @@ -0,0 +1,38 @@ + + + + + account.analytic.account.type + account.analytic.account + + + + + + + + + + Contracts + account.analytic.account + form + tree,form + [('type', '=', 'purchase')] + { + 'search_default_active':1, + 'search_default_recurring_invoices':1, + 'default_type': 'purchase' + } + + +

+ Click to create a new purchase contract. +

+
+
+ + +
+