mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
Add the ability to cancel a mandate. Add a field "SDD Mandate" on the customer invoice, to handle the scenario where one customer has multiple mandates with the company.
This commit is contained in:
committed by
Enric Tobella
parent
d8245177e2
commit
1c7c1069d2
@@ -35,6 +35,7 @@
|
|||||||
'account_payment_view.xml',
|
'account_payment_view.xml',
|
||||||
'company_view.xml',
|
'company_view.xml',
|
||||||
'mandate_expire_cron.xml',
|
'mandate_expire_cron.xml',
|
||||||
|
'account_invoice_view.xml',
|
||||||
'wizard/export_sdd_view.xml',
|
'wizard/export_sdd_view.xml',
|
||||||
'data/payment_type_sdd.xml',
|
'data/payment_type_sdd.xml',
|
||||||
'data/mandate_reference_sequence.xml',
|
'data/mandate_reference_sequence.xml',
|
||||||
|
|||||||
@@ -103,6 +103,8 @@ class sdd_mandate(orm.Model):
|
|||||||
lambda self, cr, uid, obj, ctx=None: obj['state'] == 'valid',
|
lambda self, cr, uid, obj, ctx=None: obj['state'] == 'valid',
|
||||||
'account_banking_sepa_direct_debit.mandate_expired':
|
'account_banking_sepa_direct_debit.mandate_expired':
|
||||||
lambda self, cr, uid, obj, ctx=None: obj['state'] == 'expired',
|
lambda self, cr, uid, obj, ctx=None: obj['state'] == 'expired',
|
||||||
|
'account_banking_sepa_direct_debit.mandate_cancel':
|
||||||
|
lambda self, cr, uid, obj, ctx=None: obj['state'] == 'cancel',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,9 +129,9 @@ class sdd_mandate(orm.Model):
|
|||||||
('draft', 'Draft'),
|
('draft', 'Draft'),
|
||||||
('valid', 'Valid'),
|
('valid', 'Valid'),
|
||||||
('expired', 'Expired'),
|
('expired', 'Expired'),
|
||||||
# Do we have to handle cancellation of mandate by customer ?
|
('cancel', 'Cancelled'),
|
||||||
], 'Mandate Status',
|
], 'Mandate Status',
|
||||||
help="For a recurrent mandate, this field indicate if the mandate is still valid or if it has expired (a recurrent mandate expires if it's not used during 36 months). For a one-off mandate, it expires after its first use."),
|
help="For a recurrent mandate, this field indicate if the mandate is still valid or if it has expired (a recurrent mandate expires if it's not used during 36 months). For a one-off mandate, it expires after its first use."), # TODO : update help
|
||||||
'payment_line_ids': fields.one2many(
|
'payment_line_ids': fields.one2many(
|
||||||
'payment.line', 'sdd_mandate_id', "Related Payment Lines"),
|
'payment.line', 'sdd_mandate_id', "Related Payment Lines"),
|
||||||
}
|
}
|
||||||
@@ -194,6 +196,16 @@ class sdd_mandate(orm.Model):
|
|||||||
cr, uid, to_validate_ids, {'state': 'valid'}, context=context)
|
cr, uid, to_validate_ids, {'state': 'valid'}, context=context)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def cancel(self, cr, uid, ids, context=None):
|
||||||
|
to_cancel_ids = []
|
||||||
|
for mandate in self.browse(cr, uid, ids, context=context):
|
||||||
|
assert mandate.state in ('draft', 'valid'),\
|
||||||
|
'Mandate should be in draft or valid state'
|
||||||
|
to_cancel_ids.append(mandate.id)
|
||||||
|
self.write(
|
||||||
|
cr, uid, to_cancel_ids, {'state': 'cancel'}, context=context)
|
||||||
|
return True
|
||||||
|
|
||||||
def _sdd_mandate_set_state_to_expired(self, cr, uid, context=None):
|
def _sdd_mandate_set_state_to_expired(self, cr, uid, context=None):
|
||||||
logger.info('Searching for SDD Mandates that must be set to Expired')
|
logger.info('Searching for SDD Mandates that must be set to Expired')
|
||||||
expire_limit_date = datetime.today() + \
|
expire_limit_date = datetime.today() + \
|
||||||
@@ -232,23 +244,47 @@ class payment_line(orm.Model):
|
|||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'sdd_mandate_id': fields.many2one(
|
'sdd_mandate_id': fields.many2one(
|
||||||
'sdd.mandate', 'SEPA Direct Debit Mandate'),
|
'sdd.mandate', 'SEPA Direct Debit Mandate',
|
||||||
|
domain=[('state', '=', 'valid')]),
|
||||||
}
|
}
|
||||||
|
|
||||||
def create(self, cr, uid, vals, context=None):
|
def create(self, cr, uid, vals, context=None):
|
||||||
'''Take the first valid mandate of the bank account by default'''
|
'''If the customer invoice has a mandate, take it
|
||||||
|
otherwise, take the first valid mandate of the bank account'''
|
||||||
if context is None:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
if not vals:
|
if not vals:
|
||||||
vals = {}
|
vals = {}
|
||||||
partner_bank_id = vals.get('bank_id')
|
partner_bank_id = vals.get('bank_id')
|
||||||
|
move_line_id = vals.get('move_line_id')
|
||||||
if (context.get('default_payment_order_type') == 'debit'
|
if (context.get('default_payment_order_type') == 'debit'
|
||||||
and partner_bank_id
|
|
||||||
and 'sdd_mandate_id' not in vals):
|
and 'sdd_mandate_id' not in vals):
|
||||||
mandate_ids = self.pool['sdd.mandate'].search(cr, uid, [
|
if move_line_id:
|
||||||
('partner_bank_id', '=', partner_bank_id),
|
line = self.pool['account.move.line'].browse(
|
||||||
('state', '=', 'valid'),
|
cr, uid, move_line_id, context=context)
|
||||||
], context=context)
|
if (line.invoice and line.invoice.type == 'out_invoice'
|
||||||
if mandate_ids:
|
and line.invoice.sdd_mandate_id):
|
||||||
vals['sdd_mandate_id'] = mandate_ids[0]
|
vals.update({
|
||||||
|
'sdd_mandate_id': line.invoice.sdd_mandate_id.id,
|
||||||
|
'bank_id':
|
||||||
|
line.invoice.sdd_mandate_id.partner_bank_id.id,
|
||||||
|
})
|
||||||
|
if partner_bank_id and 'sdd_mandate_id' not in vals:
|
||||||
|
mandate_ids = self.pool['sdd.mandate'].search(cr, uid, [
|
||||||
|
('partner_bank_id', '=', partner_bank_id),
|
||||||
|
('state', '=', 'valid'),
|
||||||
|
], context=context)
|
||||||
|
if mandate_ids:
|
||||||
|
vals['sdd_mandate_id'] = mandate_ids[0]
|
||||||
return super(payment_line, self).create(cr, uid, vals, context=context)
|
return super(payment_line, self).create(cr, uid, vals, context=context)
|
||||||
|
|
||||||
|
|
||||||
|
class account_invoice(orm.Model):
|
||||||
|
_inherit = 'account.invoice'
|
||||||
|
|
||||||
|
_columns = {
|
||||||
|
'sdd_mandate_id': fields.many2one(
|
||||||
|
'sdd.mandate', 'SEPA Direct Debit Mandate',
|
||||||
|
domain=[('state', '=', 'valid')], readonly=True,
|
||||||
|
states={'draft': [('readonly', False)]})
|
||||||
|
}
|
||||||
|
|||||||
@@ -85,6 +85,7 @@
|
|||||||
<form string="SEPA Direct Debit Mandate" version="7.0">
|
<form string="SEPA Direct Debit Mandate" version="7.0">
|
||||||
<header>
|
<header>
|
||||||
<button name="validate" type="object" string="Validate" states="draft"/>
|
<button name="validate" type="object" string="Validate" states="draft"/>
|
||||||
|
<button name="cancel" type="object" string="Cancel" states="draft,valid"/>
|
||||||
<field name="state" widget="statusbar"/>
|
<field name="state" widget="statusbar"/>
|
||||||
</header>
|
</header>
|
||||||
<sheet>
|
<sheet>
|
||||||
@@ -166,7 +167,7 @@
|
|||||||
sequence="20"
|
sequence="20"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- notification in the chatter -->
|
<!-- notifications in the chatter -->
|
||||||
<record id="mandate_valid" model="mail.message.subtype">
|
<record id="mandate_valid" model="mail.message.subtype">
|
||||||
<field name="name">Mandate Validated</field>
|
<field name="name">Mandate Validated</field>
|
||||||
<field name="res_model">sdd.mandate</field>
|
<field name="res_model">sdd.mandate</field>
|
||||||
@@ -181,6 +182,12 @@
|
|||||||
<field name="description">SEPA Direct Debit Mandate has Expired</field>
|
<field name="description">SEPA Direct Debit Mandate has Expired</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<record id="mandate_cancel" model="mail.message.subtype">
|
||||||
|
<field name="name">Mandate Cancelled</field>
|
||||||
|
<field name="res_model">sdd.mandate</field>
|
||||||
|
<field name="default" eval="False"/>
|
||||||
|
<field name="description">SEPA Direct Debit Mandate Cancelled</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
|
||||||
<record id="sdd_mandate_partner_bank_form" model="ir.ui.view">
|
<record id="sdd_mandate_partner_bank_form" model="ir.ui.view">
|
||||||
|
|||||||
22
account_banking_sepa_direct_debit/account_invoice_view.xml
Normal file
22
account_banking_sepa_direct_debit/account_invoice_view.xml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2013 Akretion (http://www.akretion.com)
|
||||||
|
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
The licence is in the file __openerp__.py
|
||||||
|
-->
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<record id="invoice_form" model="ir.ui.view">
|
||||||
|
<field name="name">add.sdd.mandate.on.customer.invoice.form</field>
|
||||||
|
<field name="model">account.invoice</field>
|
||||||
|
<field name="inherit_id" ref="account.invoice_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="partner_bank_id" position="after">
|
||||||
|
<field name="sdd_mandate_id" domain="[('partner_id', '=', partner_id), ('state', '=', 'valid')]" attrs="{'invisible': [('type', '=', 'out_refund')]}"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
||||||
Reference in New Issue
Block a user