diff --git a/addons/account_voucher/models/account_voucher.py b/addons/account_voucher/models/account_voucher.py index 467ed1c4533..c288aa53def 100644 --- a/addons/account_voucher/models/account_voucher.py +++ b/addons/account_voucher/models/account_voucher.py @@ -183,6 +183,7 @@ class AccountVoucher(models.Model): if company_currency != current_currency else 0.0), 'date': self.account_date, 'date_maturity': self.date_due + 'payment_id': self._context.get('payment_id'), } return move_line @@ -221,6 +222,24 @@ class AccountVoucher(models.Model): for voucher in self: return voucher.currency_id.compute(amount, voucher.company_id.currency_id) + @api.multi + def voucher_pay_now_payment_create(self): + payment_methods = self.journal_id.outbound_payment_method_ids + return { + 'payment_type': 'outbound', + 'payment_method_id': payment_methods and payment_methods[0].id or False, + 'partner_type': 'supplier', + 'partner_id': self.partner_id.id, + 'amount': self.amount, + 'currency_id': self.currency_id.id, + 'payment_date': self.date, + 'journal_id': self.journal_id.id, + 'company_id': self.company_id.id, + 'communication': self.name, + 'name': self.name, + 'state': 'reconciled', + } + @api.multi def voucher_move_line_create(self, line_total, move_id, company_currency, current_currency): ''' @@ -258,8 +277,8 @@ class AccountVoucher(models.Model): 'tax_ids': [(4,t.id) for t in line.tax_ids], 'amount_currency': line.price_subtotal if current_currency != company_currency else 0.0, 'currency_id': company_currency != current_currency and current_currency or False, + 'payment_id': self._context.get('payment_id'), } - self.env['account.move.line'].with_context(apply_taxes=True).create(move_line) return line_total @@ -279,6 +298,9 @@ class AccountVoucher(models.Model): ctx = local_context.copy() ctx['date'] = voucher.account_date ctx['check_move_validity'] = False + # Create a payment to allow the reconciliation when pay_now = 'pay_now'. + if self.pay_now == 'pay_now' and self.amount > 0: + ctx['payment_id'] = self.env['account.payment'].create(self.voucher_pay_now_payment_create()).id # Create the account move record. move = self.env['account.move'].create(voucher.account_move_get()) # Get the name of the account_move just created