[IMP] Account: Improve refund invoice wizard

bzr revid: mra@mra-laptop-20100814050555-ze43pvsvt3iaey68
This commit is contained in:
Mustufa Rangwala 2010-08-14 10:35:55 +05:30
parent 459d896486
commit da4ad519c5
3 changed files with 43 additions and 25 deletions

View File

@ -464,7 +464,7 @@ class account_invoice(osv.osv):
date_invoice = time.strftime('%Y-%m-%d') date_invoice = time.strftime('%Y-%m-%d')
pterm_list = pt_obj.compute(cr, uid, payment_term_id, value=1, date_ref=date_invoice) pterm_list = pt_obj.compute(cr, uid, payment_term_id, value=1, date_ref=date_invoice)
if pterm_list: if pterm_list:
pterm_list = [line[0] for line in pterm_list] pterm_list = [line[0] for line in pterm_list]
pterm_list.sort() pterm_list.sort()
@ -881,10 +881,10 @@ class account_invoice(osv.osv):
line = self.finalize_invoice_move_lines(cr, uid, inv, line) line = self.finalize_invoice_move_lines(cr, uid, inv, line)
move = { move = {
'ref': inv.number, 'ref': inv.number,
'line_id': line, 'line_id': line,
'journal_id': journal_id, 'journal_id': journal_id,
'date': date, 'date': date,
'type': entry_type, 'type': entry_type,
'narration':inv.comment 'narration':inv.comment
} }
@ -933,12 +933,12 @@ class account_invoice(osv.osv):
def action_number(self, cr, uid, ids, *args): def action_number(self, cr, uid, ids, *args):
# #TODO: not correct fix but required a frech values before reading it. # #TODO: not correct fix but required a frech values before reading it.
# self.write(cr, uid, ids, {}) # self.write(cr, uid, ids, {})
# #
cr.execute('SELECT id, type, number, move_id, reference ' \ cr.execute('SELECT id, type, number, move_id, reference ' \
'FROM account_invoice ' \ 'FROM account_invoice ' \
'WHERE id IN ('+','.join(map(str,ids))+')') 'WHERE id IN ('+','.join(map(str,ids))+')')
obj_inv = self.browse(cr, uid, ids)[0] obj_inv = self.browse(cr, uid, ids)[0]
for (id, invtype, number, move_id, reference) in cr.fetchall(): for (id, invtype, number, move_id, reference) in cr.fetchall():
if not number: if not number:
if obj_inv.journal_id.invoice_sequence_id: if obj_inv.journal_id.invoice_sequence_id:
@ -949,12 +949,12 @@ class account_invoice(osv.osv):
if not number: if not number:
raise osv.except_osv(_('Warning !'), _('There is no active invoice sequence defined for the journal !')) raise osv.except_osv(_('Warning !'), _('There is no active invoice sequence defined for the journal !'))
if invtype in ('in_invoice', 'in_refund'): if invtype in ('in_invoice', 'in_refund'):
ref = reference ref = reference
else: else:
ref = self._convert_ref(cr, uid, number) ref = self._convert_ref(cr, uid, number)
cr.execute('UPDATE account_invoice SET number=%s ' \ cr.execute('UPDATE account_invoice SET number=%s ' \
'WHERE id=%s', (number, id)) 'WHERE id=%s', (number, id))
cr.execute('UPDATE account_move SET ref=%s ' \ cr.execute('UPDATE account_move SET ref=%s ' \
@ -968,11 +968,11 @@ class account_invoice(osv.osv):
'WHERE account_move_line.move_id = %s ' \ 'WHERE account_move_line.move_id = %s ' \
'AND account_analytic_line.move_id = account_move_line.id', 'AND account_analytic_line.move_id = account_move_line.id',
(ref, move_id)) (ref, move_id))
for inv_id, name in self.name_get(cr, uid, [id]): for inv_id, name in self.name_get(cr, uid, [id]):
message = _('Invoice ') + " '" + name + "' "+ _("is validated.") message = _('Invoice ') + " '" + name + "' "+ _("is validated.")
self.log(cr, uid, inv_id, message) self.log(cr, uid, inv_id, message)
return True return True
def action_cancel(self, cr, uid, ids, *args): def action_cancel(self, cr, uid, ids, *args):
@ -1038,14 +1038,14 @@ class account_invoice(osv.osv):
for line in lines: for line in lines:
del line['id'] del line['id']
del line['invoice_id'] del line['invoice_id']
for field in ('company_id', 'partner_id', 'account_id', 'product_id', for field in ('company_id', 'partner_id', 'account_id', 'product_id',
'uos_id', 'account_analytic_id', 'tax_code_id', 'base_code_id'): 'uos_id', 'account_analytic_id', 'tax_code_id', 'base_code_id'):
line[field] = line.get(field, False) and line[field][0] line[field] = line.get(field, False) and line[field][0]
if 'invoice_line_tax_id' in line: if 'invoice_line_tax_id' in line:
line['invoice_line_tax_id'] = [(6,0, line.get('invoice_line_tax_id', [])) ] line['invoice_line_tax_id'] = [(6,0, line.get('invoice_line_tax_id', [])) ]
return map(lambda x: (0,0,x), lines) 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']) 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 = [] new_ids = []
@ -1059,17 +1059,19 @@ class account_invoice(osv.osv):
'in_refund': 'in_invoice', # Supplier Refund 'in_refund': 'in_invoice', # Supplier Refund
} }
invoice_lines = self.pool.get('account.invoice.line').read(cr, uid, invoice['invoice_line']) invoice_lines = self.pool.get('account.invoice.line').read(cr, uid, invoice['invoice_line'])
invoice_lines = self._refund_cleanup_lines(cr, uid, invoice_lines) 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 = self.pool.get('account.invoice.tax').read(cr, uid, invoice['tax_line'])
tax_lines = filter(lambda l: l['manual'], tax_lines) tax_lines = filter(lambda l: l['manual'], tax_lines)
tax_lines = self._refund_cleanup_lines(cr, uid, 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')]) refund_journal_ids = self.pool.get('account.journal').search(cr, uid, [('type','=','purchase_refund')])
else: else:
refund_journal_ids = self.pool.get('account.journal').search(cr, uid, [('type','=','sale_refund')]) refund_journal_ids = self.pool.get('account.journal').search(cr, uid, [('type','=','sale_refund')])
if not date : if not date :
date = time.strftime('%Y-%m-%d') date = time.strftime('%Y-%m-%d')
invoice.update({ invoice.update({
@ -1281,7 +1283,7 @@ class account_invoice_line(osv.osv):
context.update({'lang': part.lang}) context.update({'lang': part.lang})
result = {} result = {}
res = self.pool.get('product.product').browse(cr, uid, product, context=context) res = self.pool.get('product.product').browse(cr, uid, product, context=context)
if company_id: if company_id:
property_obj = self.pool.get('ir.property') property_obj = self.pool.get('ir.property')
account_obj = self.pool.get('account.account') account_obj = self.pool.get('account.account')

View File

@ -27,18 +27,31 @@ import netsvc
class account_invoice_refund(osv.osv_memory): class account_invoice_refund(osv.osv_memory):
"""Refunds invoice.""" """Refunds invoice"""
_name = "account.invoice.refund" _name = "account.invoice.refund"
_description = "Invoice Refund" _description = "Invoice Refund"
_columns = { _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!'), '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'), 'period': fields.many2one('account.period', 'Force period'),
'journal_id': fields.many2one('account.journal', 'Journal'),
'description': fields.char('Description', size=128, required=True), '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 = { _defaults = {
'date': time.strftime('%Y-%m-%d'), 'date': time.strftime('%Y-%m-%d'),
} 'journal_id': _get_journal
}
def compute_refund(self, cr, uid, ids, mode='refund', context=None): def compute_refund(self, cr, uid, ids, mode='refund', context=None):
""" """
@ -71,6 +84,8 @@ class account_invoice_refund(osv.osv_memory):
else: else:
period = inv.period_id and inv.period_id.id or False period = inv.period_id and inv.period_id.id or False
journal_id = form.get('journal_id', False)
if form['date'] : if form['date'] :
date = form['date'] date = form['date']
if not form['period'] : if not form['period'] :
@ -100,7 +115,7 @@ class account_invoice_refund(osv.osv_memory):
raise osv.except_osv(_('Data Insufficient !'), \ raise osv.except_osv(_('Data Insufficient !'), \
_('No Period found on Invoice!')) _('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) refund = inv_obj.browse(cr, uid, refund_id[0], context=context)
inv_obj.write(cr, uid, [refund.id], {'date_due': date, inv_obj.write(cr, uid, [refund.id], {'date_due': date,
'check_total': inv.check_total}) 'check_total': inv.check_total})
@ -124,7 +139,7 @@ class account_invoice_refund(osv.osv_memory):
for account in to_reconcile_ids : for account in to_reconcile_ids :
account_m_line_obj.reconcile(cr, uid, to_reconcile_ids[account], account_m_line_obj.reconcile(cr, uid, to_reconcile_ids[account],
writeoff_period_id=period, 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 writeoff_acc_id=inv.account_id.id
) )
if mode == 'modify': if mode == 'modify':
@ -180,15 +195,15 @@ class account_invoice_refund(osv.osv_memory):
result['res_id'] = created_inv result['res_id'] = created_inv
return result 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) 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) 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) return self.compute_refund(cr, uid, ids, 'modify', context=context)
account_invoice_refund() account_invoice_refund()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -12,9 +12,10 @@
<group colspan="4" > <group colspan="4" >
<label string="Are you sure you want to refund this invoice ?" colspan="2"/> <label string="Are you sure you want to refund this invoice ?" colspan="2"/>
<newline/> <newline/>
<field name="description"/>
<field name="date"/> <field name="date"/>
<field name="period"/> <field name="period"/>
<field name="description"/> <field name="journal_id" />
</group> </group>
<separator colspan="4"/> <separator colspan="4"/>
<group col="4" colspan="4" fill="1"> <group col="4" colspan="4" fill="1">