diff --git a/addons/account/invoice.py b/addons/account/invoice.py index b9620e4e123..06b520f0e18 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -464,7 +464,7 @@ class account_invoice(osv.osv): date_invoice = time.strftime('%Y-%m-%d') pterm_list = pt_obj.compute(cr, uid, payment_term_id, value=1, date_ref=date_invoice) - + if pterm_list: pterm_list = [line[0] for line in pterm_list] pterm_list.sort() @@ -881,10 +881,10 @@ class account_invoice(osv.osv): line = self.finalize_invoice_move_lines(cr, uid, inv, line) move = { - 'ref': inv.number, - 'line_id': line, - 'journal_id': journal_id, - 'date': date, + 'ref': inv.number, + 'line_id': line, + 'journal_id': journal_id, + 'date': date, 'type': entry_type, 'narration':inv.comment } @@ -933,12 +933,12 @@ class account_invoice(osv.osv): def action_number(self, cr, uid, ids, *args): # #TODO: not correct fix but required a frech values before reading it. # self.write(cr, uid, ids, {}) -# +# cr.execute('SELECT id, type, number, move_id, reference ' \ 'FROM account_invoice ' \ 'WHERE id IN ('+','.join(map(str,ids))+')') obj_inv = self.browse(cr, uid, ids)[0] - + for (id, invtype, number, move_id, reference) in cr.fetchall(): if not number: if obj_inv.journal_id.invoice_sequence_id: @@ -949,12 +949,12 @@ class account_invoice(osv.osv): if not number: raise osv.except_osv(_('Warning !'), _('There is no active invoice sequence defined for the journal !')) - + if invtype in ('in_invoice', 'in_refund'): ref = reference else: ref = self._convert_ref(cr, uid, number) - + cr.execute('UPDATE account_invoice SET number=%s ' \ 'WHERE id=%s', (number, id)) cr.execute('UPDATE account_move SET ref=%s ' \ @@ -968,11 +968,11 @@ class account_invoice(osv.osv): 'WHERE account_move_line.move_id = %s ' \ 'AND account_analytic_line.move_id = account_move_line.id', (ref, move_id)) - + for inv_id, name in self.name_get(cr, uid, [id]): message = _('Invoice ') + " '" + name + "' "+ _("is validated.") self.log(cr, uid, inv_id, message) - + return True def action_cancel(self, cr, uid, ids, *args): @@ -1038,14 +1038,14 @@ class account_invoice(osv.osv): for line in lines: del line['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'): line[field] = line.get(field, False) and line[field][0] if 'invoice_line_tax_id' in line: 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({ @@ -1281,7 +1283,7 @@ class account_invoice_line(osv.osv): context.update({'lang': part.lang}) result = {} res = self.pool.get('product.product').browse(cr, uid, product, context=context) - + if company_id: property_obj = self.pool.get('ir.property') account_obj = self.pool.get('account.account') diff --git a/addons/account/wizard/account_invoice_refund.py b/addons/account/wizard/account_invoice_refund.py index a38bfa69d7a..50d6770fd3c 100644 --- a/addons/account/wizard/account_invoice_refund.py +++ b/addons/account/wizard/account_invoice_refund.py @@ -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,15 +195,15 @@ 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() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/account/wizard/account_invoice_refund_view.xml b/addons/account/wizard/account_invoice_refund_view.xml index 82607b0d922..e4849823d52 100644 --- a/addons/account/wizard/account_invoice_refund_view.xml +++ b/addons/account/wizard/account_invoice_refund_view.xml @@ -12,9 +12,10 @@