PEP8 on account_banking_payment_export

This commit is contained in:
Sandy Carter
2014-08-21 12:48:58 -04:00
parent c12500d6f4
commit a4ad7a0fbd
8 changed files with 101 additions and 76 deletions

View File

@@ -1 +1 @@
from . import model
from . import model

View File

@@ -56,8 +56,8 @@
],
'demo': ['demo/banking_demo.xml'],
'description': '''
Infrastructure to export payment orders
plus some bug fixes and obvious enhancements to payment orders
Infrastructure to export payment orders
plus some bug fixes and obvious enhancements to payment orders
that will hopefully land in offical addons one day.
This technical module provides the base infrastructure to export
@@ -65,21 +65,25 @@
technical features:
* a new payment.mode.type model
* payment.mode now has a mandatory type
* a better implementation of payment_mode.suitable_bank_types() based on payment.mode.type
* the "make payment" button launches a wizard depending on the payment.mode.type
* a manual payment mode type is provided as an example, with a default "do nothing" wizard
* a better implementation of payment_mode.suitable_bank_types() based
on payment.mode.type
* the "make payment" button launches a wizard depending on the
payment.mode.type
* a manual payment mode type is provided as an example, with a default
"do nothing" wizard
To enable the use of payment order to collect money for customers,
it adds a payment_order_type (payment|debit) as a basis of direct debit support
(this field becomes visible when account_direct_debit is installed).
Refactoring note: this field should ideally go in account_direct_debit,
but account_banking_payment currently depends on it.
To enable the use of payment order to collect money for customers,
it adds a payment_order_type (payment|debit) as a basis of direct debit
support (this field becomes visible when account_direct_debit is
installed).
Refactoring note: this field should ideally go in account_direct_debit,
but account_banking_payment currently depends on it.
Bug fixes and enhancement that should land in official addons:
* make the search function of the payment export wizard extensible
* fix lp:1275478: allow payment of customer refunds
* display the maturity date of the move lines when you are in
* display the maturity date of the move lines when you are in
the wizard to select the lines to pay
''',
''',
'installable': True,
}

View File

@@ -73,15 +73,18 @@ class account_move_line(orm.Model):
) %(operator)s %%s ''' % {'operator': x[1]}, args))
sql_args = tuple(map(itemgetter(2), args))
cr.execute(('''SELECT id
cr.execute(
('''\
SELECT id
FROM account_move_line l
WHERE account_id IN (select id
FROM account_account
WHERE type in %s AND active)
AND reconcile_id IS null
AND credit > 0
AND ''' + where + ' and ' + query),
(('payable', 'receivable'),)+sql_args )
AND ''' + where + ' and ' + query
), (('payable', 'receivable'), ) + sql_args
)
# The patch we have compared to the original function in
# addons/account_payment is just above :
# original code : type = 'payable'
@@ -93,6 +96,10 @@ class account_move_line(orm.Model):
return [('id', 'in', map(lambda x:x[0], res))]
_columns = {
'amount_to_pay': fields.function(amount_to_pay,
type='float', string='Amount to pay', fnct_search=_to_pay_search),
'amount_to_pay': fields.function(
amount_to_pay,
type='float',
string='Amount to pay',
fnct_search=_to_pay_search
),
}

View File

@@ -3,7 +3,7 @@
#
# Copyright (C) 2009 EduSense BV (<http://www.edusense.nl>).
# (C) 2011 - 2013 Therp BV (<http://therp.nl>).
#
#
# All other contributions are (C) by their respective contributors
#
# All Rights Reserved
@@ -52,7 +52,7 @@ class payment_order(orm.Model):
If type is manual. just confirm the order.
Previously (pre-v6) in account_payment/wizard/wizard_pay.py
"""
if context == None:
if context is None:
context = {}
result = {}
orders = self.browse(cr, uid, ids, context)
@@ -81,10 +81,13 @@ class payment_order(orm.Model):
if order.mode.type and order.mode.type.ir_model_id:
raise orm.except_orm(
_('Error'),
_('You can only combine payment orders of the same type')
)
_('You can only combine payment orders of the same '
'type')
)
# process manual payments
wf_service = netsvc.LocalService('workflow')
for order_id in ids:
wf_service.trg_validate(uid, 'payment.order', order_id, 'done', cr)
wf_service.trg_validate(
uid, 'payment.order', order_id, 'done', cr
)
return result

View File

@@ -3,7 +3,7 @@
#
# Copyright (C) 2009 EduSense BV (<http://www.edusense.nl>).
# (C) 2011 - 2013 Therp BV (<http://therp.nl>).
#
#
# All other contributions are (C) by their respective contributors
#
# All Rights Reserved
@@ -37,18 +37,24 @@ class payment_manual(orm.TransientModel):
_description = 'Send payment order(s) manually'
_columns = {
'payment_order_ids': fields.many2many('payment.order',
'wiz_manual_payorders_rel', 'wizard_id', 'payment_order_id',
'Payment orders', readonly=True),
}
'payment_order_ids': fields.many2many(
'payment.order',
'wiz_manual_payorders_rel',
'wizard_id',
'payment_order_id',
'Payment orders',
readonly=True
),
}
def create(self, cr, uid, vals, context=None):
payment_order_ids = context.get('active_ids', [])
vals.update({
'payment_order_ids': [[6, 0, payment_order_ids]],
})
return super(payment_manual, self).create(cr, uid,
vals, context=context)
return super(payment_manual, self).create(
cr, uid, vals, context=context
)
def button_ok(self, cr, uid, ids, context=None):
wf_service = netsvc.LocalService('workflow')

View File

@@ -3,7 +3,7 @@
#
# Copyright (C) 2009 EduSense BV (<http://www.edusense.nl>).
# (C) 2011 - 2013 Therp BV (<http://therp.nl>).
#
#
# All other contributions are (C) by their respective contributors
#
# All Rights Reserved
@@ -38,8 +38,9 @@ class payment_mode(orm.Model):
res = []
payment_mode = self.browse(
cr, uid, payment_mode_id, context)
if (payment_mode and payment_mode.type and
payment_mode.type.suitable_bank_types):
if (payment_mode
and payment_mode.type
and payment_mode.type.suitable_bank_types):
res = [t.code for t in payment_mode.type.suitable_bank_types]
return res

View File

@@ -3,7 +3,7 @@
#
# Copyright (C) 2009 EduSense BV (<http://www.edusense.nl>).
# (C) 2011 - 2013 Therp BV (<http://therp.nl>).
#
#
# All other contributions are (C) by their respective contributors
#
# All Rights Reserved
@@ -63,9 +63,11 @@ class payment_mode_type(orm.Model):
def _auto_init(self, cr, context=None):
r = super(payment_mode_type, self)._auto_init(cr, context=context)
# migrate xmlid from manual_bank_transfer to avoid dependency on account_banking
cr.execute("""UPDATE ir_model_data SET module='account_banking_payment_export'
WHERE module='account_banking' AND
name='manual_bank_tranfer' AND
# migrate xmlid from manual_bank_transfer to avoid dependency on
# account_banking
cr.execute("""UPDATE ir_model_data
SET module='account_banking_payment_export'
WHERE module='account_banking' AND
name='manual_bank_tranfer' AND
model='payment.mode.type'""")
return r

View File

@@ -3,7 +3,7 @@
#
# Copyright (C) 2009 EduSense BV (<http://www.edusense.nl>).
# (C) 2011 - 2013 Therp BV (<http://therp.nl>).
#
#
# All other contributions are (C) by their respective contributors
#
# All Rights Reserved
@@ -50,8 +50,8 @@ class payment_order_create(orm.TransientModel):
context = {}
data = self.read(cr, uid, ids, ['duedate'], context=context)[0]
search_due_date = data['duedate']
### start account_banking_payment ###
# start account_banking_payment
payment = self.pool.get('payment.order').browse(
cr, uid, context['active_id'], context=context)
# Search for move line to pay:
@@ -62,7 +62,7 @@ class payment_order_create(orm.TransientModel):
]
self.extend_payment_order_domain(
cr, uid, payment, domain, context=context)
### end account_direct_debit ###
# end account_direct_debit
domain = domain + [
'|', ('date_maturity', '<=', search_due_date),
@@ -71,21 +71,22 @@ class payment_order_create(orm.TransientModel):
line_ids = line_obj.search(cr, uid, domain, context=context)
context.update({'line_ids': line_ids})
model_data_ids = mod_obj.search(
cr, uid,[
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': _('Entry 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',
return {
'name': _('Entry 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',
}
def _prepare_payment_line(self, cr, uid, payment, line, context=None):
@@ -93,26 +94,26 @@ class payment_order_create(orm.TransientModel):
The resulting dict is passed to the create method of payment.line'''
_today = fields.date.context_today(self, cr, uid, context=context)
if payment.date_prefered == "now":
#no payment date => immediate payment
# no payment date => immediate payment
date_to_pay = False
elif payment.date_prefered == 'due':
### account_banking
# account_banking
# date_to_pay = line.date_maturity
date_to_pay = (
line.date_maturity
if line.date_maturity and line.date_maturity > _today
else False)
### end account banking
# end account banking
elif payment.date_prefered == 'fixed':
### account_banking
# account_banking
# date_to_pay = payment.date_scheduled
date_to_pay = (
payment.date_scheduled
if payment.date_scheduled and payment.date_scheduled > _today
else False)
### end account banking
# end account banking
### account_banking
# account_banking
state = 'normal'
communication = line.ref or '-'
if line.invoice:
@@ -132,19 +133,19 @@ class payment_order_create(orm.TransientModel):
state = 'structured'
# support debit orders when enabled
if (payment.payment_order_type == 'debit' and
'amount_to_receive' in line):
if (payment.payment_order_type == 'debit'
and 'amount_to_receive' in line):
amount_currency = line.amount_to_receive
else:
amount_currency = line.amount_to_pay
### end account_banking
# end account_banking
### account banking
# account banking
# t = None
# line2bank = line_obj.line2bank(cr, uid, line_ids, t, context)
line2bank = self.pool['account.move.line'].line2bank(
cr, uid, [line.id], payment.mode.id, context)
### end account banking
# end account banking
res = {
'move_line_id': line.id,
@@ -152,11 +153,11 @@ class payment_order_create(orm.TransientModel):
'bank_id': line2bank.get(line.id),
'order_id': payment.id,
'partner_id': line.partner_id and line.partner_id.id or False,
### account banking
# account banking
# 'communication': line.ref or '/'
'communication': communication,
'state': state,
### end account banking
# end account banking
'date': date_to_pay,
'currency': (line.invoice and line.invoice.currency_id.id
or line.journal_id.currency.id
@@ -166,11 +167,11 @@ class payment_order_create(orm.TransientModel):
def create_payment(self, cr, uid, ids, context=None):
'''
This method is a slightly modified version of the existing method on this
model in account_payment.
This method is a slightly modified version of the existing method on
this model in account_payment.
- pass the payment mode to line2bank()
- allow invoices to create influence on the payment process: not only 'Free'
references are allowed, but others as well
- allow invoices to create influence on the payment process: not only
'Free' references are allowed, but others as well
- check date_to_pay is not in the past.
'''
if context is None:
@@ -182,18 +183,19 @@ class payment_order_create(orm.TransientModel):
payment = self.pool['payment.order'].browse(
cr, uid, context['active_id'], context=context)
## Populate the current payment with new lines:
# Populate the current payment with new lines:
for line in self.pool['account.move.line'].browse(
cr, uid, line_ids, context=context):
vals = self._prepare_payment_line(
cr, uid, payment, line, context=context)
self.pool['payment.line'].create(cr, uid, vals, context=context)
# Force reload of payment order view as a workaround for lp:1155525
return {'name': _('Payment Orders'),
'context': context,
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'payment.order',
'res_id': context['active_id'],
'type': 'ir.actions.act_window',
return {
'name': _('Payment Orders'),
'context': context,
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'payment.order',
'res_id': context['active_id'],
'type': 'ir.actions.act_window',
}