account_banking_sepa_direct_debit: Use api.multi instead

This commit is contained in:
sergio-incaser
2016-04-05 23:11:50 +02:00
committed by Enric Tobella
parent b06d52b610
commit 04cd389976
6 changed files with 75 additions and 77 deletions

View File

@@ -71,6 +71,7 @@ Contributors
* Raphaël Valyi
* Sandy Carter
* Antonio Espinosa <antonioea@antiun.com>
* Sergio Teruel <sergio.teruel@tecnativa.com>
Maintainer

View File

@@ -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() + \

View File

@@ -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."))

View File

@@ -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."))

View File

@@ -17,10 +17,13 @@
<field name="inherit_id" ref="account_banking_mandate.view_mandate_form"/>
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="type" attrs="{'invisible': [('format', '!=', 'sepa')]}"/>
<field name="type" attrs="{'invisible': [('format', '!=', 'sepa')],
'required': [('format', '=', 'sepa')]}"/>
<field name="recurrent_sequence_type"
attrs="{'invisible': ['|', ('type', '=', 'oneoff'), ('format', '!=', 'sepa')], 'required': [('type', '=', 'recurrent')]}"/>
<field name="scheme" attrs="{'invisible': [('format', '!=', 'sepa')]}"/>
attrs="{'invisible': ['|', ('type', '=', 'oneoff'), ('format', '!=', 'sepa')],
'required': [('type', '=', 'recurrent')]}"/>
<field name="scheme" attrs="{'invisible': [('format', '!=', 'sepa')],
'required': [('format', '=', 'sepa')]}"/>
</field>
<field name="last_debit_date" position="after">
<field name="sepa_migrated" groups="account_banking_sepa_direct_debit.group_original_mandate_required"/>

View File

@@ -46,9 +46,9 @@
</div>
<div class="row mt0" style="font-size:12px;">
<div class="col-xs-12">
<p>By signing this mandate form, you authorise (A) <strong><span t-field="o.company_id.name"/></strong>
<p>By signing this mandate form, you authorise (A) <strong t-if="o.scheme == 'B2B'"><span t-field="o.company_id.name"/></strong>
to send instructions to your bank to debit your account and (B) your bank to
debit your account in accordance with the instructions from <strong><span t-field="o.company_id.name"/></strong>.
debit your account in accordance with the instructions from <strong t-if="o.scheme == 'B2B'"><span t-field="o.company_id.name"/></strong>.
</p>
</div>
</div>