[IMP] allows to update credit/debit for initial balances of accounts, config wizard
bzr revid: fp@tinyerp.com-20111002105404-tkwzujn086qgjm6h
This commit is contained in:
parent
23b7cca691
commit
31803314ab
|
@ -346,6 +346,52 @@ class account_account(osv.osv):
|
||||||
res[account.id] = level
|
res[account.id] = level
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def _set_credit_debit(self, cr, uid, account_id, name, value, arg, context=None):
|
||||||
|
if context.get('config_invisible', True):
|
||||||
|
return True
|
||||||
|
|
||||||
|
account = self.browse(cr, uid, account_id, context=context)
|
||||||
|
diff = value - getattr(account,name)
|
||||||
|
if not diff:
|
||||||
|
return True
|
||||||
|
|
||||||
|
journal_obj = self.pool.get('account.journal')
|
||||||
|
jids = journal_obj.search(cr, uid, [('type','=','situation'),('centralisation','=',1),('company_id','=',account.company_id.id)], context=context)
|
||||||
|
if not jids:
|
||||||
|
raise osv.except_osv(_('Error!'),_("You need an Opening journal with centralisation checked to set the initial balance!"))
|
||||||
|
|
||||||
|
period_obj = self.pool.get('account.period')
|
||||||
|
pids = period_obj.search(cr, uid, [('special','=',True),('company_id','=',account.company_id.id)], context=context)
|
||||||
|
if not pids:
|
||||||
|
raise osv.except_osv(_('Error!'),_("No opening/closing period defined, please create one to set the initial balance!"))
|
||||||
|
|
||||||
|
move_obj = self.pool.get('account.move.line')
|
||||||
|
move_id = move_obj.search(cr, uid, [
|
||||||
|
('journal_id','=',jids[0]),
|
||||||
|
('period_id','=',pids[0]),
|
||||||
|
('account_id','=', account_id),
|
||||||
|
(name,'>', 0.0),
|
||||||
|
('name','=', _('Opening Balance'))
|
||||||
|
], context=context)
|
||||||
|
if move_id:
|
||||||
|
move = move_obj.browse(cr, uid, move_id[0], context=context)
|
||||||
|
move_obj.write(cr, uid, move_id[0], {
|
||||||
|
name: diff+getattr(move,name)
|
||||||
|
}, context=context)
|
||||||
|
else:
|
||||||
|
if diff<0.0:
|
||||||
|
raise osv.except_osv(_('Error!'),_("Unable to adapt the initial balance (negative value)!"))
|
||||||
|
nameinv = (name=='credit' and 'debit') or 'credit'
|
||||||
|
move_id = move_obj.create(cr, uid, {
|
||||||
|
'name': _('Opening Balance'),
|
||||||
|
'account_id': account_id,
|
||||||
|
'journal_id': jids[0],
|
||||||
|
'period_id': pids[0],
|
||||||
|
name: diff,
|
||||||
|
nameinv: 0.0
|
||||||
|
}, context=context)
|
||||||
|
return True
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'name': fields.char('Name', size=128, required=True, select=True),
|
'name': fields.char('Name', size=128, required=True, select=True),
|
||||||
'currency_id': fields.many2one('res.currency', 'Secondary Currency', help="Forces all moves for this account to have this secondary currency."),
|
'currency_id': fields.many2one('res.currency', 'Secondary Currency', help="Forces all moves for this account to have this secondary currency."),
|
||||||
|
@ -370,8 +416,8 @@ class account_account(osv.osv):
|
||||||
'child_consol_ids': fields.many2many('account.account', 'account_account_consol_rel', 'child_id', 'parent_id', 'Consolidated Children'),
|
'child_consol_ids': fields.many2many('account.account', 'account_account_consol_rel', 'child_id', 'parent_id', 'Consolidated Children'),
|
||||||
'child_id': fields.function(_get_child_ids, type='many2many', relation="account.account", string="Child Accounts"),
|
'child_id': fields.function(_get_child_ids, type='many2many', relation="account.account", string="Child Accounts"),
|
||||||
'balance': fields.function(__compute, digits_compute=dp.get_precision('Account'), string='Balance', multi='balance'),
|
'balance': fields.function(__compute, digits_compute=dp.get_precision('Account'), string='Balance', multi='balance'),
|
||||||
'credit': fields.function(__compute, digits_compute=dp.get_precision('Account'), string='Credit', multi='balance'),
|
'credit': fields.function(__compute, fnct_inv=_set_credit_debit, digits_compute=dp.get_precision('Account'), string='Credit', multi='balance'),
|
||||||
'debit': fields.function(__compute, digits_compute=dp.get_precision('Account'), string='Debit', multi='balance'),
|
'debit': fields.function(__compute, fnct_inv=_set_credit_debit, digits_compute=dp.get_precision('Account'), string='Debit', multi='balance'),
|
||||||
'reconcile': fields.boolean('Allow Reconciliation', help="Check this box if this account allows reconciliation of journal items."),
|
'reconcile': fields.boolean('Allow Reconciliation', help="Check this box if this account allows reconciliation of journal items."),
|
||||||
'shortcut': fields.char('Shortcut', size=12),
|
'shortcut': fields.char('Shortcut', size=12),
|
||||||
'tax_ids': fields.many2many('account.tax', 'account_account_tax_default_rel',
|
'tax_ids': fields.many2many('account.tax', 'account_account_tax_default_rel',
|
||||||
|
|
|
@ -91,6 +91,7 @@
|
||||||
<field name="res_model">account.account</field>
|
<field name="res_model">account.account</field>
|
||||||
<field name="view_type">form</field>
|
<field name="view_type">form</field>
|
||||||
<field name="view_mode">tree,form</field>
|
<field name="view_mode">tree,form</field>
|
||||||
|
<field name="context">{'config_invisible': False}</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record id="view_financial_accounts_todo" model="ir.actions.todo">
|
<record id="view_financial_accounts_todo" model="ir.actions.todo">
|
||||||
|
|
|
@ -162,14 +162,18 @@
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form string="Account">
|
<form string="Account">
|
||||||
<group col="6" colspan="4">
|
<group col="6" colspan="4">
|
||||||
<field name="name" select="1"/>
|
<field name="name" select="1"/>
|
||||||
<field name="code" select="1"/>
|
<field name="code" select="1"/>
|
||||||
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
|
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
|
||||||
<newline/>
|
<newline/>
|
||||||
<field name="parent_id"/>
|
<field name="parent_id"/>
|
||||||
<field name="type" select="1"/>
|
<field name="type" select="1"/>
|
||||||
<field name="user_type" select="1"/>
|
<field name="user_type" select="1"/>
|
||||||
<field name="active" groups="base.group_extended" />
|
<field name="active" groups="base.group_extended" />
|
||||||
|
<newline/>
|
||||||
|
<field name="debit" invisible="context.get('config_invisible', True)"/>
|
||||||
|
<field name="credit" invisible="context.get('config_invisible', True)"/>
|
||||||
|
<field name="balance" invisible="context.get('config_invisible', True)"/>
|
||||||
</group>
|
</group>
|
||||||
<notebook colspan="4">
|
<notebook colspan="4">
|
||||||
<page string="General Information">
|
<page string="General Information">
|
||||||
|
|
Loading…
Reference in New Issue