'state': 'draft',
'currency_id': _get_currency,
'journal_id': lambda self, cr, uid, c: c.get('journal_id', False),
+ 'credit': 0.0,
+ 'debit': 0.0,
'account_id': lambda self, cr, uid, c: c.get('account_id', False),
'period_id': lambda self, cr, uid, c: c.get('period_id', False),
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.move.line', context=c)
lines = self.browse(cr, uid, ids, context=context)
for l in lines:
if l.account_id.type == 'view':
- return False
+ raise osv.except_osv(_('Error :'), _('You can not create move line on view account %s %s') % (l.account_id.code, l.account_id.name))
return True
def _check_no_closed(self, cr, uid, ids, context=None):
lines = self.browse(cr, uid, ids, context=context)
for l in lines:
if l.account_id.type == 'closed':
- return False
+ raise osv.except_osv(_('Error :'), _('You can not create move line on closed account %s %s') % (l.account_id.code, l.account_id.name))
return True
def _check_company_id(self, cr, uid, ids, context=None):
return False
return True
+ def _check_currency(self, cr, uid, ids, context=None):
+ for l in self.browse(cr, uid, ids, context=context):
+ if l.account_id.currency_id:
+ if not l.currency_id or not l.currency_id.id == l.account_id.currency_id.id:
+ return False
+ return True
+
_constraints = [
(_check_no_view, 'You can not create move line on view account.', ['account_id']),
(_check_no_closed, 'You can not create move line on closed account.', ['account_id']),
- (_check_company_id, 'Company must be same for its related account and period.',['company_id'] ),
- (_check_date, 'The date of your Journal Entry is not in the defined period!',['date'] ),
+ (_check_company_id, 'Company must be same for its related account and period.', ['company_id']),
+ (_check_date, 'The date of your Journal Entry is not in the defined period!', ['date']),
+ (_check_currency, 'The selected account of your Journal Entry must receive a value in its secondary currency', ['currency_id']),
]
#TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id
company_list.append(line.company_id.id)
for line in self.browse(cr, uid, ids, context=context):
- company_currency_id = line.company_id.currency_id
+ if line.account_id.currency_id:
+ currency_id = line.account_id.currency_id
+ else:
+ currency_id = line.company_id.currency_id
if line.reconcile_id:
raise osv.except_osv(_('Warning'), _('Already Reconciled!'))
if line.reconcile_partial_id:
if not line2.reconcile_id:
if line2.id not in merges:
merges.append(line2.id)
- total += (line2.debit or 0.0) - (line2.credit or 0.0)
+ if line2.account_id.currency_id:
+ total += line2.amount_currency
+ else:
+ total += (line2.debit or 0.0) - (line2.credit or 0.0)
merges_rec.append(line.reconcile_partial_id.id)
else:
unmerge.append(line.id)
- total += (line.debit or 0.0) - (line.credit or 0.0)
- if self.pool.get('res.currency').is_zero(cr, uid, company_currency_id, total):
+ if line.account_id.currency_id:
+ total += line.amount_currency
+ else:
+ total += (line.debit or 0.0) - (line.credit or 0.0)
+ if self.pool.get('res.currency').is_zero(cr, uid, currency_id, total):
res = self.reconcile(cr, uid, merges+unmerge, context=context, writeoff_acc_id=writeoff_acc_id, writeoff_period_id=writeoff_period_id, writeoff_journal_id=writeoff_journal_id)
return res
r_id = move_rec_obj.create(cr, uid, {
f.set("invisible", "context.get('journal_id', False)")
elif field in ('period_id',):
f.set("invisible", "context.get('period_id', False)")
- else:
- f.set('invisible', "context.get('visible_id') not in %s" % (fields.get(field)))
orm.setup_modifiers(f, fields_get[field], context=context,
in_tree_view=True)
m = move_obj.browse(cr, uid, vals['move_id'])
context['journal_id'] = m.journal_id.id
context['period_id'] = m.period_id.id
+ #we need to treat the case where a value is given in the context for period_id as a string
+ if 'period_id' not in context or not isinstance(context.get('period_id', ''), (int, long)):
+ period_candidate_ids = self.pool.get('account.period').name_search(cr, uid, name=context.get('period_id',''))
+ if len(period_candidate_ids) != 1:
+ raise osv.except_osv(_('Encoding error'), _('No period found or period given is ambigous.'))
+ context['period_id'] = period_candidate_ids[0][0]
+ if not context.get('journal_id', False) and context.get('search_default_journal_id', False):
+ context['journal_id'] = context.get('search_default_journal_id')
self._update_journal_check(cr, uid, context['journal_id'], context['period_id'], context)
move_id = vals.get('move_id', False)
journal = journal_obj.browse(cr, uid, context['journal_id'], context=context)
base_sign = 'base_sign'
tax_sign = 'tax_sign'
tmp_cnt = 0
- for tax in tax_obj.compute_all(cr, uid, [tax_id], total, 1.00).get('taxes'):
+ for tax in tax_obj.compute_all(cr, uid, [tax_id], total, 1.00, force_excluded=True).get('taxes'):
#create the base movement
if tmp_cnt == 0:
if tax[base_code]:
else:
data = {
'move_id': vals['move_id'],
- 'journal_id': vals['journal_id'],
- 'period_id': vals['period_id'],
'name': tools.ustr(vals['name'] or '') + ' ' + tools.ustr(tax['name'] or ''),
'date': vals['date'],
'partner_id': vals.get('partner_id',False),
#create the VAT movement
data = {
'move_id': vals['move_id'],
- 'journal_id': vals['journal_id'],
- 'period_id': vals['period_id'],
'name': tools.ustr(vals['name'] or '') + ' ' + tools.ustr(tax['name'] or ''),
'date': vals['date'],
'partner_id': vals.get('partner_id',False),