mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
Finalise merge of account_banking_payment_transfer into account_payment_order
Add support for transfer moves Display transfer moves in a dedicated tab in payment order view Code cleanup
This commit is contained in:
committed by
Enric Tobella
parent
e5fc812f6a
commit
75b3c0d0e9
@@ -17,6 +17,6 @@ class AccountMoveLine(models.Model):
|
||||
vals = super(AccountMoveLine, self)._prepare_payment_line_vals(
|
||||
payment_order)
|
||||
if payment_order.payment_type == 'inbound' and self.mandate_id:
|
||||
vals['mandate_id'] = self.mandate_id.id or False
|
||||
vals['partner_bank_id'] = self.mandate_id.partner_bank_id.id or False
|
||||
vals['mandate_id'] = self.mandate_id.id
|
||||
vals['partner_bank_id'] = self.mandate_id.partner_bank_id.id
|
||||
return vals
|
||||
|
||||
@@ -15,49 +15,23 @@ class AccountPaymentLine(models.Model):
|
||||
comodel_name='account.banking.mandate', string='Direct Debit Mandate',
|
||||
domain=[('state', '=', 'valid')])
|
||||
|
||||
# TODO : remove this
|
||||
@api.model
|
||||
def create(self, vals=None):
|
||||
"""If the customer invoice has a mandate, take it
|
||||
otherwise, take the first valid mandate of the bank account
|
||||
"""
|
||||
if vals is None:
|
||||
vals = {}
|
||||
partner_bank_id = vals.get('partner_bank_id')
|
||||
move_line_id = vals.get('move_line_id')
|
||||
if (self.env.context.get('search_payment_order_type') == 'debit' and
|
||||
'mandate_id' not in vals):
|
||||
if move_line_id:
|
||||
line = self.env['account.move.line'].browse(move_line_id)
|
||||
if (line.invoice and line.invoice.type == 'out_invoice' and
|
||||
line.invoice.mandate_id):
|
||||
vals.update({
|
||||
'mandate_id': line.invoice.mandate_id.id,
|
||||
'partner_bank_id': line.invoice.mandate_id.partner_bank_id.id,
|
||||
})
|
||||
if partner_bank_id and 'mandate_id' not in vals:
|
||||
mandates = self.env['account.banking.mandate'].search(
|
||||
[('partner_bank_id', '=', partner_bank_id),
|
||||
('state', '=', 'valid')])
|
||||
if mandates:
|
||||
vals['mandate_id'] = mandates[0].id
|
||||
return super(AccountPaymentLine, self).create(vals)
|
||||
|
||||
@api.one
|
||||
@api.multi
|
||||
@api.constrains('mandate_id', 'partner_bank_id')
|
||||
def _check_mandate_bank_link(self):
|
||||
if (self.mandate_id and self.partner_bank_id and
|
||||
self.mandate_id.partner_bank_id.id !=
|
||||
self.partner_bank_id.id):
|
||||
raise ValidationError(
|
||||
_("The payment line with reference '%s' has the bank account "
|
||||
"'%s' which is not attached to the mandate '%s' (this "
|
||||
"mandate is attached to the bank account '%s').") %
|
||||
(self.name,
|
||||
self.partner_bank_id.name_get()[0][1],
|
||||
self.mandate_id.unique_mandate_reference,
|
||||
self.mandate_id.partner_bank_id.name_get()[0][1]))
|
||||
for pline in self:
|
||||
if (pline.mandate_id and pline.partner_bank_id and
|
||||
pline.mandate_id.partner_bank_id !=
|
||||
pline.partner_bank_id):
|
||||
raise ValidationError(_(
|
||||
"The payment line number %s has the bank account "
|
||||
"'%s' which is not attached to the mandate '%s' (this "
|
||||
"mandate is attached to the bank account '%s').") %
|
||||
(pline.name,
|
||||
pline.partner_bank_id.acc_number,
|
||||
pline.mandate_id.unique_mandate_reference,
|
||||
pline.mandate_id.partner_bank_id.acc_number))
|
||||
|
||||
# @api.multi
|
||||
# def check_payment_line(self):
|
||||
# TODO : i would like to block here is mandate is missing... but how do you know it's required ? => create option on payment order ?
|
||||
# TODO : i would like to block here is mandate is missing...
|
||||
# but how do you know it's required ? => create option on payment order ?
|
||||
|
||||
Reference in New Issue
Block a user