Skip to content
Browse files

invoice_ids -> invoice_id

  • Loading branch information...
william-andre committed Mar 13, 2019
1 parent 0bf165c commit c92892991dc28aed796386ddfe14ded4be0eb741
Showing with 17 additions and 30 deletions.
  1. +16 −29 addons/account/models/
  2. +1 −1 addons/account/views/account_payment_view.xml
@@ -47,10 +47,8 @@ class account_payment(models.Model):
# For money transfer, money goes from journal_id to a transfer account, then from the transfer account to destination_journal_id
destination_journal_id = fields.Many2one('account.journal', string='Transfer To', domain=[('type', 'in', ('bank', 'cash'))], readonly=True, states={'draft': [('readonly', False)]})

invoice_ids = fields.Many2many('account.invoice', 'account_invoice_payment_rel', 'payment_id', 'invoice_id', string="Invoices", copy=False, readonly=True,
help="""Technical field containing the invoices for which the payment has been generated.
This does not especially correspond to the invoices reconciled with the payment,
as it can have been generated first, and reconciled later""")
invoice_id = fields.Many2one('account.invoice', string="Invoices", copy=False, readonly=True, store=False,
help="""Technical field containing the invoice for which the payment has been generated.""")
reconciled_invoice_ids = fields.Many2many('account.invoice', string='Reconciled Invoices', compute='_compute_reconciled_invoice_ids', help="Invoices whose journal items have been reconciled with this payment's.")
has_invoices = fields.Boolean(compute="_compute_reconciled_invoice_ids", help="Technical field used for usability purposes")

@@ -139,9 +137,9 @@ def _compute_hide_payment_method(self):
or payment.journal_id.outbound_payment_method_ids
payment.hide_payment_method = len(journal_payment_methods) == 1 and journal_payment_methods[0].code == 'manual'

@api.depends('invoice_ids', 'amount', 'payment_date', 'currency_id', 'payment_type')
@api.depends('invoice_id', 'amount', 'payment_date', 'currency_id', 'payment_type')
def _compute_payment_difference(self):
for pay in self.filtered(lambda p: p.invoice_ids):
for pay in self.filtered(lambda p: p.invoice_id):
payment_amount = -pay.amount if pay.payment_type == 'outbound' else pay.amount
pay.payment_difference = pay._compute_payment_amount() - payment_amount

@@ -174,8 +172,8 @@ def _onchange_journal(self):

def _onchange_partner_id(self):
if self.invoice_ids and self.invoice_ids[0].partner_bank_id:
self.partner_bank_account_id = self.invoice_ids[0].partner_bank_id
if self.invoice_id and self.invoice_id.partner_bank_id:
self.partner_bank_account_id = self.invoice_id.partner_bank_id
elif self.partner_id != self.partner_bank_account_id.partner_id:
# This condition ensures we use the default value provided into
# context for partner_bank_account_id properly when provided with a
@@ -261,7 +259,7 @@ def _compute_payment_amount(self, invoices=None, currency=None):

# Get the payment invoices
if not invoices:
invoices = self.invoice_ids
invoices = self.invoice_id

# Get the payment currency
if not currency:
@@ -316,10 +314,10 @@ def open_payment_matching_screen(self):
@api.depends('invoice_ids', 'payment_type', 'partner_type', 'partner_id')
@api.depends('invoice_id', 'payment_type', 'partner_type', 'partner_id')
def _compute_destination_account_id(self):
if self.invoice_ids:
self.destination_account_id = self.invoice_ids[0]
if self.invoice_id:
self.destination_account_id =
elif self.payment_type == 'transfer':
if not
raise UserError(_('There is no Transfer Account defined in the accounting settings. Please define one to be able to confirm this transfer.'))
@@ -404,7 +402,7 @@ def unreconcile(self):
def cancel(self):
for rec in self:
for move in rec.move_line_ids.mapped('move_id'):
if rec.invoice_ids:
if rec.reconciled_invoice_ids:
@@ -423,15 +421,15 @@ def post(self):
""" Create the journal items for the payment and update the payment's state to 'posted'.
A journal entry is created containing an item in the source liquidity account (selected journal's default_debit or default_credit)
and another in the destination reconcilable account (see _compute_destination_account_id).
If invoice_ids is not empty, there will be one reconcilable move line per invoice to reconcile with.
If invoice_id is not empty, there will be one reconcilable move line per invoice to reconcile with.
If the payment is a transfer, a second journal entry is created in the destination journal to receive money from the transfer account.
for rec in self:

if rec.state != 'draft':
raise UserError(_("Only a draft payment can be posted."))

if any(inv.state != 'open' for inv in rec.invoice_ids):
if rec.invoice_id and rec.invoice_id.state != 'open':
raise ValidationError(_("The payment cannot be processed because the invoice is not open!"))

# keep the name in case of a payment reset to draft
@@ -472,17 +470,6 @@ def post(self):
def action_draft(self):
return self.write({'state': 'draft'})

def action_validate_invoice_payment(self):
""" Posts a payment used to pay an invoice. This function only posts the
payment by default but can be overridden to apply specific post or pre-processing.
It is called by the "validate" button of the popup window
triggered on invoice form by the "Register Payment" button.
if any(len(record.invoice_ids) != 1 for record in self):
# For multiple invoices, there is create_payments method
raise UserError(_("This method should only be called to process a single invoice's payment."))

def _create_payment_entry(self, amount):
""" Create a journal entry corresponding to a payment, if the payment references invoice(s) they are reconciled.
Return the journal entry.
@@ -494,7 +481,7 @@ def _create_payment_entry(self, amount):

#Write line corresponding to invoice payment
counterpart_aml_dict = self._get_shared_move_line_vals(debit, credit, amount_currency,, False)
counterpart_aml_dict.update({'currency_id': currency_id})
counterpart_aml = aml_obj.create(counterpart_aml_dict)

@@ -528,8 +515,8 @@ def _create_payment_entry(self, amount):

#reconcile the invoice receivable/payable line(s) with the payment
if self.invoice_ids:
if self.invoice_id:

return move

@@ -143,7 +143,7 @@
<h1><field name="name"/></h1>
<field name="invoice_ids" invisible="1"/>
<field name="invoice_id" invisible="1"/>
<group name="partner_group">
<field name="payment_type" widget="radio"/>
<field name="partner_type" widget="selection" attrs="{'required': [('state', '=', 'draft'), ('payment_type', 'in', ('inbound', 'outbound'))], 'invisible': [('payment_type', 'not in', ('inbound', 'outbound'))]}"/>

0 comments on commit c928929

Please sign in to comment.
You can’t perform that action at this time.