From e5769e665e42d3289c3d6d79f3a1cc85c6097d53 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 16 Jun 2016 15:19:01 +0200 Subject: [PATCH] FIX manual payment method --- .../models/account_payment_order.py | 4 +- .../models/account_payment_order.py | 47 ++++++++++--------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/account_banking_sepa_direct_debit/models/account_payment_order.py b/account_banking_sepa_direct_debit/models/account_payment_order.py index 16bd8557b..e68abe27e 100644 --- a/account_banking_sepa_direct_debit/models/account_payment_order.py +++ b/account_banking_sepa_direct_debit/models/account_payment_order.py @@ -35,9 +35,7 @@ class AccountPaymentOrder(models.Model): def generate_payment_file(self): """Creates the SEPA Direct Debit file. That's the important code !""" self.ensure_one() - if ( - self.payment_method_id.code != - 'sepa_direct_debit'): + if self.payment_method_id.code != 'sepa_direct_debit': return super(AccountPaymentOrder, self).generate_payment_file() pain_flavor = self.payment_method_id.pain_version # We use pain_flavor.startswith('pain.008.001.xx') diff --git a/account_payment_order/models/account_payment_order.py b/account_payment_order/models/account_payment_order.py index e1e0163a2..baf21abd2 100644 --- a/account_payment_order/models/account_payment_order.py +++ b/account_payment_order/models/account_payment_order.py @@ -274,37 +274,42 @@ class AccountPaymentOrder(models.Model): def generate_payment_file(self): """Returns (payment file as string, filename)""" self.ensure_one() - raise UserError(_( - "No handler for this payment method. Maybe you haven't " - "installed the related Odoo module.")) + if self.payment_method_id.code == 'manual': + return (False, False) + else: + raise UserError(_( + "No handler for this payment method. Maybe you haven't " + "installed the related Odoo module.")) @api.multi def open2generated(self): self.ensure_one() payment_file_str, filename = self.generate_payment_file() - attachment = self.env['ir.attachment'].create({ - 'res_model': 'account.payment.order', - 'res_id': self.id, - 'name': filename, - 'datas': payment_file_str.encode('base64'), - 'datas_fname': filename, - }) + action = {} + if payment_file_str and filename: + attachment = self.env['ir.attachment'].create({ + 'res_model': 'account.payment.order', + 'res_id': self.id, + 'name': filename, + 'datas': payment_file_str.encode('base64'), + 'datas_fname': filename, + }) + simplified_form_view = self.env.ref( + 'account_payment_order.view_attachment_simplified_form') + action = { + 'name': _('Payment File'), + 'view_mode': 'form', + 'view_id': simplified_form_view.id, + 'res_model': 'ir.attachment', + 'type': 'ir.actions.act_window', + 'target': 'current', + 'res_id': attachment.id, + } self.write({ 'date_generated': fields.Date.context_today(self), 'state': 'generated', 'generated_user_id': self._uid, }) - simplified_form_view = self.env.ref( - 'account_payment_order.view_attachment_simplified_form') - action = { - 'name': _('Payment File'), - 'view_mode': 'form', - 'view_id': simplified_form_view.id, - 'res_model': 'ir.attachment', - 'type': 'ir.actions.act_window', - 'target': 'current', - 'res_id': attachment.id, - } return action @api.multi