[IMP] Account: Improve refund invoice wizard
bzr revid: mra@mra-laptop-20100814050555-ze43pvsvt3iaey68
This commit is contained in:
parent
459d896486
commit
da4ad519c5
|
@ -1045,7 +1045,7 @@ class account_invoice(osv.osv):
|
|||
line['invoice_line_tax_id'] = [(6,0, line.get('invoice_line_tax_id', [])) ]
|
||||
return map(lambda x: (0,0,x), lines)
|
||||
|
||||
def refund(self, cr, uid, ids, date=None, period_id=None, description=None):
|
||||
def refund(self, cr, uid, ids, date=None, period_id=None, description=None, journal_id=None):
|
||||
invoices = self.read(cr, uid, ids, ['name', 'type', 'number', 'reference', 'comment', 'date_due', 'partner_id', 'address_contact_id', 'address_invoice_id', 'partner_contact', 'partner_insite', 'partner_ref', 'payment_term', 'account_id', 'currency_id', 'invoice_line', 'tax_line', 'journal_id'])
|
||||
|
||||
new_ids = []
|
||||
|
@ -1059,17 +1059,19 @@ class account_invoice(osv.osv):
|
|||
'in_refund': 'in_invoice', # Supplier Refund
|
||||
}
|
||||
|
||||
|
||||
invoice_lines = self.pool.get('account.invoice.line').read(cr, uid, invoice['invoice_line'])
|
||||
invoice_lines = self._refund_cleanup_lines(cr, uid, invoice_lines)
|
||||
|
||||
tax_lines = self.pool.get('account.invoice.tax').read(cr, uid, invoice['tax_line'])
|
||||
tax_lines = filter(lambda l: l['manual'], tax_lines)
|
||||
tax_lines = self._refund_cleanup_lines(cr, uid, tax_lines)
|
||||
if invoice['type'] == 'in_invoice':
|
||||
if journal_id:
|
||||
refund_journal_ids = [journal_id]
|
||||
elif invoice['type'] == 'in_invoice':
|
||||
refund_journal_ids = self.pool.get('account.journal').search(cr, uid, [('type','=','purchase_refund')])
|
||||
else:
|
||||
refund_journal_ids = self.pool.get('account.journal').search(cr, uid, [('type','=','sale_refund')])
|
||||
|
||||
if not date :
|
||||
date = time.strftime('%Y-%m-%d')
|
||||
invoice.update({
|
||||
|
|
|
@ -27,18 +27,31 @@ import netsvc
|
|||
|
||||
class account_invoice_refund(osv.osv_memory):
|
||||
|
||||
"""Refunds invoice."""
|
||||
"""Refunds invoice"""
|
||||
|
||||
_name = "account.invoice.refund"
|
||||
_description = "Invoice Refund"
|
||||
_columns = {
|
||||
'date': fields.date('Operation date', help='This date will be used as the invoice date for Refund Invoice and Period will be chosen accordingly!'),
|
||||
'period': fields.many2one('account.period', 'Force period'),
|
||||
'journal_id': fields.many2one('account.journal', 'Journal'),
|
||||
'description': fields.char('Description', size=128, required=True),
|
||||
}
|
||||
|
||||
def _get_journal(self, cr, uid, context=None):
|
||||
obj_journal = self.pool.get('account.journal')
|
||||
if context is None:
|
||||
context = {}
|
||||
journal = obj_journal.search(cr, uid, [('type', '=', 'sale_refund')])
|
||||
if context.get('type', False):
|
||||
if context['type'] == 'in_invoice':
|
||||
journal = obj_journal.search(cr, uid, [('type', '=', 'purchase_refund')])
|
||||
return journal and journal[0] or False
|
||||
|
||||
_defaults = {
|
||||
'date': time.strftime('%Y-%m-%d'),
|
||||
}
|
||||
'journal_id': _get_journal
|
||||
}
|
||||
|
||||
def compute_refund(self, cr, uid, ids, mode='refund', context=None):
|
||||
"""
|
||||
|
@ -71,6 +84,8 @@ class account_invoice_refund(osv.osv_memory):
|
|||
else:
|
||||
period = inv.period_id and inv.period_id.id or False
|
||||
|
||||
journal_id = form.get('journal_id', False)
|
||||
|
||||
if form['date'] :
|
||||
date = form['date']
|
||||
if not form['period'] :
|
||||
|
@ -100,7 +115,7 @@ class account_invoice_refund(osv.osv_memory):
|
|||
raise osv.except_osv(_('Data Insufficient !'), \
|
||||
_('No Period found on Invoice!'))
|
||||
|
||||
refund_id = inv_obj.refund(cr, uid, [inv.id], date, period, description)
|
||||
refund_id = inv_obj.refund(cr, uid, [inv.id], date, period, description, journal_id)
|
||||
refund = inv_obj.browse(cr, uid, refund_id[0], context=context)
|
||||
inv_obj.write(cr, uid, [refund.id], {'date_due': date,
|
||||
'check_total': inv.check_total})
|
||||
|
@ -124,7 +139,7 @@ class account_invoice_refund(osv.osv_memory):
|
|||
for account in to_reconcile_ids :
|
||||
account_m_line_obj.reconcile(cr, uid, to_reconcile_ids[account],
|
||||
writeoff_period_id=period,
|
||||
writeoff_journal_id=inv.journal_id.id,
|
||||
writeoff_journal_id = inv.journal_id.id,
|
||||
writeoff_acc_id=inv.account_id.id
|
||||
)
|
||||
if mode == 'modify':
|
||||
|
@ -180,13 +195,13 @@ class account_invoice_refund(osv.osv_memory):
|
|||
result['res_id'] = created_inv
|
||||
return result
|
||||
|
||||
def invoice_refund(self, cr, uid, ids, context={}):
|
||||
def invoice_refund(self, cr, uid, ids, context=None):
|
||||
return self.compute_refund(cr, uid, ids, 'refund', context=context)
|
||||
|
||||
def invoice_cancel(self, cr, uid, ids, context={}):
|
||||
def invoice_cancel(self, cr, uid, ids, context=None):
|
||||
return self.compute_refund(cr, uid, ids, 'cancel', context=context)
|
||||
|
||||
def invoice_modify(self, cr, uid, ids, context={}):
|
||||
def invoice_modify(self, cr, uid, ids, context=None):
|
||||
return self.compute_refund(cr, uid, ids, 'modify', context=context)
|
||||
|
||||
account_invoice_refund()
|
||||
|
|
|
@ -12,9 +12,10 @@
|
|||
<group colspan="4" >
|
||||
<label string="Are you sure you want to refund this invoice ?" colspan="2"/>
|
||||
<newline/>
|
||||
<field name="description"/>
|
||||
<field name="date"/>
|
||||
<field name="period"/>
|
||||
<field name="description"/>
|
||||
<field name="journal_id" />
|
||||
</group>
|
||||
<separator colspan="4"/>
|
||||
<group col="4" colspan="4" fill="1">
|
||||
|
|
Loading…
Reference in New Issue