[ADD] account_payment: Populate payments => osv memory
bzr revid: mra@tinyerp.com-20100430112741-yrq1tx23p6vyekuz
This commit is contained in:
parent
2c08059898
commit
e4a3054a53
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# OpenERP, Open Source Management Solution
|
# OpenERP, Open Source Management Solution
|
||||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||||
#
|
#
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
# GNU Affero General Public License for more details.
|
# GNU Affero General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
|
@ -39,11 +39,12 @@
|
||||||
'security/account_payment_security.xml',
|
'security/account_payment_security.xml',
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
'payment_wizard.xml',
|
'payment_wizard.xml',
|
||||||
|
'wizard/account_payment_create_order_view.xml',
|
||||||
'payment_view.xml',
|
'payment_view.xml',
|
||||||
'payment_workflow.xml',
|
'payment_workflow.xml',
|
||||||
'payment_sequence.xml',
|
'payment_sequence.xml',
|
||||||
'account_invoice_view.xml',
|
'account_invoice_view.xml',
|
||||||
'payment_report.xml'
|
'payment_report.xml',
|
||||||
],
|
],
|
||||||
'demo_xml': [],
|
'demo_xml': [],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
|
|
|
@ -107,7 +107,7 @@
|
||||||
<field name="date_prefered"/>
|
<field name="date_prefered"/>
|
||||||
<field name="date_planned" select="1"/>
|
<field name="date_planned" select="1"/>
|
||||||
<field name="user_id"/>
|
<field name="user_id"/>
|
||||||
<button colspan="2" name="%(wizard_populate_payment)d" string="Select Invoices to Pay" type="action" attrs="{'invisible':[('state','=','done')]}" icon="gtk-find"/>
|
<button colspan="2" name="%(action_create_payment_order)d" string="Select Invoices to Pay" type="action" attrs="{'invisible':[('state','=','done')]}" icon="gtk-find"/>
|
||||||
<field name="line_ids" colspan="4" widget="one2many_list" nolabel="1">
|
<field name="line_ids" colspan="4" widget="one2many_list" nolabel="1">
|
||||||
<form string="Payment Line">
|
<form string="Payment Line">
|
||||||
<notebook>
|
<notebook>
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<openerp>
|
<openerp>
|
||||||
<data>
|
<data>
|
||||||
<wizard id="wizard_populate_payment" menu="False" model="payment.order" name="populate_payment" string="Populate payment"/>
|
<!--<wizard id="wizard_populate_payment" menu="False" model="payment.order" name="populate_payment" string="Populate payment"/>-->
|
||||||
|
|
||||||
<wizard id="wizard_pay_payment" menu="False" model="payment.order" name="pay_payment" string="Pay"/>
|
<wizard id="wizard_pay_payment" menu="False" model="payment.order" name="pay_payment" string="Pay"/>
|
||||||
|
|
||||||
<wizard id="wizard_populate_statement" menu="False" model="account.bank.statement" name="populate_statement" string="Populate Statement with Payment lines"/>
|
<wizard id="wizard_populate_statement" menu="False" model="account.bank.statement" name="populate_statement" string="Populate Statement with Payment lines"/>
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
</openerp>
|
</openerp>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# OpenERP, Open Source Management Solution
|
# OpenERP, Open Source Management Solution
|
||||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||||
#
|
#
|
||||||
|
@ -15,11 +15,11 @@
|
||||||
# GNU Affero General Public License for more details.
|
# GNU Affero General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
import wizard_payment_order
|
import account_payment_order
|
||||||
import wizard_pay
|
import wizard_pay
|
||||||
import wizard_populate_statement
|
import wizard_populate_statement
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<record id="view_create_payment_order" model="ir.ui.view">
|
||||||
|
<field name="name">payment.order.create.form</field>
|
||||||
|
<field name="model">payment.order.create</field>
|
||||||
|
<field name="type">form</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form string="Search Payment lines">
|
||||||
|
<group col="4" colspan="6">
|
||||||
|
<field name="duedate" />
|
||||||
|
</group>
|
||||||
|
<separator colspan="4"/>
|
||||||
|
<group col="2" colspan="4">
|
||||||
|
<button special="cancel" string="Cancel" icon='gtk-cancel'/>
|
||||||
|
<button name="search_entries" string="Search" colspan="1" type="object" icon="gtk-execute"/>
|
||||||
|
</group>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="view_create_payment_order_lines" model="ir.ui.view">
|
||||||
|
<field name="name">payment.order.create.form</field>
|
||||||
|
<field name="model">payment.order.create</field>
|
||||||
|
<field name="type">form</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form string="Search Payment lines">
|
||||||
|
<group col="4" colspan="6">
|
||||||
|
</group>
|
||||||
|
<separator colspan="4"/>
|
||||||
|
<group col="2" colspan="4">
|
||||||
|
<button special="cancel" string="Cancel" icon='gtk-cancel'/>
|
||||||
|
<button name="create_payment" string="_Add to payment order" colspan="1" type="object" icon="gtk-execute"/>
|
||||||
|
</group>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="action_create_payment_order" model="ir.actions.act_window">
|
||||||
|
<field name="name">Populate Payment</field>
|
||||||
|
<field name="type">ir.actions.act_window</field>
|
||||||
|
<field name="res_model">payment.order.create</field>
|
||||||
|
<field name="view_type">form</field>
|
||||||
|
<field name="view_mode">form</field>
|
||||||
|
<field name="target">new</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
|
@ -0,0 +1,125 @@
|
||||||
|
# -*- 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 time
|
||||||
|
from lxml import etree
|
||||||
|
|
||||||
|
from osv import osv, fields
|
||||||
|
|
||||||
|
class payment_order_create(osv.osv_memory):
|
||||||
|
"""
|
||||||
|
Create a payment object with lines corresponding to the account move line
|
||||||
|
to pay according to the date and the mode provided by the user.
|
||||||
|
Hypothesis:
|
||||||
|
- Small number of non-reconcilied move line , payment mode and bank account type,
|
||||||
|
- Big number of partner and bank account.
|
||||||
|
|
||||||
|
If a type is given, unsuitable account Entry lines are ignored.
|
||||||
|
"""
|
||||||
|
|
||||||
|
_name = 'payment.order.create'
|
||||||
|
_description = 'payment.order.create'
|
||||||
|
_columns = {
|
||||||
|
'duedate': fields.date('Due Date', required=True),
|
||||||
|
'entries': fields.many2many('account.move.line', 'line_pay_rel', 'pay_id', 'line_id', 'Entries')
|
||||||
|
}
|
||||||
|
_defaults = {
|
||||||
|
'duedate': time.strftime('%Y-%m-%d'),
|
||||||
|
}
|
||||||
|
|
||||||
|
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
|
||||||
|
res = super(payment_order_create, 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':'entries', 'colspan':'4', 'height':'300', 'width':'800', 'nolabel':"1"})
|
||||||
|
child.addprevious(field)
|
||||||
|
res['arch'] = etree.tostring(view_obj)
|
||||||
|
return res
|
||||||
|
|
||||||
|
def create_payment(self, cr, uid, ids, context=None):
|
||||||
|
order_obj = self.pool.get('payment.order')
|
||||||
|
line_obj = self.pool.get('account.move.line')
|
||||||
|
|
||||||
|
data = self.read(cr, uid, ids, [], context)[0]
|
||||||
|
line_ids= data['entries']
|
||||||
|
if not line_ids: return {}
|
||||||
|
|
||||||
|
payment = order_obj.browse(cr, uid, data['active_id'],
|
||||||
|
context=context)
|
||||||
|
t = payment.mode and payment.mode.type.id or None
|
||||||
|
line2bank = pool.get('account.move.line').line2bank(cr, uid,
|
||||||
|
line_ids, t, context)
|
||||||
|
|
||||||
|
## Finally populate the current payment with new lines:
|
||||||
|
for line in line_obj.browse(cr, uid, line_ids, context=context):
|
||||||
|
if payment.date_prefered == "now":
|
||||||
|
#no payment date => immediate payment
|
||||||
|
date_to_pay = False
|
||||||
|
elif payment.date_prefered == 'due':
|
||||||
|
date_to_pay = line.date_maturity
|
||||||
|
elif payment.date_prefered == 'fixed':
|
||||||
|
date_to_pay = payment.date_planned
|
||||||
|
pool.get('payment.line').create(cr, uid,{
|
||||||
|
'move_line_id': line.id,
|
||||||
|
'amount_currency': line.amount_to_pay,
|
||||||
|
'bank_id': line2bank.get(line.id),
|
||||||
|
'order_id': payment.id,
|
||||||
|
'partner_id': line.partner_id and line.partner_id.id or False,
|
||||||
|
'communication': line.ref or '/',
|
||||||
|
'date': date_to_pay,
|
||||||
|
'currency': line.invoice and line.invoice.currency_id.id or False,
|
||||||
|
}, context=context)
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def search_entries(self, cr, uid, ids, context=None):
|
||||||
|
order_obj = self.pool.get('payment.order')
|
||||||
|
line_obj = self.pool.get('account.move.line')
|
||||||
|
mod_obj = self.pool.get('ir.model.data')
|
||||||
|
|
||||||
|
data = self.read(cr, uid, ids, [], context=context)[0]
|
||||||
|
search_due_date = data['duedate']
|
||||||
|
payment = order_obj.browse(cr, uid, context['active_id'], context=context)
|
||||||
|
ctx = ''
|
||||||
|
if payment.mode:
|
||||||
|
ctx = '''context="{'journal_id': %d}"''' % payment.mode.journal.id
|
||||||
|
|
||||||
|
# Search for move line to pay:
|
||||||
|
domain = [('reconcile_id', '=', False),('account_id.type', '=', 'payable'),('amount_to_pay', '>', 0)]
|
||||||
|
domain = domain + ['|',('date_maturity','<',search_due_date),('date_maturity','=',False)]
|
||||||
|
line_ids = line_obj.search(cr, uid, domain, context=context)
|
||||||
|
context.update({'line_ids': line_ids})
|
||||||
|
model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_create_payment_order_lines')], 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': 'payment.order.create',
|
||||||
|
'views': [(resource_id,'form')],
|
||||||
|
'type': 'ir.actions.act_window',
|
||||||
|
'target': 'new',
|
||||||
|
}
|
||||||
|
|
||||||
|
payment_order_create()
|
||||||
|
|
||||||
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -1,154 +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
|
|
||||||
import time
|
|
||||||
|
|
||||||
|
|
||||||
FORM = UpdateableStr()
|
|
||||||
|
|
||||||
FIELDS = {
|
|
||||||
'entries': {'string':'Entries', 'type':'many2many',
|
|
||||||
'relation': 'account.move.line',},
|
|
||||||
}
|
|
||||||
field_duedate={
|
|
||||||
'duedate': {'string':'Due Date', 'type':'date','required':True, 'default': lambda *a: time.strftime('%Y-%m-%d'),},
|
|
||||||
}
|
|
||||||
arch_duedate='''<?xml version="1.0"?>
|
|
||||||
<form string="Search Payment lines">
|
|
||||||
<field name="duedate" />
|
|
||||||
</form>'''
|
|
||||||
|
|
||||||
|
|
||||||
def search_entries(self, cr, uid, data, context):
|
|
||||||
search_due_date=data['form']['duedate']
|
|
||||||
|
|
||||||
pool = pooler.get_pool(cr.dbname)
|
|
||||||
order_obj = pool.get('payment.order')
|
|
||||||
line_obj = pool.get('account.move.line')
|
|
||||||
|
|
||||||
payment = order_obj.browse(cr, uid, data['id'],
|
|
||||||
context=context)
|
|
||||||
ctx = ''
|
|
||||||
if payment.mode:
|
|
||||||
ctx = '''context="{'journal_id': %d}"''' % payment.mode.journal.id
|
|
||||||
|
|
||||||
# Search for move line to pay:
|
|
||||||
domain = [('reconcile_id', '=', False),('account_id.type', '=', 'payable'),('amount_to_pay', '>', 0)]
|
|
||||||
domain = domain + ['|',('date_maturity','<',search_due_date),('date_maturity','=',False)]
|
|
||||||
line_ids = line_obj.search(cr, uid, domain, context=context)
|
|
||||||
FORM.string = '''<?xml version="1.0"?>
|
|
||||||
<form string="Populate Payment:">
|
|
||||||
<field name="entries" colspan="4" height="300" width="800" nolabel="1"
|
|
||||||
domain="[('id', 'in', [%s])]" %s/>
|
|
||||||
</form>''' % (','.join([str(x) for x in line_ids]), ctx)
|
|
||||||
return {}
|
|
||||||
|
|
||||||
def create_payment(self, cr, uid, data, context):
|
|
||||||
line_ids= data['form']['entries'][0][2]
|
|
||||||
if not line_ids: return {}
|
|
||||||
|
|
||||||
pool= pooler.get_pool(cr.dbname)
|
|
||||||
order_obj = pool.get('payment.order')
|
|
||||||
line_obj = pool.get('account.move.line')
|
|
||||||
|
|
||||||
payment = order_obj.browse(cr, uid, data['id'],
|
|
||||||
context=context)
|
|
||||||
t = payment.mode and payment.mode.type.id or None
|
|
||||||
line2bank = pool.get('account.move.line').line2bank(cr, uid,
|
|
||||||
line_ids, t, context)
|
|
||||||
|
|
||||||
## Finally populate the current payment with new lines:
|
|
||||||
for line in line_obj.browse(cr, uid, line_ids, context=context):
|
|
||||||
if payment.date_prefered == "now":
|
|
||||||
#no payment date => immediate payment
|
|
||||||
date_to_pay = False
|
|
||||||
elif payment.date_prefered == 'due':
|
|
||||||
date_to_pay = line.date_maturity
|
|
||||||
elif payment.date_prefered == 'fixed':
|
|
||||||
date_to_pay = payment.date_planned
|
|
||||||
pool.get('payment.line').create(cr,uid,{
|
|
||||||
'move_line_id': line.id,
|
|
||||||
'amount_currency': line.amount_to_pay,
|
|
||||||
'bank_id': line2bank.get(line.id),
|
|
||||||
'order_id': payment.id,
|
|
||||||
'partner_id': line.partner_id and line.partner_id.id or False,
|
|
||||||
'communication': line.ref or '/',
|
|
||||||
'date': date_to_pay,
|
|
||||||
'currency': line.invoice and line.invoice.currency_id.id or False,
|
|
||||||
}, context=context)
|
|
||||||
return {}
|
|
||||||
|
|
||||||
|
|
||||||
class wizard_payment_order(wizard.interface):
|
|
||||||
"""
|
|
||||||
Create a payment object with lines corresponding to the account move line
|
|
||||||
to pay according to the date and the mode provided by the user.
|
|
||||||
Hypothesis:
|
|
||||||
- Small number of non-reconcilied move line , payment mode and bank account type,
|
|
||||||
- Big number of partner and bank account.
|
|
||||||
|
|
||||||
If a type is given, unsuitable account Entry lines are ignored.
|
|
||||||
"""
|
|
||||||
states = {
|
|
||||||
|
|
||||||
'init': {
|
|
||||||
'actions': [],
|
|
||||||
'result': {
|
|
||||||
'type': 'form',
|
|
||||||
'arch': arch_duedate,
|
|
||||||
'fields':field_duedate,
|
|
||||||
'state': [
|
|
||||||
('end','_Cancel'),
|
|
||||||
('search','_Search', '', True)
|
|
||||||
]
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
'search': {
|
|
||||||
'actions': [search_entries],
|
|
||||||
'result': {
|
|
||||||
'type': 'form',
|
|
||||||
'arch': FORM,
|
|
||||||
'fields': FIELDS,
|
|
||||||
'state': [
|
|
||||||
('end','_Cancel'),
|
|
||||||
('create','_Add to payment order', '', True)
|
|
||||||
]
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'create': {
|
|
||||||
'actions': [],
|
|
||||||
'result': {
|
|
||||||
'type': 'action',
|
|
||||||
'action': create_payment,
|
|
||||||
'state': 'end'}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
wizard_payment_order('populate_payment')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
||||||
|
|
Loading…
Reference in New Issue