Skip to content

Commit

Permalink
[9.0][ADD] contract_mandate: New module
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdauden committed Jun 3, 2017
1 parent 6c22269 commit e47f043
Show file tree
Hide file tree
Showing 9 changed files with 281 additions and 0 deletions.
63 changes: 63 additions & 0 deletions contract_mandate/README.rst
Original file line number Diff line number Diff line change
@@ -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 Mandate
================

This module allows to set a mandate mode on contract for creating the invoices
with this mandate.

Configuration
=============

Your user should be a Sales Manager or Accountant.

Usage
=====

#. Go to *Sales > Sales > Contracts*.
#. Create one.
#. Select a partner to which invoice.
#. Select a mandate.
#. Click on **Generate recurring invoices automatically** checkbox.
#. Add a product to invoice.
#. If you create an invoice, new invoice will have the selected mandate.


.. 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

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/contract/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
=======

Contributors
------------

* Carlos Dauden <carlos.dauden@tecnativa.com>


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.
3 changes: 3 additions & 0 deletions contract_mandate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import models
23 changes: 23 additions & 0 deletions contract_mandate/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Carlos Dauden - Tecnativa <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Contract Mandate',
'summary': 'Mandate in contracts and their invoices',
'version': '9.0.1.0.0',
'author': 'Tecnativa, '
'Odoo Community Association (OCA)',
'website': 'http://www.tecnativa.com',
'depends': [
'contract_payment_mode',
'account_banking_mandate',
],
'category': 'Sales Management',
'license': 'AGPL-3',
'data': [
'views/contract_view.xml',
],
'installable': True,
'auto_install': True,
}
50 changes: 50 additions & 0 deletions contract_mandate/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * contract_mandate
#
# Translators:
# OCA Transbot <transbot@odoo-community.org>, 2017
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 9.0c\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-06-03 14:32+0200\n"
"PO-Revision-Date: 2017-06-03 15:01+0200\n"
"Last-Translator: Carlos Dauden <carlos.dauden@tecnativa.com>\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: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 1.8.7.1\n"

#. module: contract_mandate
#: model:ir.model.fields,help:contract_mandate.field_account_analytic_account_mandate_required
msgid "Activate this option if this payment method requires your customer to sign a direct debit mandate with your company."
msgstr ""

#. module: contract_mandate
#: model:ir.model,name:contract_mandate.model_account_analytic_account
msgid "Analytic Account"
msgstr ""

#. module: contract_mandate
#: model:ir.model.fields,field_description:contract_mandate.field_account_analytic_account_commercial_partner_id
msgid "Commercial Entity"
msgstr "Entidad comercial"

#. module: contract_mandate
#: model:ir.model.fields,field_description:contract_mandate.field_account_analytic_account_mandate_id
msgid "Direct Debit Mandate"
msgstr "Mandato adeudo directo"

#. module: contract_mandate
#: model:ir.model.fields,help:contract_mandate.field_account_analytic_account_mandate_id
msgid "If mandate required in payment method and not set mandate, invoice takes the first valid mandate"
msgstr "Si el mandato es requerido en el método de pago y no está informado en el contrato, la factura coge el primer mandato válido"

#. module: contract_mandate
#: model:ir.model.fields,field_description:contract_mandate.field_account_analytic_account_mandate_required
msgid "Mandate Required"
msgstr "Mandato requerido"
3 changes: 3 additions & 0 deletions contract_mandate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import contract
38 changes: 38 additions & 0 deletions contract_mandate/models/contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Carlos Dauden - Tecnativa <carlos.dauden@tecnativa.com>
# 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'

mandate_id = fields.Many2one(
comodel_name='account.banking.mandate',
ondelete='restrict',
string='Direct Debit Mandate',
help="If mandate required in payment method and not set mandate, "
"invoice takes the first valid mandate"
)
mandate_required = fields.Boolean(
related='payment_mode_id.payment_method_id.mandate_required',
readonly=True)
commercial_partner_id = fields.Many2one(
related='partner_id.commercial_partner_id',
readonly=True,
string='Commercial Entity',
)

@api.multi
def _prepare_invoice(self):
invoice_vals = super(AccountAnalyticAccount, self)._prepare_invoice()
if self.mandate_id:
invoice_vals['mandate_id'] = self.mandate_id.id
elif self.payment_mode_id.payment_method_id.mandate_required:
mandate = self.env['account.banking.mandate'].search([
('partner_id', '=', self.partner_id.commercial_partner_id.id),
('state', '=', 'valid'),
], limit=1)
invoice_vals['mandate_id'] = mandate.id
return invoice_vals
3 changes: 3 additions & 0 deletions contract_mandate/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import test_contract_mandate
80 changes: 80 additions & 0 deletions contract_mandate/tests/test_contract_mandate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Carlos Dauden - Tecnativa <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp.tests import common


class TestContractMandate(common.SavepointCase):
@classmethod
def setUpClass(cls):
super(TestContractMandate, cls).setUpClass()
cls.payment_method = cls.env['account.payment.method'].create({
'name': 'Test SDD',
'code': 'test_code_sdd',
'payment_type': 'inbound',
'mandate_required': True,
})
cls.payment_mode = cls.env['account.payment.mode'].create({
'name': 'Test payment mode',
'bank_account_link': 'variable',
'payment_method_id': cls.payment_method.id,
})
cls.partner = cls.env['res.partner'].create({
'customer': True,
'name': 'Test Customer',
'customer_payment_mode_id': cls.payment_mode.id,
})
cls.partner_bank = cls.env['res.partner.bank'].create({
'acc_number': '1234',
'partner_id': cls.partner.id,
})
cls.mandate = cls.env['account.banking.mandate'].create({
'partner_id': cls.partner.id,
'partner_bank_id': cls.partner_bank.id,
'signature_date': '2017-01-01',
})
cls.uom = cls.env.ref('product.product_uom_hour')
cls.product = cls.env['product.product'].create({
'name': 'Custom Service',
'type': 'service',
'uom_id': cls.uom.id,
'uom_po_id': cls.uom.id,
'sale_ok': True,
'taxes_id': [(6, 0, [])],
})
cls.contract = cls.env['account.analytic.account'].create({
'name': 'Test contract',
'partner_id': cls.partner.id,
'recurring_invoices': True,
'recurring_interval': 1,
'recurring_invoice_line_ids': [(0, 0, {
'quantity': 2.0,
'price_unit': 200.0,
'name': 'Test contract line',
'product_id': cls.product.id,
'uom_id': cls.product.uom_id.id,
})],
'payment_mode_id': cls.payment_mode.id,
'mandate_id': cls.mandate.id,
})

def test_contract_mandate(self):
new_invoice = self.contract.recurring_create_invoice()
self.assertEqual(new_invoice.mandate_id, self.mandate)

def test_contract_not_mandate(self):
self.contract.mandate_id = False
self.mandate2 = self.mandate.copy({
'unique_mandate_reference': 'BM0000XX2',
})
self.mandate2.validate()
self.mandate.state = 'expired'
new_invoice = self.contract.recurring_create_invoice()
self.assertEqual(new_invoice.mandate_id, self.mandate2)

def test_contract_mandate_default(self):
self.payment_mode.mandate_required = False
self.contract.mandate_id = False
new_invoice = self.contract.recurring_create_invoice()
self.assertFalse(new_invoice.mandate_id)
18 changes: 18 additions & 0 deletions contract_mandate/views/contract_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<odoo>

<record id="account_analytic_account_payment_form" model="ir.ui.view">
<field name="model">account.analytic.account</field>
<field name="inherit_id" ref="contract_payment_mode.account_analytic_account_payment_form" />
<field name="arch" type="xml">
<field name="payment_mode_id" position="after">
<field name="mandate_id"
domain="[('partner_id', '=', commercial_partner_id), ('state', '=', 'valid')]"
attrs="{'invisible': ['|', ('mandate_required', '=', False), ('recurring_invoices', '=', False)]}"/>
<field name="commercial_partner_id" invisible="1"/>
<field name="mandate_required" invisible="1"/>
</field>
</field>
</record>

</odoo>

0 comments on commit e47f043

Please sign in to comment.