[ADD] Don't allow deletion of confirmed statement lines, and make sure that deleted satement lines remove the linked imported transaction record.

[ADD] Default the company on the import wizard.
[ADD] Make write-off fields optional, otherwise it's not possible to do a partial-reconcile.
[FIX] When local_currency is the company currency, look for journals with or without the currency set.
This commit is contained in:
James Jesudason
2012-02-21 23:50:13 +00:00
parent 6461c0e282
commit 38999d7ee7
5 changed files with 39 additions and 11 deletions

View File

@@ -1611,11 +1611,13 @@ class banking_import_transaction(osv.osv):
'writeoff_analytic_id': fields.many2one(
'account.analytic.account', 'Write off analytic account'),
}
_defaults = {
'company_id': lambda s,cr,uid,c:
s.pool.get('res.company')._company_default_get(
cr, uid, 'bank.import.transaction', context=c),
}
banking_import_transaction()
class account_bank_statement_line(osv.osv):
@@ -1623,7 +1625,7 @@ class account_bank_statement_line(osv.osv):
_columns = {
'import_transaction_id': fields.many2one(
'banking.import.transaction',
'Import transaction', readonly=True),
'Import transaction', readonly=True, delete='cascade'),
'match_multi': fields.related(
'import_transaction_id', 'match_multi', type='boolean',
string='Multi match', readonly=True),
@@ -1762,6 +1764,19 @@ class account_bank_statement_line(osv.osv):
self.write(
cr, uid, set_draft_ids, {'state': 'draft'}, context=context)
return True
def unlink(self, cr, uid, ids, context=None):
"""
Don't allow deletion of a confirmed statement line
"""
if type(ids) is int:
ids = [ids]
for line in self.browse(cr, uid, ids, context=context):
if line.state == 'confirmed':
raise osv.except_osv(_('Confirmed Statement Line'), _("You cannot delete a confirmed Statement Line: '%s'" % line.name))
return super(account_bank_statement,self).unlink(cr, uid, ids, context=context)
account_bank_statement_line()
class account_bank_statement(osv.osv):
@@ -1843,6 +1858,18 @@ class account_bank_statement(osv.osv):
"""
self.write(cr, uid, ids, {'state':'draft'}, context=context)
def unlink(self, cr, uid, ids, context=None):
"""
Don't allow deletion of statement with confirmed bank statement lines.
"""
if type(ids) is int:
ids = [ids]
for st in self.browse(cr, uid, ids, context=context):
for line in st.line_ids:
if line.state == 'confirmed':
raise osv.except_osv(_('Confirmed Statement Lines'), _("You cannot delete a Statement with confirmed Statement Lines: '%s'" % st.name))
return super(account_bank_statement,self).unlink(cr, uid, ids, context=context)
_columns = {
# override this field *only* to replace the
# function method with the one from this module.

View File

@@ -425,7 +425,11 @@ class banking_import(osv.osv_memory):
_defaults = {
'state': 'init',
'company': lambda s,cr,uid,c:
s.pool.get('res.company')._company_default_get(
cr, uid, 'bank.import.transaction', context=c),
}
banking_import()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@@ -341,5 +341,6 @@ class banking_transaction_wizard(osv.osv_memory):
#'manual_payment_order_id': fields.many2one(
# 'payment.order', "Payment order to reconcile"),
}
banking_transaction_wizard()

View File

@@ -100,11 +100,8 @@
<page string="Write-Off" attrs="{'invisible': [('match_type', '=', False)]}">
<group colspan="2" col="2">
<label string="If the amount exceeds the match, you must set a write-off account and journal for the residual of this reconciliation. If the amount is smaller than the match, this is optional. If you do not set a write-off account in this case, the result will be a partial reconciliation." colspan="2"/>
<!-- no luck with these lt/gt calculations in attrs -->
<field name="writeoff_account_id"
attrs="{'required': ['|','&amp;',('residual', '&lt;', 0),('amount', '&gt;', 0),'&amp;',('residual', '&gt;', 0),('amount', '&lt;', 0)]}"/>
<field name="writeoff_journal_id"
attrs="{'required': ['|','&amp;',('residual', '&lt;', 0),('amount', '&gt;', 0),'&amp;',('residual', '&gt;', 0),('amount', '&lt;', 0)]}"/>
<field name="writeoff_account_id" />
<field name="writeoff_journal_id" />
<field name="writeoff_analytic_id" />
<button colspan="1"
name="trigger_write"

View File

@@ -220,22 +220,21 @@ def get_company_bank_account(pool, cursor, uid, account_number, currency,
('type', '=', 'bank'),
('currency.name', '=', currency or company.currency_id.name)
])
print "---journal_ids:", account_number, journal_ids
if not journal_ids and currency == company.currency_id.name:
journal_ids = journal_obj.search(cursor, uid, [
if currency == company.currency_id.name:
journal_ids_no_curr = journal_obj.search(cursor, uid, [
('type', '=', 'bank'), ('currency', '=', False)
])
journal_ids.extend(journal_ids_no_curr)
if journal_ids:
criteria.append(('journal_id', 'in', journal_ids))
# Find bank account settings
print "---criteria:", criteria
bank_settings_ids = bank_settings_obj.search(cursor, uid, criteria)
if bank_settings_ids:
settings = bank_settings_obj.browse(cursor, uid, bank_settings_ids)[0]
results.company_id = company
results.journal_id = settings.journal_id
print "---journal_id", settings.journal_id
# Take currency from settings or from company
if settings.journal_id.currency.id:
results.currency_id = settings.journal_id.currency