From 26e88569c58a3f393a632d6757593eeebbb24ff8 Mon Sep 17 00:00:00 2001 From: Wolfgang Taferner Date: Thu, 18 May 2017 11:59:45 +0200 Subject: [PATCH] [IMP] account: fields of refunds streamlined for better inheritance Closed 17065 --- addons/account/models/account_invoice.py | 22 +++++++++++++++++-- .../account/wizard/account_invoice_refund.py | 13 +++-------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index ddd9011b7ce..52ad468d7a8 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -1029,6 +1029,25 @@ class AccountInvoice(models.Model): result.append((0, 0, values)) return result + @api.model + def _get_refund_common_fields(self): + return ['partner_id', 'payment_term_id', 'account_id', 'currency_id', 'journal_id'] + + @api.model + def _get_refund_prepare_fields(self): + return ['name', 'reference', 'comment', 'date_due'] + + @api.model + def _get_refund_modify_read_fields(self): + read_fields = ['type', 'number', 'invoice_line_ids', 'tax_line_ids', + 'date', 'partner_insite', 'partner_contact', 'partner_ref'] + return self._get_refund_common_fields() + self._get_refund_prepare_fields() + read_fields + + @api.model + def _get_refund_copy_fields(self): + copy_fields = ['company_id', 'user_id', 'fiscal_position_id'] + return self._get_refund_common_fields() + self._get_refund_prepare_fields() + copy_fields + @api.model def _prepare_refund(self, invoice, date_invoice=None, date=None, description=None, journal_id=None): """ Prepare the dict of values to create the new credit note from the invoice. @@ -1044,8 +1063,7 @@ class AccountInvoice(models.Model): :return: dict of value to create() the credit note """ values = {} - for field in ['name', 'reference', 'comment', 'date_due', 'partner_id', 'company_id', - 'account_id', 'currency_id', 'payment_term_id', 'user_id', 'fiscal_position_id']: + for field in self._get_refund_copy_fields(): if invoice._fields[field].type == 'many2one': values[field] = invoice[field].id else: diff --git a/addons/account/wizard/account_invoice_refund.py b/addons/account/wizard/account_invoice_refund.py index 5c5bf9eb607..4923ef95040 100644 --- a/addons/account/wizard/account_invoice_refund.py +++ b/addons/account/wizard/account_invoice_refund.py @@ -76,13 +76,7 @@ class AccountInvoiceRefund(models.TransientModel): to_reconcile_lines += tmpline to_reconcile_lines.filtered(lambda l: l.reconciled == False).reconcile() if mode == 'modify': - invoice = inv.read( - ['name', 'type', 'number', 'reference', - 'comment', 'date_due', 'partner_id', - 'partner_insite', 'partner_contact', - 'partner_ref', 'payment_term_id', 'account_id', - 'currency_id', 'invoice_line_ids', 'tax_line_ids', - 'journal_id', 'date']) + invoice = inv.read(inv_obj._get_refund_modify_read_fields()) invoice = invoice[0] del invoice['id'] invoice_lines = inv_line_obj.browse(invoice['invoice_line_ids']) @@ -100,9 +94,8 @@ class AccountInvoiceRefund(models.TransientModel): 'origin': inv.origin, 'fiscal_position_id': inv.fiscal_position_id.id, }) - for field in ('partner_id', 'account_id', 'currency_id', - 'payment_term_id', 'journal_id'): - invoice[field] = invoice[field] and invoice[field][0] + for field in inv_obj._get_refund_common_fields(): + invoice[field] = invoice[field] and invoice[field][0] inv_refund = inv_obj.create(invoice) if inv_refund.payment_term_id.id: inv_refund._onchange_payment_term_date_invoice()