[FIX] account_check_writing: print check in batch

bzr revid: qdp-launchpad@openerp.com-20121206111134-71s81rczm5t6bcq6
This commit is contained in:
Quentin (OpenERP) 2012-12-06 12:11:34 +01:00
parent 39c47913a8
commit b1fd9f7dca
2 changed files with 32 additions and 14 deletions

View File

@ -18,39 +18,57 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from tools.translate import _
from osv import fields, osv
class account_check_write(osv.osv_memory):
_name = 'account.check.write'
_description = 'Assign Check Number'
_description = 'Prin Check in Batch'
_columns = {
'check_number': fields.char('Check Number', required=True, help="The Check Number."),
'check_number': fields.integer('Next Check Number', required=True, help="The number of the next check number to be printed."),
}
def _get_next_number(self, cr, uid, context=None):
dummy, sequence_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_check_writing', 'sequence_check_number')
return self.pool.get('ir.sequence').read(cr, uid, sequence_id, ['number_next'])['number_next']
_defaults = {
'check_number': lambda obj, cr, uid, context:obj.pool.get('ir.sequence').get(cr, uid, 'check.number'),
'check_number': _get_next_number,
}
def print_check_write(self, cr, uid, ids, context=None):
voucher_obj = self.pool.get('account.voucher')
if context is None:
context = {}
voucher_ids = context.get('active_ids', [])
number = int(self.browse(cr, uid, ids[0], context=context).check_number)
if voucher_ids:
checks = voucher_obj.browse(cr, uid, voucher_ids, context=context)
for check in checks:
if not check.number:
voucher_obj.write(cr, uid, [check.id], {'number': str(number)}, context=context)
number += 1
voucher_obj = self.pool.get('account.voucher')
ir_sequence_obj = self.pool.get('ir.sequence')
#update the sequence to number the checks from the value encoded in the wizard
dummy, sequence_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_check_writing', 'sequence_check_number')
increment = ir_sequence_obj.read(cr, uid, sequence_id, ['number_increment'])['number_increment']
new_value = self.browse(cr, uid, ids[0], context=context).check_number
ir_sequence_obj.write(cr, uid, sequence_id, {'number_next': new_value})
#validate the checks so that they get a number
voucher_ids = context.get('active_ids', [])
for check in voucher_obj.browse(cr, uid, voucher_ids, context=context):
new_value += increment
if check.number:
raise osv.except_osv(_('Error!'),_("One of the printed check already got a number."))
voucher_obj.proforma_voucher(cr, uid, voucher_ids, context=context)
#update the sequence again (because the assignation using next_val was made during the same transaction of
#the first update of sequence)
ir_sequence_obj.write(cr, uid, sequence_id, {'number_next': new_value})
#print the checks
check_layout_report = {
'top' : 'account.print.check.top',
'middle' : 'account.print.check.middle',
'bottom' : 'account.print.check.bottom',
}
check_layout = voucher_obj.browse(cr, uid, voucher_ids[0], context=context).company_id.check_layout
if not check_layout:
check_layout = 'top'

View File

@ -20,7 +20,7 @@
<act_window id="action_account_check_write"
multi="True"
name="Check Write"
name="Print Check in Batch"
res_model="account.check.write" src_model="account.voucher"
view_mode="form" target="new" view_type="form" />