[IMP][8.0] account_banking_mandate: Use api.multi instead

This commit is contained in:
sergio-incaser
2016-04-05 23:23:48 +02:00
committed by Sergio Incaser
parent aa93ed24c5
commit 5ea5adf33a

View File

@@ -71,33 +71,38 @@ class AccountBankingMandate(models.Model):
'unique(unique_mandate_reference, company_id)',
'A Mandate with the same reference already exists for this company !')]
@api.one
@api.multi
@api.constrains('signature_date', 'last_debit_date')
def _check_dates(self):
if (self.signature_date and
self.signature_date > fields.Date.context_today(self)):
raise exceptions.Warning(
_("The date of signature of mandate '%s' is in the future !")
% self.unique_mandate_reference)
if (self.signature_date and self.last_debit_date and
self.signature_date > self.last_debit_date):
raise exceptions.Warning(
_("The mandate '%s' can't have a date of last debit before "
"the date of signature.") % self.unique_mandate_reference)
for mandate in self:
if (mandate.signature_date and
mandate.signature_date > fields.Date.context_today(
mandate)):
raise exceptions.Warning(
_("The date of signature of mandate '%s' "
"is in the future !")
% mandate.unique_mandate_reference)
if (mandate.signature_date and mandate.last_debit_date and
mandate.signature_date > mandate.last_debit_date):
raise exceptions.Warning(
_("The mandate '%s' can't have a date of last debit "
"before the date of signature."
) % mandate.unique_mandate_reference)
@api.one
@api.multi
@api.constrains('state', 'partner_bank_id')
def _check_valid_state(self):
if self.state == 'valid':
if not self.signature_date:
raise exceptions.Warning(
_("Cannot validate the mandate '%s' without a date of "
"signature.") % self.unique_mandate_reference)
if not self.partner_bank_id:
raise exceptions.Warning(
_("Cannot validate the mandate '%s' because it is not "
"attached to a bank account.") %
self.unique_mandate_reference)
for mandate in self:
if mandate.state == 'valid':
if not mandate.signature_date:
raise exceptions.Warning(
_("Cannot validate the mandate '%s' without a date of "
"signature.") % mandate.unique_mandate_reference)
if not mandate.partner_bank_id:
raise exceptions.Warning(
_("Cannot validate the mandate '%s' because it is not "
"attached to a bank account.") %
mandate.unique_mandate_reference)
@api.model
def create(self, vals=None):
@@ -106,10 +111,11 @@ class AccountBankingMandate(models.Model):
self.env['ir.sequence'].next_by_code('account.banking.mandate')
return super(AccountBankingMandate, self).create(vals)
@api.one
@api.multi
@api.onchange('partner_bank_id')
def mandate_partner_bank_change(self):
self.partner_id = self.partner_bank_id.partner_id
for mandate in self:
mandate.partner_id = mandate.partner_bank_id.partner_id
@api.multi
def validate(self):