[ADD] account_payment: Payment poplulate statement=> osv memory (ref:PSI)

bzr revid: mra@tinyerp.com-20100503073459-bc79m7d5jqwf9318
This commit is contained in:
mra (Open ERP) 2010-05-03 13:04:59 +05:30
parent 85a81de438
commit 8ac697eccc
6 changed files with 173 additions and 127 deletions

View File

@ -39,6 +39,7 @@
'security/account_payment_security.xml',
'security/ir.model.access.csv',
'wizard/account_payment_pay_view.xml',
'wizard/account_payment_populate_statement_view.xml',
'wizard/account_payment_create_order_view.xml',
'payment_view.xml',
'payment_workflow.xml',

View File

@ -2,7 +2,6 @@
<openerp>
<data>
<wizard id="wizard_populate_statement" menu="False" model="account.bank.statement" name="populate_statement" string="Populate Statement with Payment lines"/>
<!-- View used in the wizard -->
<record id="view_move_line_form" model="ir.ui.view">
<field name="name">account.move.line.form.inherit</field>
@ -300,7 +299,7 @@
<field name="inherit_id" ref="account.view_bank_statement_form"/>
<field name="arch" type="xml">
<group colspan="2" col="3" position="inside">
<button name="%(wizard_populate_statement)d" string="Import payment lines" type="action" icon="gtk-open"/>
<button name="%(action_account_populate_statement_confirm)d" string="Import payment lines" type="action" icon="gtk-open"/>
</group>
</field>
</record>

View File

@ -18,10 +18,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import account_payment_order
import account_payment_populate_statement
import account_payment_pay
import wizard_populate_statement
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,110 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from lxml import etree
from osv import osv, fields
class account_payment_populate_statement(osv.osv_memory):
_name = "account.payment.populate.statement"
_description = "Account Payment Populate Statement"
_columns = {
'lines': fields.many2many('payment.line', 'payment_line_rel_', 'payment_id', 'line_id', 'Payment Lines')
}
def search_entries(self, cr, uid, ids, context=None):
line_obj = self.pool.get('payment.line')
statement_obj = self.pool.get('account.bank.statement')
mod_obj = self.pool.get('ir.model.data')
data = self.read(cr, uid, ids, [], context=context)[0]
statement = statement_obj.browse(cr, uid, context['active_id'], context=context)
line_ids = line_obj.search(cr, uid, [
('move_line_id.reconcile_id', '=', False),
('order_id.mode.journal.id', '=', statement.journal_id.id)])
line_ids.extend(line_obj.search(cr, uid, [
('move_line_id.reconcile_id', '=', False),
('order_id.mode', '=', False)]))
context.update({'line_ids': line_ids})
model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','account_payment_populate_statement_view')], context=context)
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
return {
'name': ('Entrie Lines'),
'context': context,
'view_type': 'form',
'view_mode': 'form',
'res_model': 'account.payment.populate.statement',
'views': [(resource_id,'form')],
'type': 'ir.actions.act_window',
'target': 'new',
}
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
res = super(account_payment_populate_statement, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=False)
if context and 'line_ids' in context:
view_obj = etree.XML(res['arch'])
child = view_obj.getchildren()[0]
domain = '[("id", "in", '+ str(context['line_ids'])+')]'
field = etree.Element('field', attrib={'domain': domain, 'name':'lines', 'colspan':'4', 'height':'300', 'width':'800', 'nolabel':"1"})
child.addprevious(field)
res['arch'] = etree.tostring(view_obj)
return res
def populate_statement(self, cr, uid, ids, context=None):
line_obj = self.pool.get('payment.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')
if context is None:
context = {}
data = self.read(cr, uid, ids, [])[0]
line_ids = data['lines']
if not line_ids:
return {}
statement = statement_obj.browse(cr, uid, context['active_id'], context=context)
for line in line_obj.browse(cr, uid, line_ids, context=context):
ctx = context.copy()
ctx['date'] = line.ml_maturity_date # was value_date earlier,but this field exists no more now
amount = currency_obj.compute(cr, uid, line.currency.id,
statement.currency.id, line.amount_currency, context=ctx)
if line.move_line_id:
reconcile_id = statement_reconcile_obj.create(cr, uid, {
'line_ids': [(6, 0, [line.move_line_id.id])]
}, context=context)
statement_line_obj.create(cr, uid, {
'name': line.order_id.reference or '?',
'amount': - amount,
'type': 'supplier',
'partner_id': line.partner_id.id,
'account_id': line.move_line_id.account_id.id,
'statement_id': statement.id,
'ref': line.communication,
'reconcile_id': reconcile_id,
}, context=context)
return {'type' : 'ir.actions.act_window_close'}
account_payment_populate_statement()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="account_populate_statement_confirm_view" model="ir.ui.view">
<field name="name">Payment Populate statement</field>
<field name="model">account.payment.populate.statement</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Populate Statement:">
<label string="Are your sure to import Payment Lines!"/>
<group colspan="4" col="6">
<separator colspan="6"/>
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
<button name="search_entries" string="Yes" type="object" icon="gtk-ok"/>
</group>
</form>
</field>
</record>
<record id="action_account_populate_statement_confirm" model="ir.actions.act_window">
<field name="name">Payment Populate statement</field>
<field name="res_model">account.payment.populate.statement</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="account_populate_statement_confirm_view"/>
<field name="context">{'record_id':active_id}</field>
<field name="target">new</field>
</record>
<record id="account_payment_populate_statement_view" model="ir.ui.view">
<field name="name">Payment Populate statement</field>
<field name="model">account.payment.populate.statement</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Populate Statement:">
<group colspan="4" col="6">
<separator colspan="6"/>
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
<button name="populate_statement" string="ADD" type="object" icon="gtk-ok"/>
</group>
</form>
</field>
</record>
<record id="action_account_payment_populate_statement" model="ir.actions.act_window">
<field name="name">Payment Populate statement</field>
<field name="res_model">account.payment.populate.statement</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="account_payment_populate_statement_view"/>
<field name="context">{'record_id':active_id}</field>
<field name="target">new</field>
</record>
</data>
</openerp>

View File

@ -1,121 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
import wizard
import pooler
from tools.misc import UpdateableStr
FORM = UpdateableStr()
FIELDS = {
'lines': {'string': 'Payment Lines', 'type': 'many2many',
'relation': 'payment.line'},
}
def _search_entries(obj, cursor, user, data, context):
pool = pooler.get_pool(cursor.dbname)
line_obj = pool.get('payment.line')
statement_obj = pool.get('account.bank.statement')
statement = statement_obj.browse(cursor, user, data['id'], context=context)
line_ids = line_obj.search(cursor, user, [
('move_line_id.reconcile_id', '=', False),
('order_id.mode.journal.id', '=', statement.journal_id.id)])
line_ids.extend(line_obj.search(cursor, user, [
('move_line_id.reconcile_id', '=', False),
('order_id.mode', '=', False)]))
FORM.string = '''<?xml version="1.0"?>
<form string="Populate Statement:">
<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]
if not line_ids:
return {}
pool = pooler.get_pool(cursor.dbname)
line_obj = pool.get('payment.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 line in line_obj.browse(cursor, user, line_ids, context=context):
ctx = context.copy()
ctx['date'] = line.ml_maturity_date # was value_date earlier,but this field exists no more now
amount = currency_obj.compute(cursor, user, line.currency.id,
statement.currency.id, line.amount_currency, context=ctx)
if line.move_line_id:
reconcile_id = statement_reconcile_obj.create(cursor, user, {
'line_ids': [(6, 0, [line.move_line_id.id])]
}, context=context)
statement_line_obj.create(cursor, user, {
'name': line.order_id.reference or '?',
'amount': - amount,
'type': 'supplier',
'partner_id': line.partner_id.id,
'account_id': line.move_line_id.account_id.id,
'statement_id': statement.id,
'ref': line.communication,
'reconcile_id': reconcile_id,
}, context=context)
return {}
class PopulateStatement(wizard.interface):
"""
Populate the current statement with selected payement lines
"""
states = {
'init': {
'actions': [_search_entries],
'result': {
'type': 'form',
'arch': FORM,
'fields': FIELDS,
'state': [
('end', '_Cancel'),
('add', '_Add', '', True)
]
},
},
'add': {
'actions': [],
'result': {
'type': 'action',
'action': _populate_statement,
'state': 'end'
},
},
}
PopulateStatement('populate_statement')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: