diff --git a/account_banking_sepa_direct_debit/README.rst b/account_banking_sepa_direct_debit/README.rst index 10eb9754d..04d40f4c3 100644 --- a/account_banking_sepa_direct_debit/README.rst +++ b/account_banking_sepa_direct_debit/README.rst @@ -71,6 +71,7 @@ Contributors * Raphaƫl Valyi * Sandy Carter * Antonio Espinosa +* Sergio Teruel Maintainer diff --git a/account_banking_sepa_direct_debit/models/account_banking_mandate.py b/account_banking_sepa_direct_debit/models/account_banking_mandate.py index 4219cee81..f3ac6d38d 100644 --- a/account_banking_sepa_direct_debit/models/account_banking_mandate.py +++ b/account_banking_sepa_direct_debit/models/account_banking_mandate.py @@ -37,7 +37,7 @@ class AccountBankingMandate(models.Model): ) type = fields.Selection([('recurrent', 'Recurrent'), ('oneoff', 'One-Off')], - string='Type of Mandate', required=True, + string='Type of Mandate', track_visibility='always') recurrent_sequence_type = fields.Selection( [('first', 'First'), @@ -63,69 +63,61 @@ class AccountBankingMandate(models.Model): "Direct Debit file.") scheme = fields.Selection([('CORE', 'Basic (CORE)'), ('B2B', 'Enterprise (B2B)')], - string='Scheme', required=True, default="CORE") + string='Scheme', default="CORE") unique_mandate_reference = fields.Char(size=35) # cf ISO 20022 - @api.one + @api.multi @api.constrains('type', 'recurrent_sequence_type') def _check_recurring_type(self): - if (self.type == 'recurrent' and - not self.recurrent_sequence_type): - raise exceptions.Warning( - _("The recurrent mandate '%s' must have a sequence type.") - % self.unique_mandate_reference) - - @api.one - @api.constrains('type', 'recurrent_sequence_type', 'sepa_migrated') - def _check_migrated_to_sepa(self): - if (self.type == 'recurrent' and not self.sepa_migrated and - self.recurrent_sequence_type != 'first'): - raise exceptions.Warning( - _("The recurrent mandate '%s' which is not marked as " - "'Migrated to SEPA' must have its recurrent sequence type " - "set to 'First'.") % self.unique_mandate_reference) - - @api.one - @api.constrains('type', 'original_mandate_identification', 'sepa_migrated') - def _check_original_mandate_identification(self): - if (self.type == 'recurrent' and not self.sepa_migrated and - not self.original_mandate_identification): - raise exceptions.Warning( - _("You must set the 'Original Mandate Identification' on the " - "recurrent mandate '%s' which is not marked as 'Migrated to " - "SEPA'.") % self.unique_mandate_reference) - - @api.model - def _get_mandate_format(self): - res = super(AccountBankingMandate, self)._get_mandate_format() - res.append(('sepa', _('Sepa Mandate'))) - return res - - - @api.model - def _default_mandate_format(self): - res = super(AccountBankingMandate, self).default_mandate_format() - return 'sepa' - - @api.one - @api.onchange('partner_bank_id') - def mandate_partner_bank_change(self): - super(AccountBankingMandate, self).mandate_partner_bank_change() - res = {} - if (self.state == 'valid' and - self.partner_bank_id and - self.type == 'recurrent' and - self.recurrent_sequence_type != 'first'): - self.recurrent_sequence_type = 'first' - res['warning'] = { - 'title': _('Mandate update'), - 'message': _("As you changed the bank account attached to " - "this mandate, the 'Sequence Type' has been set " - "back to 'First'."), - } - return res + for mandate in self: + if (mandate.type == 'recurrent' and + not mandate.recurrent_sequence_type): + raise exceptions.Warning( + _("The recurrent mandate '%s' must have a sequence type.") + % mandate.unique_mandate_reference) @api.multi + @api.constrains('type', 'recurrent_sequence_type', 'sepa_migrated') + def _check_migrated_to_sepa(self): + for mandate in self: + if (mandate.type == 'recurrent' and not mandate.sepa_migrated and + mandate.recurrent_sequence_type != 'first'): + raise exceptions.Warning( + _("The recurrent mandate '%s' which is not marked as " + "'Migrated to SEPA' must have its recurrent sequence type " + "set to 'First'.") % mandate.unique_mandate_reference) + + @api.multi + @api.constrains('type', 'original_mandate_identification', 'sepa_migrated') + def _check_original_mandate_identification(self): + for mandate in self: + if (mandate.type == 'recurrent' and not mandate.sepa_migrated and + not mandate.original_mandate_identification): + raise exceptions.Warning( + _("You must set the 'Original Mandate Identification' on the " + "recurrent mandate '%s' which is not marked as 'Migrated to " + "SEPA'.") % mandate.unique_mandate_reference) + + @api.multi + @api.onchange('partner_bank_id') + def mandate_partner_bank_change(self): + for mandate in self: + super(AccountBankingMandate, self).mandate_partner_bank_change() + res = {} + if (mandate.state == 'valid' and + mandate.partner_bank_id and + mandate.type == 'recurrent' and + mandate.recurrent_sequence_type != 'first'): + mandate.recurrent_sequence_type = 'first' + res['warning'] = { + 'title': _('Mandate update'), + 'message': _("As you changed the bank account attached to " + "this mandate, the 'Sequence Type' has been set " + "back to 'First'."), + } + return res + + @api.model def _sdd_mandate_set_state_to_expired(self): logger.info('Searching for SDD Mandates that must be set to Expired') expire_limit_date = datetime.today() + \ diff --git a/account_banking_sepa_direct_debit/models/payment_mode.py b/account_banking_sepa_direct_debit/models/payment_mode.py index 9753ac319..f3c1ac1b6 100644 --- a/account_banking_sepa_direct_debit/models/payment_mode.py +++ b/account_banking_sepa_direct_debit/models/payment_mode.py @@ -31,12 +31,13 @@ class PaymentMode(models.Model): res = 'sepa_direct_debit' return res - @api.one + @api.multi @api.constrains('sepa_creditor_identifier') def _check_sepa_creditor_identifier(self): - if self.sepa_creditor_identifier: - if not is_sepa_creditor_identifier_valid( - self.sepa_creditor_identifier): - raise exceptions.Warning( - _('Error'), - _("Invalid SEPA Creditor Identifier.")) + for payment_mode in self: + if payment_mode.sepa_creditor_identifier: + if not is_sepa_creditor_identifier_valid( + payment_mode.sepa_creditor_identifier): + raise exceptions.Warning( + _('Error'), + _("Invalid SEPA Creditor Identifier.")) diff --git a/account_banking_sepa_direct_debit/models/res_company.py b/account_banking_sepa_direct_debit/models/res_company.py index 8b76a9678..c57dc8b04 100644 --- a/account_banking_sepa_direct_debit/models/res_company.py +++ b/account_banking_sepa_direct_debit/models/res_company.py @@ -21,12 +21,13 @@ class ResCompany(models.Model): original_creditor_identifier = fields.Char( string='Original Creditor Identifier', size=70) - @api.one + @api.multi @api.constrains('sepa_creditor_identifier') def _check_sepa_creditor_identifier(self): - if self.sepa_creditor_identifier: - if not is_sepa_creditor_identifier_valid( - self.sepa_creditor_identifier): - raise exceptions.Warning( - _('Error'), - _("Invalid SEPA Creditor Identifier.")) + for company in self: + if company.sepa_creditor_identifier: + if not is_sepa_creditor_identifier_valid( + company.sepa_creditor_identifier): + raise exceptions.Warning( + _('Error'), + _("Invalid SEPA Creditor Identifier.")) diff --git a/account_banking_sepa_direct_debit/views/account_banking_mandate_view.xml b/account_banking_sepa_direct_debit/views/account_banking_mandate_view.xml index 0728c8616..667cedb54 100644 --- a/account_banking_sepa_direct_debit/views/account_banking_mandate_view.xml +++ b/account_banking_sepa_direct_debit/views/account_banking_mandate_view.xml @@ -17,10 +17,13 @@ - + - + attrs="{'invisible': ['|', ('type', '=', 'oneoff'), ('format', '!=', 'sepa')], + 'required': [('type', '=', 'recurrent')]}"/> + diff --git a/account_banking_sepa_direct_debit/views/report_sepa_direct_debit_mandate.xml b/account_banking_sepa_direct_debit/views/report_sepa_direct_debit_mandate.xml index 7d5b312c3..42705e28a 100644 --- a/account_banking_sepa_direct_debit/views/report_sepa_direct_debit_mandate.xml +++ b/account_banking_sepa_direct_debit/views/report_sepa_direct_debit_mandate.xml @@ -46,9 +46,9 @@
-

By signing this mandate form, you authorise (A) +

By signing this mandate form, you authorise (A) to send instructions to your bank to debit your account and (B) your bank to - debit your account in accordance with the instructions from . + debit your account in accordance with the instructions from .