[IMP] improve find method of account period and make comapny_id as related on account voucher
bzr revid: ara@tinyerp.com-20110804095550-xu04lz4wkfhusvg0
This commit is contained in:
parent
db61756ea7
commit
1f4c3d2fbb
|
@ -918,10 +918,17 @@ class account_period(osv.osv):
|
|||
return False
|
||||
|
||||
def find(self, cr, uid, dt=None, context=None):
|
||||
if context is None: context = {}
|
||||
if not dt:
|
||||
dt = time.strftime('%Y-%m-%d')
|
||||
#CHECKME: shouldn't we check the state of the period?
|
||||
ids = self.search(cr, uid, [('date_start','<=',dt),('date_stop','>=',dt)])
|
||||
args = [('date_start', '<=' ,dt), ('date_stop', '>=', dt)]
|
||||
if context.get('company_id', False):
|
||||
args.append(('company_id', '=', context['company_id']))
|
||||
else:
|
||||
company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
|
||||
args.append(('company_id', '=', company_id))
|
||||
ids = self.search(cr, uid, args, context=context)
|
||||
if not ids:
|
||||
raise osv.except_osv(_('Error !'), _('No period defined for this date: %s !\nPlease create one.')%dt)
|
||||
return ids
|
||||
|
|
|
@ -39,7 +39,10 @@ class account_voucher(osv.osv):
|
|||
if context is None: context = {}
|
||||
if context.get('period_id', False):
|
||||
return context.get('period_id')
|
||||
periods = self.pool.get('account.period').find(cr, uid)
|
||||
if context.get('invoice_id', False):
|
||||
company_id = self.pool.get('account.invoice').browse(cr, uid, context['invoice_id'], context=context).company_id.id
|
||||
context.update({'company_id': company_id})
|
||||
periods = self.pool.get('account.period').find(cr, uid, context=context)
|
||||
return periods and periods[0] or False
|
||||
|
||||
def _get_journal(self, cr, uid, context=None):
|
||||
|
@ -228,7 +231,7 @@ class account_voucher(osv.osv):
|
|||
'currency_id': fields.function(_currency_id, type='many2one', relation='res.currency', string='Currency', store=True, readonly=True, multi="currency"),
|
||||
#duplicated field for display purposes
|
||||
'currency_id2': fields.function(_currency_id, type='many2one', relation='res.currency', string='Currency', store=True, readonly=True, multi="currency"),
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True, readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'company_id': fields.related('journal_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True),
|
||||
'company_currency': fields.related('company_id','currency_id', type='many2one', relation='res.currency', string='Currency', readonly=True),
|
||||
'state':fields.selection(
|
||||
[('draft','Draft'),
|
||||
|
@ -596,9 +599,13 @@ class account_voucher(osv.osv):
|
|||
@param context: context arguments, like lang, time zone
|
||||
@return: Returns a dict which contains new values, and context
|
||||
"""
|
||||
if context is None: context = {}
|
||||
period_pool = self.pool.get('account.period')
|
||||
res = self.onchange_partner_id(cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, context=context)
|
||||
pids = period_pool.search(cr, uid, [('date_start', '<=', date), ('date_stop', '>=', date)])
|
||||
if context.get('invoice_id', False):
|
||||
company_id = self.pool.get('account.invoice').browse(cr, uid, context['invoice_id'], context=context).company_id.id
|
||||
context.update({'company_id': company_id})
|
||||
pids = period_pool.find(cr, uid, date, context=context)
|
||||
if pids:
|
||||
if not 'value' in res:
|
||||
res['value'] = {}
|
||||
|
@ -606,6 +613,7 @@ class account_voucher(osv.osv):
|
|||
return res
|
||||
|
||||
def onchange_journal(self, cr, uid, ids, journal_id, line_ids, tax_id, partner_id, context=None):
|
||||
if context is None: context = {}
|
||||
if not journal_id:
|
||||
return {}
|
||||
journal_pool = self.pool.get('account.journal')
|
||||
|
@ -621,6 +629,9 @@ class account_voucher(osv.osv):
|
|||
if journal.currency:
|
||||
currency_id = journal.currency.id
|
||||
vals['value'].update({'currency_id':currency_id})
|
||||
context.update({'company_id': journal.company_id.id})
|
||||
periods = self.pool.get('account.period').find(cr, uid, context=context)
|
||||
vals['value'].update({'period_id':periods[0]})
|
||||
return vals
|
||||
|
||||
def proforma_voucher(self, cr, uid, ids, context=None):
|
||||
|
|
Loading…
Reference in New Issue