From 8b61d56f72ce5c1ac13434f20ad5ba20ea1dab9d Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Sat, 7 May 2016 23:55:46 +0200 Subject: [PATCH] Add module account_banking_mandate_sale Add option 'mandate_required' on payment orders Autoselect first valid mandate on customer invoice that have a payment mode 'mandate_required' = True Add option on select move lines to pay wizard to allow selection of litigation moves (unchecked by default), in order to integrate the feature of the module account_payment_blocking --- account_banking_mandate_sale/README.rst | 69 +++++++++++++++++++ account_banking_mandate_sale/__init__.py | 4 ++ account_banking_mandate_sale/__openerp__.py | 22 ++++++ .../models/__init__.py | 3 + .../models/sale_order.py | 36 ++++++++++ .../views/sale_order.xml | 27 ++++++++ .../wizard/__init__.py | 3 + .../wizard/sale_make_invoice_advance.py | 18 +++++ 8 files changed, 182 insertions(+) create mode 100644 account_banking_mandate_sale/README.rst create mode 100644 account_banking_mandate_sale/__init__.py create mode 100644 account_banking_mandate_sale/__openerp__.py create mode 100644 account_banking_mandate_sale/models/__init__.py create mode 100644 account_banking_mandate_sale/models/sale_order.py create mode 100644 account_banking_mandate_sale/views/sale_order.xml create mode 100644 account_banking_mandate_sale/wizard/__init__.py create mode 100644 account_banking_mandate_sale/wizard/sale_make_invoice_advance.py diff --git a/account_banking_mandate_sale/README.rst b/account_banking_mandate_sale/README.rst new file mode 100644 index 000000000..eb73e9cc8 --- /dev/null +++ b/account_banking_mandate_sale/README.rst @@ -0,0 +1,69 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +Account Banking Mandate Sale +============================ + +This modules adds the field *Direct Debit Mandate* on sale orders. + +Configuration +============= + +There is nothing to configure. + +Usage +===== + +When you select a payment mode that requires mandate on a sale order, Odoo will +select by default the first valid mandate of this customer. + +The mandate will be copied from the sale order to the invoice. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/173/9.0 + +Known issues / Roadmap +====================== + + * No known issues. + +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 +`_. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Alexis de Lattre + +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/account_banking_mandate_sale/__init__.py b/account_banking_mandate_sale/__init__.py new file mode 100644 index 000000000..35e7c9600 --- /dev/null +++ b/account_banking_mandate_sale/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from . import models +from . import wizard diff --git a/account_banking_mandate_sale/__openerp__.py b/account_banking_mandate_sale/__openerp__.py new file mode 100644 index 000000000..810cd5aa0 --- /dev/null +++ b/account_banking_mandate_sale/__openerp__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Account Banking Mandate Sale', + 'version': '9.0.1.0.0', + 'category': 'Banking addons', + 'license': 'AGPL-3', + 'summary': "Adds mandates on sale orders", + 'author': "Akretion, " + "Odoo Community Association (OCA)", + 'website': 'https://github.com/OCA/bank-payment', + 'depends': [ + 'account_payment_sale', + 'account_banking_mandate', + ], + 'data': [ + 'views/sale_order.xml', + ], + 'installable': True, +} diff --git a/account_banking_mandate_sale/models/__init__.py b/account_banking_mandate_sale/models/__init__.py new file mode 100644 index 000000000..6064afee1 --- /dev/null +++ b/account_banking_mandate_sale/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import sale_order diff --git a/account_banking_mandate_sale/models/sale_order.py b/account_banking_mandate_sale/models/sale_order.py new file mode 100644 index 000000000..beba347e8 --- /dev/null +++ b/account_banking_mandate_sale/models/sale_order.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +# © 2014-2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import models, fields, api + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + # This field commercial_partner_id should be moved + # in an OCA base module named for example sale_commercial_partner + commercial_partner_id = fields.Many2one( + related='partner_id.commercial_partner_id', string='Commercial Entity', + store=True, readonly=True) + mandate_id = fields.Many2one( + 'account.banking.mandate', string='Direct Debit Mandate', + ondelete='restrict', readonly=True, + states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}) + + @api.multi + def _prepare_invoice(self): + """Copy mandate from sale order to invoice""" + vals = super(SaleOrder, self)._prepare_invoice() + vals['mandate_id'] = self.mandate_id.id + return vals + + @api.onchange('payment_mode_id') + def payment_mode_change(self): + """Select by default the first valid mandate of the partner""" + if self.payment_mode_id.mandate_required and self.partner_id: + mandates = self.env['account.banking.mandate'].search([ + ('state', '=', 'valid'), + ('partner_id', '=', self.commercial_partner_id.id), + ]) + self.mandate_id = mandates[0] diff --git a/account_banking_mandate_sale/views/sale_order.xml b/account_banking_mandate_sale/views/sale_order.xml new file mode 100644 index 000000000..d14faf64f --- /dev/null +++ b/account_banking_mandate_sale/views/sale_order.xml @@ -0,0 +1,27 @@ + + + + + + + + + account_banking_mandate_sale.sale_order.form + sale.order + + + + + + + + + + + + diff --git a/account_banking_mandate_sale/wizard/__init__.py b/account_banking_mandate_sale/wizard/__init__.py new file mode 100644 index 000000000..1eb17ffa1 --- /dev/null +++ b/account_banking_mandate_sale/wizard/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import sale_make_invoice_advance diff --git a/account_banking_mandate_sale/wizard/sale_make_invoice_advance.py b/account_banking_mandate_sale/wizard/sale_make_invoice_advance.py new file mode 100644 index 000000000..0e9d34aa4 --- /dev/null +++ b/account_banking_mandate_sale/wizard/sale_make_invoice_advance.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# © 2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp import models, api + + +class SaleAdvancePaymentInv(models.TransientModel): + _inherit = 'sale.advance.payment.inv' + + @api.multi + def _create_invoice(self, order, so_line, amount): + """Copy mandate from sale order to invoice""" + inv = super(SaleAdvancePaymentInv, self)._create_invoice( + order, so_line, amount) + if order.mandate_id: + inv.mandate_id = order.mandate_id.id + return inv