[MOD,ADD] Account : wizard account_statement_from_invoice is changed with osv memory wizard.
bzr revid: vir@tinyerp.com-20100415131709-phx8mytmtodsh7ge
This commit is contained in:
parent
b1cd4c9456
commit
593e1b9194
|
@ -66,6 +66,7 @@ module named account_voucherss
|
|||
'wizard/account_journal_select_view.xml',
|
||||
'wizard/account_change_currency_view.xml',
|
||||
'wizard/account_validate_move_view.xml',
|
||||
'wizard/account_statement_from_invoice_view.xml',
|
||||
'project/wizard/project_account_analytic_line_view.xml',
|
||||
'account_view.xml',
|
||||
'account_end_fy.xml',
|
||||
|
|
|
@ -27,6 +27,26 @@ from tools.misc import currency
|
|||
from tools.translate import _
|
||||
|
||||
class account_bank_statement(osv.osv):
|
||||
|
||||
def button_import_invoice(self, cr, uid, ids, context=None):
|
||||
mod_obj = self.pool.get('ir.model.data')
|
||||
if context is None:
|
||||
context = {}
|
||||
model_data_ids = mod_obj.search(cr,uid,[('model','=','ir.ui.view'),('name','=','view_account_statement_from_invoice')], context=context)
|
||||
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
|
||||
context.update({'statement_id': ids[0]})
|
||||
return {
|
||||
'name': _('Import Invoice'),
|
||||
'context': context,
|
||||
'view_type': 'form',
|
||||
'view_mode': 'tree,form',
|
||||
'res_model': 'account.statement.from.invoice',
|
||||
'views': [(resource_id,'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
'nodestroy': True
|
||||
}
|
||||
|
||||
def _default_journal_id(self, cr, uid, context={}):
|
||||
if context.get('journal_id', False):
|
||||
return context['journal_id']
|
||||
|
@ -352,7 +372,7 @@ class account_bank_statement(osv.osv):
|
|||
raise osv.except_osv(_('Invalid action !'), _('Cannot delete bank statement which are already confirmed !'))
|
||||
osv.osv.unlink(self, cr, uid, unlink_ids, context=context)
|
||||
return True
|
||||
|
||||
|
||||
account_bank_statement()
|
||||
|
||||
|
||||
|
|
|
@ -340,8 +340,9 @@
|
|||
<field name="currency"/>
|
||||
<field name="period_id" select="2"/>
|
||||
<group colspan="2" col="3">
|
||||
<button name="%(wizard_populate_statement_from_inv)d"
|
||||
string="Import Invoice" type="action" attrs="{'invisible':[('state','=','confirm')]}" icon="gtk-open"/>
|
||||
<!-- <button name="%(action_view_account_statement_from_invoice)d"-->
|
||||
<!-- string="Import Invoice" type="action" attrs="{'invisible':[('state','=','confirm')]}" icon="gtk-open"/>-->
|
||||
<button name="button_import_invoice" string="Import Invoice" attrs="{'invisible':[('state','=','confirm')]}" type="object" icon="gtk-apply"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<field name="balance_start"/>
|
||||
|
|
|
@ -39,12 +39,12 @@
|
|||
|
||||
<!-- Import entry in statement -->
|
||||
|
||||
<wizard
|
||||
string="Import invoices"
|
||||
model="account.bank.statement"
|
||||
name="populate_statement_from_inv"
|
||||
menu="False"
|
||||
id="wizard_populate_statement_from_inv"/>
|
||||
<!-- <wizard-->
|
||||
<!-- string="Import invoices"-->
|
||||
<!-- model="account.bank.statement"-->
|
||||
<!-- name="populate_statement_from_inv"-->
|
||||
<!-- menu="False"-->
|
||||
<!-- id="wizard_populate_statement_from_inv"/>-->
|
||||
|
||||
<!-- manual reconcile -->
|
||||
<wizard id="wizard_reconcile" model="account.move.line" name="account.move.line.reconcile" string="Reconcile Entries"/>
|
||||
|
|
|
@ -52,7 +52,7 @@ import wizard_use_model
|
|||
|
||||
import account_state_open
|
||||
|
||||
import wizard_statement_from_invoice
|
||||
import account_statement_from_invoice
|
||||
import account_print_journal
|
||||
import account_central_journal
|
||||
import account_general_journal
|
||||
|
|
|
@ -0,0 +1,143 @@
|
|||
import time
|
||||
|
||||
from osv import fields, osv
|
||||
from tools.translate import _
|
||||
|
||||
class account_statement_from_invoice_lines(osv.osv_memory):
|
||||
"""
|
||||
Generate Entries by Statement from Invoices
|
||||
"""
|
||||
_name = "account.statement.from.invoice.lines"
|
||||
_description = "Entries by Statement from Invoices"
|
||||
_columns = {
|
||||
'line_ids': fields.many2many('account.move.line', 'account_move_line_relation', 'move_id', 'line_id', 'Invoices'),
|
||||
}
|
||||
|
||||
def populate_statement(self, cr, uid, ids, context=None):
|
||||
|
||||
line_obj = self.pool.get('account.move.line')
|
||||
statement_obj = self.pool.get('account.bank.statement')
|
||||
statement_line_obj = self.pool.get('account.bank.statement.line')
|
||||
currency_obj = self.pool.get('res.currency')
|
||||
statement_reconcile_obj = self.pool.get('account.bank.statement.reconcile')
|
||||
|
||||
data = self.read(cr, uid, ids,context=context)[0]
|
||||
line_ids = data['line_ids']
|
||||
line_date = time.strftime('%Y-%m-%d')
|
||||
|
||||
if not line_ids:
|
||||
return {}
|
||||
statement_id = 'statement_id' in context and context['statement_id']
|
||||
statement = statement_obj.browse(cr, uid, statement_id, context=context)
|
||||
# for each selected move lines
|
||||
for line in line_obj.browse(cr, uid, line_ids, context=context):
|
||||
ctx = context.copy()
|
||||
# take the date for computation of currency => use payment date
|
||||
# if line.date_maturity:
|
||||
# ctx['date'] = line.date_maturity
|
||||
# else:
|
||||
ctx['date'] = line_date
|
||||
amount = 0.0
|
||||
if line.amount_currency:
|
||||
amount = currency_obj.compute(cr, uid, line.currency_id.id,
|
||||
statement.currency.id, line.amount_currency, context=ctx)
|
||||
else:
|
||||
if line.debit > 0:
|
||||
amount=line.debit
|
||||
elif line.credit > 0:
|
||||
amount=-line.credit
|
||||
reconcile_id = statement_reconcile_obj.create(cr, uid, {
|
||||
'line_ids': [(6, 0, [line.id])]
|
||||
}, context=context)
|
||||
if line.journal_id.type == 'sale':
|
||||
type = 'customer'
|
||||
elif line.journal_id.type == 'purchase':
|
||||
type = 'supplier'
|
||||
else:
|
||||
type = 'general'
|
||||
statement_line_obj.create(cr, uid, {
|
||||
'name': line.name or '?',
|
||||
'amount': amount,
|
||||
'type': type,
|
||||
'partner_id': line.partner_id.id,
|
||||
'account_id': line.account_id.id,
|
||||
'statement_id': statement_id,
|
||||
'ref': line.ref,
|
||||
'reconcile_id': reconcile_id,
|
||||
'date': time.strftime('%Y-%m-%d'), #time.strftime('%Y-%m-%d'), #line.date_maturity or,
|
||||
}, context=context)
|
||||
return {}
|
||||
|
||||
account_statement_from_invoice_lines()
|
||||
|
||||
class account_statement_from_invoice(osv.osv_memory):
|
||||
"""
|
||||
Generate Entries by Statement from Invoices
|
||||
"""
|
||||
_name = "account.statement.from.invoice"
|
||||
_description = "Entries by Statement from Invoices"
|
||||
_columns = {
|
||||
'date': fields.date('Date payment',required=True),
|
||||
'journal_ids': fields.many2many('account.journal','account_journal_relation','account_id','journal_id','Journal'),
|
||||
'line_ids': fields.many2many('account.move.line','account_move_line_relation','move_id','line_id','Invoices'),
|
||||
}
|
||||
_defaults = {
|
||||
'date':lambda *a: time.strftime('%Y-%m-%d'),
|
||||
}
|
||||
|
||||
def search_invoices(self, cr, uid, ids, context=None):
|
||||
|
||||
line_obj = self.pool.get('account.move.line')
|
||||
statement_obj = self.pool.get('account.bank.statement')
|
||||
journal_obj = self.pool.get('account.journal')
|
||||
mod_obj = self.pool.get('ir.model.data')
|
||||
statement_id = 'statement_id' in context and context['statement_id']
|
||||
|
||||
data = self.read(cr, uid, ids,context=context)[0]
|
||||
statement = statement_obj.browse(cr, uid, statement_id, context=context)
|
||||
args_move_line = []
|
||||
repeated_move_line_ids = []
|
||||
# Creating a group that is unique for importing move lines(move lines, once imported into statement lines, should not appear again)
|
||||
for st_line in statement.line_ids:
|
||||
args_move_line = []
|
||||
args_move_line.append(('name','=', st_line.name))
|
||||
args_move_line.append(('ref','=',st_line.ref))
|
||||
if st_line.partner_id:
|
||||
args_move_line.append(('partner_id','=',st_line.partner_id.id))
|
||||
args_move_line.append(('account_id','=',st_line.account_id.id))
|
||||
|
||||
move_line_id = line_obj.search(cr, uid, args_move_line,context=context)
|
||||
if move_line_id:
|
||||
repeated_move_line_ids += move_line_id
|
||||
|
||||
journal_ids = data['journal_ids']
|
||||
if journal_ids == []:
|
||||
journal_ids = journal_obj.search(cr, uid, [('type', 'in', ('sale','cash','purchase'))], context=context)
|
||||
|
||||
args = [
|
||||
('reconcile_id', '=', False),
|
||||
('journal_id', 'in', journal_ids),
|
||||
('account_id.reconcile', '=', True)]
|
||||
|
||||
if repeated_move_line_ids:
|
||||
args.append(('id','not in',repeated_move_line_ids))
|
||||
|
||||
line_ids = line_obj.search(cr, uid, args,
|
||||
#order='date DESC, id DESC', #doesn't work
|
||||
context=context)
|
||||
model_data_ids = mod_obj.search(cr,uid,[('model','=','ir.ui.view'),('name','=','view_account_statement_from_invoice_lines')], context=context)
|
||||
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
|
||||
return {
|
||||
'domain': "[('id','in', ["+','.join([str(x) for x in line_ids])+"])]",
|
||||
'name': _('Import Entries'),
|
||||
'context': context,
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'account.statement.from.invoice.lines',
|
||||
'views': [(resource_id,'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
account_statement_from_invoice()
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -0,0 +1,61 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_account_statement_from_invoice" model="ir.ui.view">
|
||||
<field name="name">account.statement.from.invoice.form</field>
|
||||
<field name="model">account.statement.from.invoice</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Import Invoices in Statement">
|
||||
<group colspan="4" >
|
||||
<field name="date"/>
|
||||
<newline/>
|
||||
<field name="journal_ids" domain="[('type','in',['sale','purchase','cash'])]"/>
|
||||
</group>
|
||||
<group colspan="4" col="6">
|
||||
<label string ="" colspan="2"/>
|
||||
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
|
||||
<button icon="gtk-execute" string="Go" name="search_invoices" type="object"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_view_account_statement_from_invoice" model="ir.actions.act_window">
|
||||
<field name="name">Import Invoices in Statement</field>
|
||||
<field name="res_model">account.statement.from.invoice</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="view_account_statement_from_invoice"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<record id="view_account_statement_from_invoice_lines" model="ir.ui.view">
|
||||
<field name="name">account.statement.from.invoice.lines.form</field>
|
||||
<field name="model">account.statement.from.invoice.lines</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Import Entries">
|
||||
<group colspan="4" >
|
||||
<field name="line_ids" />
|
||||
</group>
|
||||
<group colspan="4" col="6">
|
||||
<label string ="" colspan="2"/>
|
||||
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
|
||||
<button icon="gtk-execute" string="Ok" name="populate_statement" type="object"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record id="action_view_account_statement_from_invoice_lines" model="ir.actions.act_window">
|
||||
<field name="name">Import Entries</field>
|
||||
<field name="res_model">account.statement.from.invoice.lines</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="view_account_statement_from_invoice_lines"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -1,195 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Copyright (c) 2008 Camptocamp SA All Rights Reserved. (JGG)
|
||||
#
|
||||
# WARNING: This program as such is intended to be used by professional
|
||||
# programmers who take the whole responsability of assessing all potential
|
||||
# consequences resulting from its eventual inadequacies and bugs
|
||||
# End users who are looking for a ready-to-use solution with commercial
|
||||
# garantees and support are strongly adviced to contract a Free Software
|
||||
# Service Company
|
||||
#
|
||||
# This program is Free Software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# 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 General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import wizard
|
||||
import pooler
|
||||
from tools.misc import UpdateableStr
|
||||
import time
|
||||
|
||||
FORM = UpdateableStr()
|
||||
|
||||
FIELDS = {
|
||||
'lines': {'string': 'Invoices', 'type': 'many2many',
|
||||
'relation': 'account.move.line'},
|
||||
|
||||
}
|
||||
|
||||
START_FIELD = {
|
||||
'date': {'string': 'Date payment', 'type': 'date','required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
|
||||
'journal_id': {'string': 'Journal', 'type': 'many2many', 'relation': 'account.journal', 'domain': '[("type","in",["sale","purchase","cash"])]', 'help': 'This field allows you to choose the accounting journals you want for filtering the invoices. If you left this field empty, it will search on all sale, purchase and cash journals.'},
|
||||
}
|
||||
|
||||
START_FORM = '''<?xml version="1.0"?>
|
||||
<form string="Import Invoices in Statement">
|
||||
<label string="Choose Journal and Payment Date" colspan="4"/>
|
||||
<field name="date"/>
|
||||
<field name="journal_id" colspan="4"/>
|
||||
</form>'''
|
||||
|
||||
def _search_invoices(obj, cr, uid, data, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
line_obj = pool.get('account.move.line')
|
||||
statement_obj = pool.get('account.bank.statement')
|
||||
journal_obj = pool.get('account.journal')
|
||||
|
||||
statement = statement_obj.browse(cr, uid, data['id'], context=context)
|
||||
args_move_line = []
|
||||
repeated_move_line_ids = []
|
||||
# Creating a group that is unique for importing move lines(move lines, once imported into statement lines, should not appear again)
|
||||
for st_line in statement.line_ids:
|
||||
args_move_line = []
|
||||
args_move_line.append(('name','=', st_line.name))
|
||||
args_move_line.append(('ref','=',st_line.ref))
|
||||
if st_line.partner_id:
|
||||
args_move_line.append(('partner_id','=',st_line.partner_id.id))
|
||||
args_move_line.append(('account_id','=',st_line.account_id.id))
|
||||
|
||||
move_line_id = line_obj.search(cr, uid, args_move_line,context=context)
|
||||
if move_line_id:
|
||||
repeated_move_line_ids += move_line_id
|
||||
|
||||
journal_ids = data['form']['journal_id'][0][2]
|
||||
|
||||
if journal_ids == []:
|
||||
journal_ids = journal_obj.search(cr, uid, [('type', 'in', ('sale','cash','purchase'))], context=context)
|
||||
|
||||
args = [
|
||||
('reconcile_id', '=', False),
|
||||
('journal_id', 'in', journal_ids),
|
||||
('account_id.reconcile', '=', True)]
|
||||
|
||||
if repeated_move_line_ids:
|
||||
args.append(('id','not in',repeated_move_line_ids))
|
||||
|
||||
line_ids = line_obj.search(cr, uid, args,
|
||||
#order='date DESC, id DESC', #doesn't work
|
||||
context=context)
|
||||
|
||||
FORM.string = '''<?xml version="1.0"?>
|
||||
<form string="Import Entries">
|
||||
<field name="lines" colspan="4" height="300" width="800" nolabel="1"
|
||||
domain="[('id', 'in', [%s])]"/>
|
||||
</form>''' % (','.join([str(x) for x in line_ids]))
|
||||
return {}
|
||||
|
||||
def _populate_statement(obj, cursor, user, data, context):
|
||||
line_ids = data['form']['lines'][0][2]
|
||||
line_date=data['form']['date']
|
||||
if not line_ids:
|
||||
return {}
|
||||
|
||||
pool = pooler.get_pool(cursor.dbname)
|
||||
line_obj = pool.get('account.move.line')
|
||||
statement_obj = pool.get('account.bank.statement')
|
||||
statement_line_obj = pool.get('account.bank.statement.line')
|
||||
currency_obj = pool.get('res.currency')
|
||||
statement_reconcile_obj = pool.get('account.bank.statement.reconcile')
|
||||
|
||||
statement = statement_obj.browse(cursor, user, data['id'], context=context)
|
||||
# for each selected move lines
|
||||
for line in line_obj.browse(cursor, user, line_ids, context=context):
|
||||
ctx = context.copy()
|
||||
# take the date for computation of currency => use payment date
|
||||
# if line.date_maturity:
|
||||
# ctx['date'] = line.date_maturity
|
||||
# else:
|
||||
ctx['date'] = line_date
|
||||
amount = 0.0
|
||||
if line.amount_currency:
|
||||
amount = currency_obj.compute(cursor, user, line.currency_id.id,
|
||||
statement.currency.id, line.amount_currency, context=ctx)
|
||||
else:
|
||||
if line.debit > 0:
|
||||
amount=line.debit
|
||||
elif line.credit > 0:
|
||||
amount=-line.credit
|
||||
reconcile_id = statement_reconcile_obj.create(cursor, user, {
|
||||
'line_ids': [(6, 0, [line.id])]
|
||||
}, context=context)
|
||||
if line.journal_id.type == 'sale':
|
||||
type = 'customer'
|
||||
elif line.journal_id.type == 'purchase':
|
||||
type = 'supplier'
|
||||
else:
|
||||
type = 'general'
|
||||
|
||||
statement_line_obj.create(cursor, user, {
|
||||
'name': line.name or '?',
|
||||
'amount': amount,
|
||||
'type': type,
|
||||
'partner_id': line.partner_id.id,
|
||||
'account_id': line.account_id.id,
|
||||
'statement_id': statement.id,
|
||||
'ref': line.ref,
|
||||
'reconcile_id': reconcile_id,
|
||||
'date':line_date, #time.strftime('%Y-%m-%d'), #line.date_maturity or,
|
||||
}, context=context)
|
||||
return {}
|
||||
|
||||
|
||||
class PopulateStatementFromInv(wizard.interface):
|
||||
"""
|
||||
Populate the current statement with selected invoices
|
||||
"""
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [],
|
||||
'result': {
|
||||
'type': 'form',
|
||||
'arch': START_FORM,
|
||||
'fields':START_FIELD,
|
||||
'state': [
|
||||
('end', '_Cancel'),
|
||||
('go', '_Go', '', True),
|
||||
]
|
||||
},
|
||||
},
|
||||
'go': {
|
||||
'actions': [_search_invoices],
|
||||
'result': {
|
||||
'type': 'form',
|
||||
'arch': FORM,
|
||||
'fields': FIELDS,
|
||||
'state': [
|
||||
('end', '_Cancel','', True, 'gtk-cancel'),
|
||||
('finish', 'O_k','', True, 'gtk-ok')
|
||||
]
|
||||
},
|
||||
},
|
||||
|
||||
'finish': {
|
||||
'actions': [],
|
||||
'result': {
|
||||
'type': 'action',
|
||||
'action': _populate_statement,
|
||||
'state': 'end'
|
||||
},
|
||||
},
|
||||
}
|
||||
PopulateStatementFromInv('populate_statement_from_inv')
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
Loading…
Reference in New Issue