From 808fb068c48b91ed7cb9c63bf6f25f251b3c9989 Mon Sep 17 00:00:00 2001
From: "ATP (Open ERP)" <>
Date: Fri, 26 Feb 2010 16:50:39 +0530
Subject: [PATCH] [IMP]: Account: Converted all simple wizards to osv_memory
wizards in account module
bzr revid: rpa@openerp.co.in-20100226112039-bzb7rw7pej7v804k
---
addons/account/__terp__.py | 10 +
addons/account/account_invoice_view.xml | 10 +-
addons/account/account_view.xml | 9 +-
addons/account/account_wizard.xml | 15 +-
addons/account/wizard/__init__.py | 8 +
addons/account/wizard/account_chart.py | 79 ++++++
.../account/wizard/account_invoice_refund.py | 203 ++++++++++++++++
.../wizard/account_move_bank_reconcile.py | 62 +++++
addons/account/wizard/account_move_journal.py | 97 ++++++++
.../account_move_line_reconcile_select.py | 55 +++++
addons/account/wizard/account_period_close.py | 56 +++++
addons/account/wizard/wizard_account_chart.py | 80 -------
.../wizard/wizard_automatic_reconcile.py | 1 +
.../account/wizard/wizard_bank_reconcile.py | 67 ------
.../wizard/wizard_fiscalyear_close_state.py | 71 ------
addons/account/wizard/wizard_journal.py | 99 --------
addons/account/wizard/wizard_period_close.py | 57 -----
.../account/wizard/wizard_reconcile_select.py | 61 -----
addons/account/wizard/wizard_refund.py | 226 ------------------
19 files changed, 590 insertions(+), 676 deletions(-)
create mode 100644 addons/account/wizard/account_chart.py
create mode 100644 addons/account/wizard/account_invoice_refund.py
create mode 100644 addons/account/wizard/account_move_bank_reconcile.py
create mode 100644 addons/account/wizard/account_move_journal.py
create mode 100644 addons/account/wizard/account_move_line_reconcile_select.py
create mode 100644 addons/account/wizard/account_period_close.py
delete mode 100644 addons/account/wizard/wizard_account_chart.py
delete mode 100644 addons/account/wizard/wizard_bank_reconcile.py
delete mode 100644 addons/account/wizard/wizard_fiscalyear_close_state.py
delete mode 100644 addons/account/wizard/wizard_journal.py
delete mode 100644 addons/account/wizard/wizard_period_close.py
delete mode 100644 addons/account/wizard/wizard_reconcile_select.py
delete mode 100644 addons/account/wizard/wizard_refund.py
diff --git a/addons/account/__terp__.py b/addons/account/__terp__.py
index 921dc8c8cb9..e600b806e08 100644
--- a/addons/account/__terp__.py
+++ b/addons/account/__terp__.py
@@ -40,9 +40,19 @@
'security/account_security.xml',
'security/ir.model.access.csv',
'account_menuitem.xml',
+ 'wizard/account_invoice_refund_view.xml',
+ 'wizard/account_period_close_view.xml',
+ 'wizard/account_fiscalyear_close_state.xml',
+ 'wizard/account_chart_view.xml',
+ 'wizard/account_move_bank_reconcile_view.xml',
+ 'wizard/account_move_line_reconcile_select_view.xml',
+ 'wizard/account_move_journal_view.xml',
+
+
'account_wizard.xml',
'account_view.xml',
'account_end_fy.xml',
+
'account_invoice_view.xml',
'account_report.xml',
'partner_view.xml',
diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml
index 60eed3e0e62..4f8db313fc7 100644
--- a/addons/account/account_invoice_view.xml
+++ b/addons/account/account_invoice_view.xml
@@ -189,11 +189,13 @@
-
+
+
+
@@ -279,13 +281,15 @@
-
+
-
+
+
+
diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml
index 3ef24386c2d..d28748b4efb 100644
--- a/addons/account/account_view.xml
+++ b/addons/account/account_view.xml
@@ -81,6 +81,7 @@
+
@@ -668,8 +669,8 @@
-
-
+
+
@@ -1080,7 +1081,7 @@
-
+
-
+
-
+
+ sequence="1"/>-->
-
+
-
-
+
-
+
).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+import wizard
+import netsvc
+import pooler
+import time
+from tools.translate import _
+import tools
+from osv import fields, osv
+
+class account_chart(osv.osv_memory):
+ """
+ For account chart
+ """
+
+ def _get_defaults(self, cr, uid, context):
+
+ """Return default Fiscalyear value"""
+
+ fiscalyear_obj = self.pool.get('account.fiscalyear')
+ fiscalyear = fiscalyear_obj.find(cr, uid)
+ return fiscalyear
+
+ def _account_chart_open_window(self, cr, uid, ids, context):
+ """
+ cr is the current row, from the database cursor,
+ uid is the current user’s ID for security checks,
+ ID is the account chart’s ID or list of IDs if we want more than one
+ This function Open account chart window on given fiscalyear and all Entries or posted entries
+ """
+ for form in self.read(cr, uid, ids):
+ mod_obj = self.pool.get('ir.model.data')
+ act_obj = self.pool.get('ir.actions.act_window')
+
+ result = mod_obj._get_id(cr, uid, 'account', 'action_account_tree')
+ id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
+ result = act_obj.read(cr, uid, [id], context=context)[0]
+ result['context'] = str({'fiscalyear': form['fiscalyear'],'state':form['target_move']})
+ if form['fiscalyear']:
+ result['name']+=':'+self.pool.get('account.fiscalyear').read(cr,uid,[form['fiscalyear']])[0]['code']
+
+ return result
+
+
+ _name = "account.chart"
+ _description = "chart"
+ _columns = {
+ 'fiscalyear':fields.many2one('account.fiscalyear', 'Fiscal year', required=True, help = 'Keep empty for all open fiscal years'),
+ 'target_move':fields.selection([
+ ('all','All Entries'),
+ ('posted','All Posted Entries'),
+ ],'Target Moves', required = True),
+
+ }
+ _defaults = {
+ 'fiscalyear':_get_defaults,
+ 'target_move':lambda * a:'all'
+
+ }
+
+account_chart()
diff --git a/addons/account/wizard/account_invoice_refund.py b/addons/account/wizard/account_invoice_refund.py
new file mode 100644
index 00000000000..acd85d4f7ef
--- /dev/null
+++ b/addons/account/wizard/account_invoice_refund.py
@@ -0,0 +1,203 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+import wizard
+import netsvc
+import pooler
+import time
+from tools.translate import _
+import tools
+from osv import fields, osv
+
+class account_invoice_refund(osv.osv_memory):
+
+ """Account invoice refund or modify or cancel."""
+
+ _name = "account.invoice.refund"
+ _description = "Invoice Refund"
+ _columns = {
+ 'date':fields.date('Operation date',required=False),
+ 'period':fields.many2one('account.period', 'Force period', required=False),
+ 'description':fields.char('Description', size=150, required=True),
+ }
+
+ def _compute_refund(self, cr, uid, ids, mode, context):
+ """
+ cr is the current row, from the database cursor,
+ uid is the current user’s ID for security checks,
+ ID is the account invoice refund’s ID or list of IDs if we want more than one
+
+ """
+
+ for form in self.read(cr, uid, ids):
+ reconcile_obj = self.pool.get('account.move.reconcile')
+ account_m_line_obj = self.pool.get('account.move.line')
+ created_inv = []
+ date = False
+ period = False
+ description = False
+ for inv in self.pool.get('account.invoice').browse(cr, uid, context['active_ids']):
+ if inv.state in ['draft', 'proforma2', 'cancel']:
+ raise osv.except_osv(_('Error !'), _('Can not %s draft/proforma/cancel invoice.') % (mode))
+ if form['period'] :
+ period = form['period']
+ else:
+ period = inv.period_id and inv.period_id.id or False
+
+ if form['date'] :
+ date = form['date']
+ if not form['period'] :
+ cr.execute("select name from ir_model_fields where model='account.period' and name='company_id'")
+ result_query = cr.fetchone()
+ if result_query:
+ #in multi company mode
+ cr.execute("""SELECT id
+ from account_period where date('%s')
+ between date_start AND date_stop and company_id = %s limit 1 """,
+ (form['date'],self.pool.get('res.users').browse(cr, uid, uid).company_id.id,))
+ else:
+ #in mono company mode
+ cr.execute("""SELECT id
+ from account_period where date('%s')
+ between date_start AND date_stop limit 1 """,
+ (form['date'],))
+ res = cr.fetchone()
+ if res:
+ period = res[0]
+ else:
+ date = inv.date_invoice
+
+ if form['description'] :
+ description = form['description']
+ else:
+ description = inv.name
+
+ if not period:
+ raise osv.except_osv(_('Data Insufficient !'), _('No Period found on Invoice!'))
+
+ refund_id = self.pool.get('account.invoice').refund(cr, uid, [inv.id],date, period, description)
+ refund = self.pool.get('account.invoice').browse(cr, uid, refund_id[0])
+ # we compute due date
+ #!!!due date = date inv date on formdate
+ self.pool.get('account.invoice').write(cr, uid, [refund.id],{'date_due':date,'check_total':inv.check_total})
+ # to make the taxes calculated
+ self.pool.get('account.invoice').button_compute(cr, uid, refund_id)
+
+ created_inv.append(refund_id[0])
+ #if inv is paid we unreconcile
+ if mode in ('cancel','modify'):
+ movelines = inv.move_id.line_id
+ #we unreconcile the lines
+ to_reconcile_ids = {}
+ for line in movelines :
+ #if the account of the line is the as the one in the invoice
+ #we reconcile
+ if line.account_id.id == inv.account_id.id :
+ to_reconcile_ids[line.account_id.id] =[line.id]
+ if type(line.reconcile_id) != osv.orm.browse_null :
+ reconcile_obj.unlink(cr,uid, line.reconcile_id.id)
+ #we advance the workflow of the refund to open
+ wf_service = netsvc.LocalService('workflow')
+ wf_service.trg_validate(uid, 'account.invoice', refund.id, 'invoice_open', cr)
+ #we reload the browse record
+ refund = self.pool.get('account.invoice').browse(cr, uid, refund_id[0])
+ #we match the line to reconcile
+ for tmpline in refund.move_id.line_id :
+ if tmpline.account_id.id == inv.account_id.id :
+ to_reconcile_ids[tmpline.account_id.id].append(tmpline.id)
+ 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_acc_id=inv.account_id.id
+ )
+ #we create a new invoice that is the copy of the original
+ if mode == 'modify' :
+ invoice = self.pool.get('account.invoice').read(cr, uid, [inv.id],
+ ['name', 'type', 'number', 'reference',
+ 'comment', 'date_due', 'partner_id', 'address_contact_id',
+ 'address_invoice_id', 'partner_insite','partner_contact',
+ 'partner_ref', 'payment_term', 'account_id', 'currency_id',
+ 'invoice_line', 'tax_line', 'journal_id','period_id'
+ ]
+ )
+ invoice = invoice[0]
+ del invoice['id']
+ invoice_lines = self.pool.get('account.invoice.line').read(cr, uid, invoice['invoice_line'])
+ invoice_lines = self.pool.get('account.invoice')._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')._refund_cleanup_lines(cr, uid, tax_lines)
+
+ invoice.update({
+ 'type': inv.type,
+ 'date_invoice': date,
+ 'state': 'draft',
+ 'number': False,
+ 'invoice_line': invoice_lines,
+ 'tax_line': tax_lines,
+ 'period_id': period,
+ 'name':description
+ })
+
+ #take the id part of the tuple returned for many2one fields
+ for field in ('address_contact_id', 'address_invoice_id', 'partner_id',
+ 'account_id', 'currency_id', 'payment_term', 'journal_id'):
+ invoice[field] = invoice[field] and invoice[field][0]
+
+ # create the new invoice
+ inv_id = self.pool.get('account.invoice').create(cr, uid, invoice,{})
+ # we compute due date
+ if inv.payment_term.id:
+ data = self.pool.get('account.invoice').onchange_payment_term_date_invoice(cr, uid, [inv_id],inv.payment_term.id,date)
+ if 'value' in data and data['value']:
+ self.pool.get('account.invoice').write(cr, uid, [inv_id],data['value'])
+ created_inv.append(inv_id)
+
+ #we get the view id
+ mod_obj = self.pool.get('ir.model.data')
+ act_obj = self.pool.get('ir.actions.act_window')
+ if inv.type == 'out_invoice':
+ xml_id = 'action_invoice_tree1'
+ elif inv.type == 'in_invoice':
+ xml_id = 'action_invoice_tree2'
+ elif type == 'out_refund':
+ xml_id = 'action_invoice_tree3'
+ else:
+ xml_id = 'action_invoice_tree4'
+ #we get the model
+ result = mod_obj._get_id(cr, uid, 'account', xml_id)
+ id = mod_obj.read(cr, uid, result, ['res_id'])['res_id']
+ # we read the act window
+ result = act_obj.read(cr, uid, id)
+ result['res_id'] = created_inv
+
+ return result
+
+ def _invoice_refund(self, cr, uid, ids, context):
+ return self._compute_refund(cr, uid, ids, 'refund', context)
+
+ def _invoice_cancel(self, cr, uid, ids, context):
+ return self._compute_refund(cr, uid, ids, 'cancel', context)
+
+ def _invoice_modify(self, cr, uid, ids, context):
+ return self._compute_refund(cr, uid, ids, 'modify', context)
+
+account_invoice_refund()
diff --git a/addons/account/wizard/account_move_bank_reconcile.py b/addons/account/wizard/account_move_bank_reconcile.py
new file mode 100644
index 00000000000..4dd3e1354c2
--- /dev/null
+++ b/addons/account/wizard/account_move_bank_reconcile.py
@@ -0,0 +1,62 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+import wizard
+import netsvc
+import pooler
+import time
+from tools.translate import _
+import tools
+from osv import fields, osv
+
+
+class account_move_bank_reconcile(osv.osv_memory):
+
+ _name = "account.move.bank.reconcile"
+ _description = "Move bank reconcile"
+ _columns = {
+ 'journal_id':fields.many2one('account.journal', 'Journal', required=True),
+
+ }
+ def _action_open_window(self, cr, uid, ids, context):
+ """
+ cr is the current row, from the database cursor,
+ uid is the current user’s ID for security checks,
+ ID is the account move bank reconcile’s ID or list of IDs if we want more than one
+ This function Open account move line on given journal_id.
+ """
+ for form in self.read(cr, uid, ids):
+ cr.execute('select default_credit_account_id from account_journal where id=%s', (form['journal_id'],))
+ account_id = cr.fetchone()[0]
+ if not account_id:
+ raise osv.except_osv(_('Error'), _('You have to define the bank account\nin the journal definition for reconciliation.'))
+ return {
+ 'domain': "[('journal_id','=',%d), ('account_id','=',%d), ('state','<>','draft')]" % (form['journal_id'],account_id),
+ 'name': _('Standard Encoding'),
+
+ 'view_type': 'form',
+ 'view_mode': 'tree,form',
+ 'res_model': 'account.move.line',
+ 'view_id': False,
+ 'context': "{'journal_id':%d}" % (form['journal_id'],),
+ 'type': 'ir.actions.act_window'
+ }
+
+account_move_bank_reconcile()
\ No newline at end of file
diff --git a/addons/account/wizard/account_move_journal.py b/addons/account/wizard/account_move_journal.py
new file mode 100644
index 00000000000..cc74f663677
--- /dev/null
+++ b/addons/account/wizard/account_move_journal.py
@@ -0,0 +1,97 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+import wizard
+import netsvc
+import pooler
+import time
+from tools.translate import _
+import tools
+from osv import fields, osv
+
+
+class account_move_journal(osv.osv_memory):
+
+ def _get_period(self, cr, uid, context={}):
+ """Return default account period value"""
+
+ ids = self.pool.get('account.period').find(cr, uid, context=context)
+ period_id = False
+ if len(ids):
+ period_id = ids[0]
+ return period_id
+
+ def _action_open_window(self, cr, uid, ids, context={}):
+ """
+ cr is the current row, from the database cursor,
+ uid is the current user’s ID for security checks,
+ ID is the account move journal’s ID or list of IDs if we want more than one
+ This function Open action move line window on given period and Journal/Payment Mode
+ """
+ for form in self.read(cr, uid, ids,['journal_id', 'period_id']):
+ cr.execute('select id,name from ir_ui_view where model=%s and type=%s', ('account.move.line', 'form' ))
+ view_res = cr.fetchone()
+ jp = self.pool.get('account.journal.period')
+ ids = jp.search(cr, uid, [('journal_id','=',form['journal_id']), ('period_id','=',form['period_id'])])
+
+ if not len(ids):
+ print "ids",ids
+ name = self.pool.get('account.journal').read(cr, uid, [form['journal_id']])[0]['name']
+ state = self.pool.get('account.period').read(cr, uid, [form['period_id']])[0]['state']
+ if state == 'done':
+ raise osv.except_osv(_('UserError'), _('This period is already closed !'))
+ company = self.pool.get('account.period').read(cr, uid, [form['period_id']])[0]['company_id'][0]
+ jp.create(cr, uid, {'name':name, 'period_id': form['period_id'], 'journal_id':form['journal_id'], 'company_id':company})
+ ids = jp.search(cr, uid, [('journal_id','=',form['journal_id']), ('period_id','=',form['period_id'])])
+ print "jp",ids
+ jp = jp.browse(cr, uid, ids, context=context)[0]
+ name = (jp.journal_id.code or '') + ':' + (jp.period_id.code or '')
+ mod_obj = self.pool.get('ir.model.data')
+ result = mod_obj._get_id(cr, uid, 'account', 'view_account_move_line_filter')
+ id = mod_obj.read(cr, uid, result, ['res_id'])
+ return {
+ 'domain': "[('journal_id','=',%d), ('period_id','=',%d)]" % (form['journal_id'],form['period_id']),
+ 'name': name,
+ 'view_type': 'form',
+ 'view_mode': 'tree,form',
+ 'res_model': 'account.move.line',
+ 'view_id': view_res,
+ 'context': "{'journal_id':%d, 'period_id':%d}" % (form['journal_id'],form['period_id']),
+ 'type': 'ir.actions.act_window',
+ 'search_view_id': id['res_id']
+ }
+
+ _name = "account.move.journal"
+ _description = "Move journal"
+
+ _columns = {
+ 'journal_id':fields.many2one('account.journal', 'Journal/Payment Mode', required=True),
+ 'period_id':fields.many2one('account.period', 'Period', required=True),
+ }
+
+ _defaults = {
+ 'period_id':_get_period
+ }
+
+account_move_journal()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+
diff --git a/addons/account/wizard/account_move_line_reconcile_select.py b/addons/account/wizard/account_move_line_reconcile_select.py
new file mode 100644
index 00000000000..5c100b38ac0
--- /dev/null
+++ b/addons/account/wizard/account_move_line_reconcile_select.py
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+import wizard
+import netsvc
+import pooler
+import time
+from tools.translate import _
+import tools
+from osv import fields, osv
+
+class account_move_line_reconcile_select(osv.osv_memory):
+ _name = "account.move.line.reconcile.select"
+ _description = "Move line reconcile select"
+ _columns = {
+ 'account_id':fields.many2one('account.account', 'Account', domain = [('reconcile','=',1)], required=True),
+ }
+
+ def _action_open_window(self, cr, uid, ids, context):
+ """
+ cr is the current row, from the database cursor,
+ uid is the current user’s ID for security checks,
+ ID is the account move line reconcile select’s ID or list of IDs if we want more than one
+ This function Open account move line window for reconcile on given account id
+ """
+ for data in self.read(cr, uid, ids):
+
+ return {
+ 'domain': "[('account_id','=',%d),('reconcile_id','=',False),('state','<>','draft')]" % data['account_id'],
+ 'name': _('Reconciliation'),
+ 'view_type': 'form',
+ 'view_mode': 'tree,form',
+ 'view_id': False,
+ 'res_model': 'account.move.line',
+ 'type': 'ir.actions.act_window'
+ }
+
+account_move_line_reconcile_select()
\ No newline at end of file
diff --git a/addons/account/wizard/account_period_close.py b/addons/account/wizard/account_period_close.py
new file mode 100644
index 00000000000..4df4e652ec5
--- /dev/null
+++ b/addons/account/wizard/account_period_close.py
@@ -0,0 +1,56 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+import wizard
+import netsvc
+import pooler
+import time
+from tools.translate import _
+import tools
+from osv import fields, osv
+
+
+class account_period_close(osv.osv_memory):
+ """close period"""
+ _name = "account.period.close"
+ _description = "period close"
+ _columns = {
+ 'sure':fields.boolean('Check this box', required=False),
+ }
+
+ def _data_save(self, cr, uid, ids, context):
+ """
+ cr is the current row, from the database cursor,
+ uid is the current user’s ID for security checks,
+ ID is the account period close’s ID or list of IDs if we want more than one
+ This function close period
+ """
+
+ mode = 'done'
+ for form in self.read(cr, uid, ids):
+ if form['sure']:
+ for id in context['active_ids']:
+ cr.execute('update account_journal_period set state=%s where period_id=%s', (mode, id))
+ cr.execute('update account_period set state=%s where id=%s', (mode, id))
+ return {}
+
+account_period_close()
+
+
diff --git a/addons/account/wizard/wizard_account_chart.py b/addons/account/wizard/wizard_account_chart.py
deleted file mode 100644
index ca8153f3ce7..00000000000
--- a/addons/account/wizard/wizard_account_chart.py
+++ /dev/null
@@ -1,80 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-# OpenERP, Open Source Management Solution
-# Copyright (C) 2004-2010 Tiny SPRL ().
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see .
-#
-##############################################################################
-
-import wizard
-import pooler
-
-class wizard_account_chart(wizard.interface):
- _account_chart_arch = '''
- '''
-
- _account_chart_fields = {
- 'fiscalyear': {
- 'string': 'Fiscal year',
- 'type': 'many2one',
- 'relation': 'account.fiscalyear',
- 'help': 'Keep empty for all open fiscal years',
- },
- 'target_move': {
- 'string': 'Target Moves',
- 'type': 'selection',
- 'selection': [('all','All Entries'),('posted','All Posted Entries')],
- 'required': True,
- 'default': lambda *a:"all",
- },
- }
-
- def _get_defaults(self, cr, uid, data, context):
- fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
- data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
- return data['form']
-
-
- def _account_chart_open_window(self, cr, uid, data, context):
- mod_obj = pooler.get_pool(cr.dbname).get('ir.model.data')
- act_obj = pooler.get_pool(cr.dbname).get('ir.actions.act_window')
-
- result = mod_obj._get_id(cr, uid, 'account', 'action_account_tree')
- id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
- result = act_obj.read(cr, uid, [id], context=context)[0]
- result['context'] = str({'fiscalyear': data['form']['fiscalyear'],'state':data['form']['target_move']})
- if data['form']['fiscalyear']:
- result['name']+=':'+pooler.get_pool(cr.dbname).get('account.fiscalyear').read(cr,uid,[data['form']['fiscalyear']])[0]['code']
- return result
-
- states = {
- 'init': {
- 'actions': [_get_defaults],
- 'result': {'type': 'form', 'arch':_account_chart_arch, 'fields':_account_chart_fields, 'state': [('end', 'Cancel'), ('open', 'Open Charts')]}
- },
- 'open': {
- 'actions': [],
- 'result': {'type': 'action', 'action':_account_chart_open_window, 'state':'end'}
- }
- }
-wizard_account_chart('account.chart')
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-
diff --git a/addons/account/wizard/wizard_automatic_reconcile.py b/addons/account/wizard/wizard_automatic_reconcile.py
index 7a0f5a8c465..e80b4406fdf 100644
--- a/addons/account/wizard/wizard_automatic_reconcile.py
+++ b/addons/account/wizard/wizard_automatic_reconcile.py
@@ -218,6 +218,7 @@ def _reconcile(self, cr, uid, data, context):
max_amount = form.get('max_amount', 0.0)
power = form['power']
reconciled = unreconciled = 0
+ print "form",form
if not form['account_ids'][0][2]:
raise wizard.except_wizard(_('UserError'), _('You must select accounts to reconcile'))
for account_id in form['account_ids'][0][2]:
diff --git a/addons/account/wizard/wizard_bank_reconcile.py b/addons/account/wizard/wizard_bank_reconcile.py
deleted file mode 100644
index c081657304a..00000000000
--- a/addons/account/wizard/wizard_bank_reconcile.py
+++ /dev/null
@@ -1,67 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-# OpenERP, Open Source Management Solution
-# Copyright (C) 2004-2010 Tiny SPRL ().
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see .
-#
-##############################################################################
-
-import wizard
-from tools.translate import _
-
-_journal_form = '''
-''' % ('Bank reconciliation',)
-
-_journal_fields = {
- 'journal_id': {'string':'Journal', 'type':'many2one', 'relation':'account.journal', 'required':True},
-}
-
-def _action_open_window(self, cr, uid, data, context):
- form = data['form']
- cr.execute('select default_credit_account_id from account_journal where id=%s', (form['journal_id'],))
- account_id = cr.fetchone()[0]
- if not account_id:
- raise wizard.except_wizard(_('Error'), _('You have to define the bank account\nin the journal definition for reconciliation.'))
- return {
- 'domain': "[('journal_id','=',%d), ('account_id','=',%d), ('state','<>','draft')]" % (form['journal_id'],account_id),
- 'name': _('Standard Encoding'),
-
- 'view_type': 'form',
- 'view_mode': 'tree,form',
- 'res_model': 'account.move.line',
- 'view_id': False,
- 'context': "{'journal_id':%d}" % (form['journal_id'],),
- 'type': 'ir.actions.act_window'
- }
-
-class wiz_journal(wizard.interface):
- states = {
- 'init': {
- 'actions': [],
- 'result': {'type': 'form', 'arch':_journal_form, 'fields':_journal_fields, 'state':[('end','Cancel'),('open','Open for bank reconciliation')]}
- },
- 'open': {
- 'actions': [],
- 'result': {'type': 'action', 'action': _action_open_window, 'state':'end'}
- }
- }
-wiz_journal('account.move.bank.reconcile')
-
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-
diff --git a/addons/account/wizard/wizard_fiscalyear_close_state.py b/addons/account/wizard/wizard_fiscalyear_close_state.py
deleted file mode 100644
index 2f8331f2d3e..00000000000
--- a/addons/account/wizard/wizard_fiscalyear_close_state.py
+++ /dev/null
@@ -1,71 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-# OpenERP, Open Source Management Solution
-# Copyright (C) 2004-2010 Tiny SPRL ().
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see .
-#
-##############################################################################
-
-import wizard
-import osv
-import pooler
-from tools.translate import _
-
-_transaction_form = '''
-'''
-
-_transaction_fields = {
- 'fy_id': {'string':'Fiscal Year to close', 'type':'many2one', 'relation': 'account.fiscalyear','required':True, 'domain':[('state','=','draft')]},
- 'sure': {'string':'Check this box', 'type':'boolean'},
-}
-
-def _data_save(self, cr, uid, data, context):
- if not data['form']['sure']:
- raise wizard.except_wizard(_('UserError'), _('Closing of states cancelled, please check the box !'))
- pool = pooler.get_pool(cr.dbname)
-
- fy_id = data['form']['fy_id']
-
- cr.execute('UPDATE account_journal_period ' \
- 'SET state = %s ' \
- 'WHERE period_id IN (SELECT id FROM account_period WHERE fiscalyear_id = %s)',
- ('done',fy_id))
- cr.execute('UPDATE account_period SET state = %s ' \
- 'WHERE fiscalyear_id = %s', ('done',fy_id))
- cr.execute('UPDATE account_fiscalyear ' \
- 'SET state = %s WHERE id = %s', ('done', fy_id))
- return {}
-
-class wiz_journal_close_state(wizard.interface):
- states = {
- 'init': {
- 'actions': [],
- 'result': {'type': 'form', 'arch':_transaction_form, 'fields':_transaction_fields, 'state':[('end','Cancel'),('close','Close states')]}
- },
- 'close': {
- 'actions': [_data_save],
- 'result': {'type': 'state', 'state':'end'}
- }
- }
-wiz_journal_close_state('account.fiscalyear.close.state')
-
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-
diff --git a/addons/account/wizard/wizard_journal.py b/addons/account/wizard/wizard_journal.py
deleted file mode 100644
index fd2b012863e..00000000000
--- a/addons/account/wizard/wizard_journal.py
+++ /dev/null
@@ -1,99 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-# OpenERP, Open Source Management Solution
-# Copyright (C) 2004-2010 Tiny SPRL ().
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see .
-#
-##############################################################################
-
-import wizard
-from osv import osv
-import pooler
-from tools.translate import _
-
-_journal_form = '''
-'''
-
-def _period_get(self, cr, uid, datas, ctx={}):
- try:
- pool = pooler.get_pool(cr.dbname)
- ids = pool.get('account.period').find(cr, uid, context=ctx)
- return {'period_id': ids[0]}
- except:
- return {}
-
-_journal_fields = {
- 'journal_id': {'string':'Journal', 'type':'many2one', 'relation':'account.journal', 'required':True},
- 'period_id': {
- 'string':'Period',
- 'type':'many2one',
- 'relation':'account.period',
- 'required':True,
- }
-}
-
-def _action_open_window(self, cr, uid, data, context):
- form = data['form']
- cr.execute('select id,name from ir_ui_view where model=%s and type=%s', ('account.move.line', 'form'))
- view_res = cr.fetchone()
- jp = pooler.get_pool(cr.dbname).get('account.journal.period')
- ids = jp.search(cr, uid, [('journal_id','=',form['journal_id']), ('period_id','=',form['period_id'])])
- if not len(ids):
- name = pooler.get_pool(cr.dbname).get('account.journal').read(cr, uid, [form['journal_id']])[0]['name']
- state = pooler.get_pool(cr.dbname).get('account.period').read(cr, uid, [form['period_id']])[0]['state']
- if state == 'done':
- raise wizard.except_wizard(_('UserError'), _('This period is already closed !'))
- company = pooler.get_pool(cr.dbname).get('account.period').read(cr, uid, [form['period_id']])[0]['company_id'][0]
- jp.create(cr, uid, {'name':name, 'period_id': form['period_id'], 'journal_id':form['journal_id'], 'company_id':company})
- ids = jp.search(cr, uid, [('journal_id','=',form['journal_id']), ('period_id','=',form['period_id'])])
- jp = jp.browse(cr, uid, ids, context=context)[0]
- name = (jp.journal_id.code or '') + ':' + (jp.period_id.code or '')
-
- mod_obj = pooler.get_pool(cr.dbname).get('ir.model.data')
- result = mod_obj._get_id(cr, uid, 'account', 'view_account_move_line_filter')
- id = mod_obj.read(cr, uid, result, ['res_id'])
- return {
- 'domain': "[('journal_id','=',%d), ('period_id','=',%d)]" % (form['journal_id'],form['period_id']),
- 'name': name,
- 'view_type': 'form',
- 'view_mode': 'tree,form',
- 'res_model': 'account.move.line',
- 'view_id': view_res,
- 'context': "{'journal_id':%d, 'period_id':%d}" % (form['journal_id'],form['period_id']),
- 'type': 'ir.actions.act_window',
- 'search_view_id': id['res_id']
- }
-
-class wiz_journal(wizard.interface):
- states = {
- 'init': {
- 'actions': [_period_get],
- 'result': {'type': 'form', 'arch':_journal_form, 'fields':_journal_fields, 'state':[('end','Cancel'),('open','Open Journal')]}
- },
- 'open': {
- 'actions': [],
- 'result': {'type': 'action', 'action': _action_open_window, 'state':'end'}
- }
- }
-wiz_journal('account.move.journal')
-
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-
diff --git a/addons/account/wizard/wizard_period_close.py b/addons/account/wizard/wizard_period_close.py
deleted file mode 100644
index d6ba73683f2..00000000000
--- a/addons/account/wizard/wizard_period_close.py
+++ /dev/null
@@ -1,57 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-# OpenERP, Open Source Management Solution
-# Copyright (C) 2004-2010 Tiny SPRL ().
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see .
-#
-##############################################################################
-
-import wizard
-
-_transaction_form = '''
-'''
-
-_transaction_fields = {
- 'sure': {'string':'Check this box', 'type':'boolean'},
-}
-
-def _data_save(self, cr, uid, data, context):
- mode = 'done'
- if data['form']['sure']:
- for id in data['ids']:
- cr.execute('update account_journal_period set state=%s where period_id=%s', (mode, id))
- cr.execute('update account_period set state=%s where id=%s', (mode, id))
- return {}
-
-class wiz_journal_close(wizard.interface):
- states = {
- 'init': {
- 'actions': [],
- 'result': {'type': 'form', 'arch':_transaction_form, 'fields':_transaction_fields, 'state':[('end','Cancel'),('close','Close Period')]}
- },
- 'close': {
- 'actions': [_data_save],
- 'result': {'type': 'state', 'state':'end'}
- }
- }
-wiz_journal_close('account.period.close')
-
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-
diff --git a/addons/account/wizard/wizard_reconcile_select.py b/addons/account/wizard/wizard_reconcile_select.py
deleted file mode 100644
index 594020debd4..00000000000
--- a/addons/account/wizard/wizard_reconcile_select.py
+++ /dev/null
@@ -1,61 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-# OpenERP, Open Source Management Solution
-# Copyright (C) 2004-2010 Tiny SPRL ().
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see .
-#
-##############################################################################
-
-import wizard
-from tools.translate import _
-
-
-_journal_form = '''
-''' % ('Reconciliation',)
-
-_journal_fields = {
- 'account_id': {'string':'Account', 'type':'many2one', 'relation':'account.account','domain': [('reconcile','=',1)], 'required':True},
-}
-
-def _action_open_window(self, cr, uid, data, context):
- return {
- 'domain': "[('account_id','=',%d),('reconcile_id','=',False),('state','<>','draft')]" % data['form']['account_id'],
- 'name': _('Reconciliation'),
- 'view_type': 'form',
- 'view_mode': 'tree,form',
- 'view_id': False,
- 'res_model': 'account.move.line',
- 'type': 'ir.actions.act_window'
- }
-
-class wiz_rec_select(wizard.interface):
- states = {
- 'init': {
- 'actions': [],
- 'result': {'type': 'form', 'arch':_journal_form, 'fields':_journal_fields, 'state':[('end','Cancel'),('open','Open for reconciliation')]}
- },
- 'open': {
- 'actions': [],
- 'result': {'type': 'action', 'action': _action_open_window, 'state':'end'}
- }
- }
-wiz_rec_select('account.move.line.reconcile.select')
-
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-
diff --git a/addons/account/wizard/wizard_refund.py b/addons/account/wizard/wizard_refund.py
deleted file mode 100644
index 42526f3cc0a..00000000000
--- a/addons/account/wizard/wizard_refund.py
+++ /dev/null
@@ -1,226 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-# OpenERP, Open Source Management Solution
-# Copyright (C) 2004-2010 Tiny SPRL ().
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see .
-#
-##############################################################################
-
-import wizard
-import pooler
-import osv
-import netsvc
-import time
-from tools.translate import _
-
-sur_form = '''
-'''
-
-sur_fields = {
- 'date': {'string':'Operation date','type':'date', 'required':'False'},
- 'period':{'string': 'Force period', 'type': 'many2one',
- 'relation': 'account.period', 'required': False},
- 'description':{'string':'Description', 'type':'char', 'required':'True'},
- }
-
-
-class wiz_refund(wizard.interface):
-
- def _invoice_refund(self, cr, uid, data, context):
- return self._compute_refund(cr, uid, data, 'refund', context)
-
- def _invoice_cancel(self, cr, uid, data, context):
- return self._compute_refund(cr, uid, data, 'cancel', context)
-
- def _invoice_modify(self, cr, uid, data, context):
- return self._compute_refund(cr, uid, data, 'modify', context)
-
- def _compute_refund(self, cr, uid, data, mode, context):
- form = data['form']
- pool = pooler.get_pool(cr.dbname)
- reconcile_obj = pool.get('account.move.reconcile')
- account_m_line_obj = pool.get('account.move.line')
- created_inv = []
- date = False
- period = False
- description = False
- for inv in pool.get('account.invoice').browse(cr, uid, data['ids']):
- if inv.state in ['draft', 'proforma2', 'cancel']:
- raise wizard.except_wizard(_('Error !'), _('Can not %s draft/proforma/cancel invoice.') % (mode))
- if form['period'] :
- period = form['period']
- else:
- period = inv.period_id and inv.period_id.id or False
-
- if form['date'] :
- date = form['date']
- if not form['period'] :
- cr.execute("select name from ir_model_fields where model='account.period' and name='company_id'")
- result_query = cr.fetchone()
- if result_query:
- #in multi company mode
- cr.execute("""SELECT id
- from account_period where date('%s')
- between date_start AND date_stop and company_id = %s limit 1 """,
- (form['date'],pool.get('res.users').browse(cr,uid,uid).company_id.id,))
- else:
- #in mono company mode
- cr.execute("""SELECT id
- from account_period where date('%s')
- between date_start AND date_stop limit 1 """,
- (form['date'],))
- res = cr.fetchone()
- if res:
- period = res[0]
- else:
- date = inv.date_invoice
-
- if form['description'] :
- description = form['description']
- else:
- description = inv.name
-
- if not period:
- raise wizard.except_wizard(_('Data Insufficient !'), _('No Period found on Invoice!'))
-
- refund_id = pool.get('account.invoice').refund(cr, uid, [inv.id],date, period, description)
- refund = pool.get('account.invoice').browse(cr, uid, refund_id[0])
- # we compute due date
- #!!!due date = date inv date on formdate
- pool.get('account.invoice').write(cr, uid, [refund.id],{'date_due':date,'check_total':inv.check_total})
- # to make the taxes calculated
- pool.get('account.invoice').button_compute(cr, uid, refund_id)
-
- created_inv.append(refund_id[0])
- #if inv is paid we unreconcile
- if mode in ('cancel','modify'):
- movelines = inv.move_id.line_id
- #we unreconcile the lines
- to_reconcile_ids = {}
- for line in movelines :
- #if the account of the line is the as the one in the invoice
- #we reconcile
- if line.account_id.id == inv.account_id.id :
- to_reconcile_ids[line.account_id.id] =[line.id]
- if type(line.reconcile_id) != osv.orm.browse_null :
- reconcile_obj.unlink(cr,uid, line.reconcile_id.id)
- #we advance the workflow of the refund to open
- wf_service = netsvc.LocalService('workflow')
- wf_service.trg_validate(uid, 'account.invoice', refund.id, 'invoice_open', cr)
- #we reload the browse record
- refund = pool.get('account.invoice').browse(cr, uid, refund_id[0])
- #we match the line to reconcile
- for tmpline in refund.move_id.line_id :
- if tmpline.account_id.id == inv.account_id.id :
- to_reconcile_ids[tmpline.account_id.id].append(tmpline.id)
- 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_acc_id=inv.account_id.id
- )
- #we create a new invoice that is the copy of the original
- if mode == 'modify' :
- invoice = pool.get('account.invoice').read(cr, uid, [inv.id],
- ['name', 'type', 'number', 'reference',
- 'comment', 'date_due', 'partner_id', 'address_contact_id',
- 'address_invoice_id', 'partner_insite','partner_contact',
- 'partner_ref', 'payment_term', 'account_id', 'currency_id',
- 'invoice_line', 'tax_line', 'journal_id','period_id'
- ]
- )
- invoice = invoice[0]
- del invoice['id']
- invoice_lines = pool.get('account.invoice.line').read(cr, uid, invoice['invoice_line'])
- invoice_lines = pool.get('account.invoice')._refund_cleanup_lines(cr, uid, invoice_lines)
- tax_lines = pool.get('account.invoice.tax').read(
- cr, uid, invoice['tax_line'])
- tax_lines = pool.get('account.invoice')._refund_cleanup_lines(cr, uid, tax_lines)
-
- invoice.update({
- 'type': inv.type,
- 'date_invoice': date,
- 'state': 'draft',
- 'number': False,
- 'invoice_line': invoice_lines,
- 'tax_line': tax_lines,
- 'period_id': period,
- 'name':description
- })
-
- #take the id part of the tuple returned for many2one fields
- for field in ('address_contact_id', 'address_invoice_id', 'partner_id',
- 'account_id', 'currency_id', 'payment_term', 'journal_id'):
- invoice[field] = invoice[field] and invoice[field][0]
-
- # create the new invoice
- inv_id = pool.get('account.invoice').create(cr, uid, invoice,{})
- # we compute due date
- if inv.payment_term.id:
- data = pool.get('account.invoice').onchange_payment_term_date_invoice(cr, uid, [inv_id],inv.payment_term.id,date)
- if 'value' in data and data['value']:
- pool.get('account.invoice').write(cr, uid, [inv_id],data['value'])
- created_inv.append(inv_id)
-
- #we get the view id
- mod_obj = pool.get('ir.model.data')
- act_obj = pool.get('ir.actions.act_window')
- if inv.type == 'out_invoice':
- xml_id = 'action_invoice_tree5'
- elif inv.type == 'in_invoice':
- xml_id = 'action_invoice_tree8'
- elif type == 'out_refund':
- xml_id = 'action_invoice_tree10'
- else:
- xml_id = 'action_invoice_tree12'
- #we get the model
- result = mod_obj._get_id(cr, uid, 'account', xml_id)
- id = mod_obj.read(cr, uid, result, ['res_id'])['res_id']
- # we read the act window
- result = act_obj.read(cr, uid, id)
- result['res_id'] = created_inv
-
- return result
-
- states = {
- 'init': {
- 'actions': [],
- 'result': {'type':'form', 'arch':sur_form, 'fields':sur_fields, 'state':[('end','Cancel'),('refund','Refund Invoice'),('cancel_invoice','Cancel Invoice'),('modify_invoice','Modify Invoice')]}
- },
- 'refund': {
- 'actions': [],
- 'result': {'type':'action', 'action':_invoice_refund, 'state':'end'},
- },
- 'cancel_invoice': {
- 'actions': [],
- 'result': {'type':'action', 'action':_invoice_cancel, 'state':'end'},
- },
- 'modify_invoice': {
- 'actions': [],
- 'result': {'type':'action', 'action':_invoice_modify, 'state':'end'},
- },
-
- }
-wiz_refund('account.invoice.refund')
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-