← Back to team overview

banking-addons-team team mailing list archive

[Merge] lp:~akretion-team/banking-addons/70-sdd-mandate-back2draft into lp:banking-addons

 

Alexis de Lattre has proposed merging lp:~akretion-team/banking-addons/70-sdd-mandate-back2draft into lp:banking-addons.

Requested reviews:
  Banking Addons Core Editors (banking-addons-team)

For more details, see:
https://code.launchpad.net/~akretion-team/banking-addons/70-sdd-mandate-back2draft/+merge/222970

This small merge proposal features :

1) Add "Back to draft" button on SDD mandates (usefull if a mandate was cancelled by mistake, and only in this case)

2) Fix double increment of the sequence when you create an SDD mandate.
-- 
https://code.launchpad.net/~akretion-team/banking-addons/70-sdd-mandate-back2draft/+merge/222970
Your team Banking Addons Core Editors is requested to review the proposed merge of lp:~akretion-team/banking-addons/70-sdd-mandate-back2draft into lp:banking-addons.
=== modified file 'account_banking_sepa_direct_debit/account_banking_sdd.py'
--- account_banking_sepa_direct_debit/account_banking_sdd.py	2013-12-24 00:01:04 +0000
+++ account_banking_sepa_direct_debit/account_banking_sdd.py	2014-06-12 16:09:08 +0000
@@ -191,8 +191,7 @@
         'company_id': lambda self, cr, uid, context:
         self.pool['res.company']._company_default_get(
             cr, uid, 'sdd.mandate', context=context),
-        'unique_mandate_reference': lambda self, cr, uid, ctx:
-        self.pool['ir.sequence'].get(cr, uid, 'sdd.mandate.reference'),
+        'unique_mandate_reference': '/',
         'state': 'draft',
         'sepa_migrated': True,
     }
@@ -203,6 +202,13 @@
         'A Mandate with the same reference already exists for this company !'
         )]
 
+    def create(self, cr, uid, vals, context=None):
+        if vals.get('unique_mandate_reference', '/') == '/':
+            vals['unique_mandate_reference'] = \
+                self.pool['ir.sequence'].next_by_code(
+                    cr, uid, 'sdd.mandate.reference', context=context)
+        return super(sdd_mandate, self).create(cr, uid, vals, context=context)
+
     def _check_sdd_mandate(self, cr, uid, ids):
         for mandate in self.browse(cr, uid, ids):
             if (mandate.signature_date and
@@ -314,6 +320,16 @@
             cr, uid, to_cancel_ids, {'state': 'cancel'}, context=context)
         return True
 
+    def back2draft(self, cr, uid, ids, context=None):
+        to_draft_ids = []
+        for mandate in self.browse(cr, uid, ids, context=context):
+            assert mandate.state == 'cancel',\
+                'Mandate should be in cancel state'
+            to_draft_ids.append(mandate.id)
+        self.write(
+            cr, uid, to_draft_ids, {'state': 'draft'}, context=context)
+        return True
+
     def _sdd_mandate_set_state_to_expired(self, cr, uid, context=None):
         logger.info('Searching for SDD Mandates that must be set to Expired')
         expire_limit_date = datetime.today() + \

=== modified file 'account_banking_sepa_direct_debit/sdd_mandate_view.xml'
--- account_banking_sepa_direct_debit/sdd_mandate_view.xml	2014-02-16 13:56:24 +0000
+++ account_banking_sepa_direct_debit/sdd_mandate_view.xml	2014-06-12 16:09:08 +0000
@@ -13,8 +13,11 @@
     <field name="arch" type="xml">
         <form string="SEPA Direct Debit Mandate" version="7.0">
             <header>
-                <button name="validate" type="object" string="Validate" states="draft"/>
+                <button name="validate" type="object" string="Validate" states="draft" class="oe_highlight"/>
                 <button name="cancel" type="object" string="Cancel" states="draft,valid"/>
+                <button name="back2draft" type="object" string="Back to Draft"
+                    states="cancel" groups="account.group_account_manager"
+                    confirm="You should set a mandate back to draft only if you cancelled it by mistake. Do you want to continue ?"/>
                 <field name="state" widget="statusbar"/>
             </header>
             <sheet>


Follow ups