From 4a1b55d617dd060f6dd115c55f76bd0122c544ab Mon Sep 17 00:00:00 2001 From: elacunza Date: Sun, 6 Nov 2016 11:02:07 +0100 Subject: [PATCH] [ADD] [8.0] contract_account_banking_mandate (#38) --- contract_account_banking_mandate/README.rst | 39 +++++++++++ contract_account_banking_mandate/__init__.py | 4 ++ .../__openerp__.py | 22 ++++++ contract_account_banking_mandate/i18n/es.po | 23 +++++++ .../models/__init__.py | 4 ++ .../models/account_analytic_account.py | 20 ++++++ .../contract_account_banking_mandate.yml | 68 +++++++++++++++++++ .../views/contract_view.xml | 19 ++++++ 8 files changed, 199 insertions(+) create mode 100644 contract_account_banking_mandate/README.rst create mode 100644 contract_account_banking_mandate/__init__.py create mode 100644 contract_account_banking_mandate/__openerp__.py create mode 100644 contract_account_banking_mandate/i18n/es.po create mode 100644 contract_account_banking_mandate/models/__init__.py create mode 100644 contract_account_banking_mandate/models/account_analytic_account.py create mode 100644 contract_account_banking_mandate/tests/contract_account_banking_mandate.yml create mode 100644 contract_account_banking_mandate/views/contract_view.xml diff --git a/contract_account_banking_mandate/README.rst b/contract_account_banking_mandate/README.rst new file mode 100644 index 00000000..5d17b95a --- /dev/null +++ b/contract_account_banking_mandate/README.rst @@ -0,0 +1,39 @@ +.. 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 Account Banking Mandate +================================ + +This module adds an account banking mandate field to contracts. This is used +for the creation of recurring invoices. + +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 +------------ + +* Eneko Lacunza (Binovo) + +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_account_banking_mandate/__init__.py b/contract_account_banking_mandate/__init__.py new file mode 100644 index 00000000..c04e830a --- /dev/null +++ b/contract_account_banking_mandate/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Binovo IT Human Project SL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import models diff --git a/contract_account_banking_mandate/__openerp__.py b/contract_account_banking_mandate/__openerp__.py new file mode 100644 index 00000000..eaaf5fa6 --- /dev/null +++ b/contract_account_banking_mandate/__openerp__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Binovo IT Human Project SL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Contract Account Banking Mandate", + "version": "8.0.1.0.0", + "depends": [ + "account_analytic_analysis", "account_banking_mandate" + ], + "author": "Binovo IT Human Project SL, Odoo Community Association (OCA)", + "category": 'Sales Management', + "website": "http://www.binovo.es", + "summary": "Add banking mandate field to contracts for their invoices", + "data": [ + "views/contract_view.xml", + ], + "test": [ + "tests/contract_account_banking_mandate.yml" + ], + "installable": True, + "auto_install": False, +} diff --git a/contract_account_banking_mandate/i18n/es.po b/contract_account_banking_mandate/i18n/es.po new file mode 100644 index 00000000..d2d65cb5 --- /dev/null +++ b/contract_account_banking_mandate/i18n/es.po @@ -0,0 +1,23 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_banking_mandate +# +# Translators: +msgid "" +msgstr "" +"Project-Id-Version: bank-payment (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-04-08 00:46+0000\n" +"PO-Revision-Date: 2016-04-07 16:04+0000\n" +"Last-Translator: OCA Transbot \n" +"Language-Team: Spanish (http://www.transifex.com/oca/OCA-bank-payment-8-0/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: contract_account_banking_mandate +#: field:account.analytic.account,mandate_id:0 +msgid "Direct Debit Mandate" +msgstr "Mandato de adeudo directo" diff --git a/contract_account_banking_mandate/models/__init__.py b/contract_account_banking_mandate/models/__init__.py new file mode 100644 index 00000000..153ed0aa --- /dev/null +++ b/contract_account_banking_mandate/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Binovo IT Human Project SL +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import account_analytic_account diff --git a/contract_account_banking_mandate/models/account_analytic_account.py b/contract_account_banking_mandate/models/account_analytic_account.py new file mode 100644 index 00000000..63fc4aa7 --- /dev/null +++ b/contract_account_banking_mandate/models/account_analytic_account.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Binovo IT Human Project SL +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +from openerp import models, fields, api + + +class AccountAnalyticAccount(models.Model): + _inherit = 'account.analytic.account' + + mandate_id = fields.Many2one( + 'account.banking.mandate', string='Direct Debit Mandate', + domain=[('state', '=', 'valid')]) + + @api.model + def _prepare_invoice_data(self, contract): + invoice_vals = super(AccountAnalyticAccount, self).\ + _prepare_invoice_data(contract) + if contract.mandate_id: + invoice_vals['mandate_id'] = contract.mandate_id.id + return invoice_vals diff --git a/contract_account_banking_mandate/tests/contract_account_banking_mandate.yml b/contract_account_banking_mandate/tests/contract_account_banking_mandate.yml new file mode 100644 index 00000000..4b9addf0 --- /dev/null +++ b/contract_account_banking_mandate/tests/contract_account_banking_mandate.yml @@ -0,0 +1,68 @@ +- + In order to test mandates in contracts, create a partner with a bank account. + Then, create two mandates, and validate them. + Finally, create a contract with mandate2, create a recurring invoice and + check that the invoice has set the contract mandate (mandate2). + + Create a partner +- + !record {model: res.partner, id: test_partner, view: False}: + name: "Contract mandate test" +- + Create a partner bank account +- + !record {model: res.partner.bank, id: test_partner_bank, view: False}: + state: 'bank' + acc_number: '1234' + partner_id: test_partner +- + Create mandate1 on 1st January +- + !record {model: account.banking.mandate, id: test_mandate1, view: False}: + partner_bank_id: test_partner_bank + signature_date: "2014-01-01" +- + Create mandate2 on 15th February +- + !record {model: account.banking.mandate, id: test_mandate2, view: False}: + partner_bank_id: test_partner_bank + signature_date: "2015-02-15" +- + Validate both mandates +- + !python {model: account.banking.mandate}: | + self.validate(cr, uid, [ref('test_mandate1')]) + self.validate(cr, uid, [ref('test_mandate2')]) +- + Create new contract with a mandate2 +- + !record {model: account.analytic.account, id: test_contract}: + name: Recurring with mandate + company_id: base.main_company + partner_id: base.main_partner + type: contract + recurring_invoices : 1 + recurring_interval : 1 + recurring_rule_type: 'monthly' + recurring_next_date: '2016-02-29' + recurring_invoice_line_ids: + - quantity: 2.0 + price_unit: 100.0 + name: Database Administration 25 + product_id: product.product_product_consultant + uom_id: product.product_uom_hour + mandate_id: test_mandate2 +- + Generate all invoices from contracts having recurring invoicing +- + !python {model: account.analytic.account}: | + self.recurring_create_invoice(cr, uid, []) +- + Check created invoice has mandate2 +- + !python {model: account.invoice}: | + aid = ref('test_contract') + ids = self.search(cr, uid, [('invoice_line.account_analytic_id','=',aid)], context=context) + assert len(ids) == 1, "Expected exactly one invoice created for the contract, got %d"%(len(ids)) + for invoice in self.browse(cr, uid, ids,context=context): + assert invoice.mandate_id.id == ref('test_mandate2'), "Recurring invoice has mandate id %d, but should have mandate id %d"%(invoice.mandate_id.id, ref('test_mandate2')) diff --git a/contract_account_banking_mandate/views/contract_view.xml b/contract_account_banking_mandate/views/contract_view.xml new file mode 100644 index 00000000..fa161ee1 --- /dev/null +++ b/contract_account_banking_mandate/views/contract_view.xml @@ -0,0 +1,19 @@ + + + + + + + account.analytic.account.form.form.mandate + account.analytic.account + + + + + + + + +