import openerp
from openerp import SUPERUSER_ID
-from openerp import pooler, tools
+from openerp import tools
from openerp.osv import fields, osv, expression
from openerp.tools.translate import _
from openerp.tools.float_utils import float_round as round
(_check_percent, 'Percentages for Payment Term Line must be between 0 and 1, Example: 0.02 for 2%.', ['value_amount']),
]
-account_payment_term_line()
class account_account_type(osv.osv):
_name = "account.account.type"
}
_order = "code"
-account_account_type()
def _code_get(self, cr, uid, context=None):
acc_type_obj = self.pool.get('account.account.type')
class account_tax(osv.osv):
_name = 'account.tax'
-account_tax()
class account_account(osv.osv):
_order = "parent_left"
self._check_moves(cr, uid, ids, "unlink", context=context)
return super(account_account, self).unlink(cr, uid, ids, context=context)
-account_account()
class account_journal(osv.osv):
_name = "account.journal"
'user_id': fields.many2one('res.users', 'User', help="The user responsible for this journal"),
'groups_id': fields.many2many('res.groups', 'account_journal_group_rel', 'journal_id', 'group_id', 'Groups'),
'currency': fields.many2one('res.currency', 'Currency', help='The currency used to enter statement'),
- 'entry_posted': fields.boolean('Skip \'Draft\' State for Manual Entries', help='Check this box if you don\'t want new journal entries to pass through the \'draft\' state and instead goes directly to the \'posted state\' without any manual validation. \nNote that journal entries that are automatically created by the system are always skipping that state.'),
+ 'entry_posted': fields.boolean('Autopost Created Moves', help='Check this box to automatically post entries of this journal. Note that legally, some entries may be automatically posted when the source document is validated (Invoices), whatever the status of this field.'),
'company_id': fields.many2one('res.company', 'Company', required=True, select=1, help="Company related to this journal"),
'allow_date':fields.boolean('Check Date in Period', help= 'If set to True then do not accept the entry if the entry date is not into the period dates'),
return self.name_get(cr, user, ids, context=context)
-account_journal()
class account_fiscalyear(osv.osv):
_name = "account.fiscalyear"
ids = self.search(cr, user, [('name', operator, name)]+ args, limit=limit)
return self.name_get(cr, user, ids, context=context)
-account_fiscalyear()
class account_period(osv.osv):
_name = "account.period"
company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
args.append(('company_id', '=', company_id))
result = []
- #WARNING: in next version the default value for account_periof_prefer_normal will be True
- if context.get('account_period_prefer_normal'):
+ if context.get('account_period_prefer_normal', True):
# look for non-special periods first, and fallback to all if no result is found
result = self.search(cr, uid, args + [('special', '=', False)], context=context)
if not result:
result = self.search(cr, uid, args, context=context)
if not result:
- raise osv.except_osv(_('Error!'), _('There is no period defined for this date: %s.\nPlease create one.')%dt)
+ model, action_id = self.pool['ir.model.data'].get_object_reference(cr, uid, 'account', 'action_account_fiscalyear')
+ msg = _('There is no period defined for this date: %s.\nPlease, go to Configuration/Periods and configure a fiscal year.') % dt
+ raise openerp.exceptions.RedirectWarning(msg, action_id, _('Go to the configuration panel'))
+
return result
def action_draft(self, cr, uid, ids, *args):
return self.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop)])
return self.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop), ('special', '=', False)])
-account_period()
class account_journal_period(osv.osv):
_name = "account.journal.period"
}
_order = "period_id"
-account_journal_period()
class account_fiscalyear(osv.osv):
_inherit = "account.fiscalyear"
})
return super(account_fiscalyear, self).copy(cr, uid, id, default=default, context=context)
-account_fiscalyear()
#----------------------------------------------------------
# Entries
#----------------------------------------------------------
context = {}
#put the company in context to find the good period
ctx = context.copy()
- ctx.update({'company_id': company_id, 'account_period_prefer_normal': True})
+ ctx.update({'company_id': company_id})
return {
'journal_id': journal_id,
'date': date,
return res
def _get_period(self, cr, uid, context=None):
- ctx = dict(context or {}, account_period_prefer_normal=True)
+ ctx = dict(context or {})
period_ids = self.pool.get('account.period').find(cr, uid, context=ctx)
return period_ids[0]
valid_moves = [move.id for move in valid_moves]
return len(valid_moves) > 0 and valid_moves or False
-account_move()
class account_move_reconcile(osv.osv):
_name = "account.move.reconcile"
result.append((r.id,r.name))
return result
-account_move_reconcile()
#----------------------------------------------------------
# Tax
if context.get('period_id', False):
period_id = context['period_id']
else:
- ctx = dict(context, account_period_prefer_normal=True)
- period_id = self.pool.get('account.period').find(cr, uid, context=ctx)
+ period_id = self.pool.get('account.period').find(cr, uid, context=context)
if not period_id:
return dict.fromkeys(ids, 0.0)
period_id = period_id[0]
]
_order = 'code'
-account_tax_code()
def get_precision_tax():
def change_digit_tax(cr):
- res = pooler.get_pool(cr.dbname).get('decimal.precision').precision_get(cr, SUPERUSER_ID, 'Account')
+ res = openerp.registry(cr.dbname)['decimal.precision'].precision_get(cr, SUPERUSER_ID, 'Account')
return (16, res+3)
return change_digit_tax
total += r['amount']
return res
-account_tax()
# ---------------------------------------------------------
# Account Entries Models
move_date = datetime.strptime(move_date,"%Y-%m-%d")
for model in self.browse(cr, uid, ids, context=context):
ctx = context.copy()
- ctx.update({'company_id': model.company_id.id, 'account_period_prefer_normal': True})
+ ctx.update({'company_id': model.company_id.id})
period_ids = period_obj.find(cr, uid, dt=context.get('date', False), context=ctx)
period_id = period_ids and period_ids[0] or False
ctx.update({'journal_id': model.journal_id.id,'period_id': period_id})
return {'value': {'company_id': company_id}}
-account_model()
class account_model_line(osv.osv):
_name = "account.model.line"
('credit_debit1', 'CHECK (credit*debit=0)', 'Wrong credit or debit value in model, they must be positive!'),
('credit_debit2', 'CHECK (credit+debit>=0)', 'Wrong credit or debit value in model, they must be positive!'),
]
-account_model_line()
# ---------------------------------------------------------
# Account Subscription
self.write(cr, uid, ids, {'state':'running'})
return True
-account_subscription()
class account_subscription_line(osv.osv):
_name = "account.subscription.line"
_rec_name = 'date'
-account_subscription_line()
# ---------------------------------------------------------------
# Account Templates: Account, Tax, Tax Code and chart. + Wizard
class account_tax_template(osv.osv):
_name = 'account.tax.template'
-account_tax_template()
class account_account_template(osv.osv):
_order = "code"
obj_acc._parent_store_compute(cr)
return acc_template_ref
-account_account_template()
class account_add_tmpl_wizard(osv.osv_memory):
"""Add one more account from the template.
def action_cancel(self, cr, uid, ids, context=None):
return { 'type': 'state', 'state': 'end' }
-account_add_tmpl_wizard()
class account_tax_code_template(osv.osv):
(_check_recursion, 'Error!\nYou cannot create recursive Tax Codes.', ['parent_id'])
]
_order = 'code,name'
-account_tax_code_template()
class account_chart_template(osv.osv):
'parent_id': fields.many2one('account.chart.template', 'Parent Chart Template'),
'code_digits': fields.integer('# of Digits', required=True, help="No. of Digits to use for account code"),
'visible': fields.boolean('Can be Visible?', help="Set this to False if you don't want this template to be used actively in the wizard that generate Chart of Accounts from templates, this is useful when you want to generate accounts of this template only when loading its child template."),
+ 'currency_id': fields.many2one('res.currency', 'Currency'),
'complete_tax_set': fields.boolean('Complete Set of Taxes', help='This boolean helps you to choose if you want to propose to the user to encode the sale and purchase rates or choose from list of taxes. This last choice assumes that the set of tax defined on this template is complete'),
'account_root_id': fields.many2one('account.account.template', 'Root Account', domain=[('parent_id','=',False)]),
'tax_code_root_id': fields.many2one('account.tax.code.template', 'Root Tax Code', domain=[('parent_id','=',False)]),
'complete_tax_set': True,
}
-account_chart_template()
class account_tax_template(osv.osv):
res.update({'tax_template_to_tax': tax_template_to_tax, 'account_dict': todo_dict})
return res
-account_tax_template()
# Fiscal Position Templates
})
return True
-account_fiscal_position_template()
class account_fiscal_position_tax_template(osv.osv):
_name = 'account.fiscal.position.tax.template'
'tax_dest_id': fields.many2one('account.tax.template', 'Replacement Tax')
}
-account_fiscal_position_tax_template()
class account_fiscal_position_account_template(osv.osv):
_name = 'account.fiscal.position.account.template'
'account_dest_id': fields.many2one('account.account.template', 'Account Destination', domain=[('type','<>','view')], required=True)
}
-account_fiscal_position_account_template()
# ---------------------------------------------------------
# Account generation from template wizards
def onchange_chart_template_id(self, cr, uid, ids, chart_template_id=False, context=None):
res = {}
tax_templ_obj = self.pool.get('account.tax.template')
- ir_values = self.pool.get('ir.values')
res['value'] = {'complete_tax_set': False, 'sale_tax': False, 'purchase_tax': False}
if chart_template_id:
data = self.pool.get('account.chart.template').browse(cr, uid, chart_template_id, context=context)
- #set currecy_id based on selected COA template using ir.vaalues else current users company's currency
- value_id = ir_values.search(cr, uid, [('model', '=', 'account.chart.template'), ('res_id', '=', chart_template_id)], limit=1, context=context)
- if value_id:
- currency_id = int(ir_values.browse(cr, uid, value_id[0], context=context).value)
- else:
- currency_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id
+ currency_id = data.currency_id and data.currency_id.id or self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id
res['value'].update({'complete_tax_set': data.complete_tax_set, 'currency_id': currency_id})
if data.complete_tax_set:
# default tax is given by the lowest sequence. For same sequence we will take the latest created as it will be the case for tax created while isntalling the generic chart of account
res = super(wizard_multi_charts_accounts, self).default_get(cr, uid, fields, context=context)
tax_templ_obj = self.pool.get('account.tax.template')
account_chart_template = self.pool['account.chart.template']
- data_obj = self.pool.get('ir.model.data')
if 'bank_accounts_id' in fields:
res.update({'bank_accounts_id': [{'acc_name': _('Cash'), 'account_type': 'cash'},{'acc_name': _('Bank'), 'account_type': 'bank'}]})
#in order to set default chart which was last created set max of ids.
chart_id = max(ids)
if context.get("default_charts"):
- data_ids = data_obj.search(cr, uid, [('model', '=', 'account.chart.template'), ('module', '=', context.get("default_charts"))], limit=1, context=context)
- if data_ids:
- chart_id = data_obj.browse(cr, uid, data_ids[0], context=context).res_id
+ model_data = self.pool.get('ir.model.data').search_read(cr, uid, [('model','=','account.chart.template'),('module','=',context.get("default_charts"))], ['res_id'], context=context)
+ if model_data:
+ chart_id = model_data[0]['res_id']
chart = account_chart_template.browse(cr, uid, chart_id, context=context)
chart_hierarchy_ids = self._get_chart_parent_ids(cr, uid, chart, context=context)
if 'chart_template_id' in fields:
def _get_analytic_journal(journal_type):
# Get the analytic journal
data = False
- if journal_type in ('sale', 'sale_refund'):
- data = obj_data.get_object_reference(cr, uid, 'account', 'analytic_journal_sale')
- elif journal_type in ('purchase', 'purchase_refund'):
- pass
- elif journal_type == 'general':
+ try:
+ if journal_type in ('sale', 'sale_refund'):
+ data = obj_data.get_object_reference(cr, uid, 'account', 'analytic_journal_sale')
+ elif journal_type in ('purchase', 'purchase_refund'):
+ data = obj_data.get_object_reference(cr, uid, 'account', 'exp')
+ elif journal_type == 'general':
+ pass
+ except ValueError:
pass
return data and data[1] or False
try:
tmp2 = obj_data.get_object_reference(cr, uid, *ref)
if tmp2:
- self.pool.get(tmp2[0]).write(cr, uid, tmp2[1], {
+ self.pool[tmp2[0]].write(cr, uid, tmp2[1], {
'currency_id': obj_wizard.currency_id.id
})
except ValueError:
current_num += 1
return True
-wizard_multi_charts_accounts()
class account_bank_accounts_wizard(osv.osv_memory):
_name='account.bank.accounts.wizard'
'account_type': fields.selection([('cash','Cash'), ('check','Check'), ('bank','Bank')], 'Account Type', size=32),
}
-account_bank_accounts_wizard()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: