[IMP] account: fields of refunds streamlined for better inheritance
Closed 17065
This commit is contained in:
committed by
Yannick Tivisse
parent
ce44ad2440
commit
26e88569c5
@@ -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:
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user