class account_move_line(osv.osv):
_inherit = 'account.move.line'
+
def _unreconciled(self, cr, uid, ids, prop, unknow_none, context):
- res={}
+ res = {}
for line in self.browse(cr, uid, ids, context=context):
res[line.id] = line.debit - line.credit
if line.reconcile_partial_id:
_columns = {
'amount_unreconciled': fields.function(_unreconciled, method=True, string='Unreconciled Amount'),
}
+
account_move_line()
class account_voucher(osv.osv):
+
def _get_type(self, cr, uid, ids, context={}):
return context.get('type', False)
journal_id = context.get('journal_id', False)
if journal_id:
journal = journal_pool.browse(cr, uid, journal_id)
- currency_id = journal.company_id.currency_id.id
+# currency_id = journal.company_id.currency_id.id
if journal.currency:
- currency_id = journal.currency.id
+ return journal.currency.id
return False
def _get_partner(self, cr, uid, context={}):
return context.get('narration', False)
def name_get(self, cr, uid, ids, context=None):
- if not len(ids):
+ if not ids:
return []
return [(r['id'], (str("%.2f" % r['amount']) or '')) for r in self.read(cr, uid, ids, ['amount'], context, load='_classic_write')]
def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):
- res = super(account_voucher,self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
+ if not view_id and context.get('invoice_type', False):
+ mod_obj = self.pool.get('ir.model.data')
+ if context.get('invoice_type') in ('out_invoice', 'out_refund'):
+ result = mod_obj._get_id(cr, uid, 'account_voucher', 'view_vendor_receipt_form')
+ else:
+ result = mod_obj._get_id(cr, uid, 'account_voucher', 'view_vendor_payment_form')
+ result = mod_obj.read(cr, uid, [result], ['res_id'], context=context)[0]['res_id']
+ view_id = result
+ res = super(account_voucher, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
doc = etree.XML(res['arch'])
nodes = doc.xpath("//field[@name='partner_id']")
if context.get('type', 'sale') in ('purchase', 'payment'):
'state': 'draft',
'pay_now': 'pay_later',
'name': '',
- 'date' : time.strftime('%Y-%m-%d'),
+ 'date': time.strftime('%Y-%m-%d'),
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.voucher',context=c),
'tax_id': _get_tax,
}
total_tax = 0.0
if not tax[0].price_include:
- for tax_line in tax_pool.compute_all(cr, uid, tax, voucher_amount, 1).get('taxes',[]):
- total_tax += tax_line.get('amount')
+ for tax_line in tax_pool.compute_all(cr, uid, tax, voucher_amount, 1).get('taxes', []):
+ total_tax += tax_line.get('amount', 0.0)
total += total_tax
else:
- line_ids2 = []
for line in voucher.line_ids:
line_total = 0.0
line_tax = 0.0
- for tax_line in tax_pool.compute_all(cr, uid, tax, line.untax_amount or line.amount, 1).get('taxes',[]):
- line_tax += tax_line.get('amount')
+ for tax_line in tax_pool.compute_all(cr, uid, tax, line.untax_amount or line.amount, 1).get('taxes', []):
+ line_tax += tax_line.get('amount', 0.0)
line_total += tax_line.get('price_unit')
total_tax += line_tax
untax_amount = line.untax_amount or line.amount
tax_pool = self.pool.get('account.tax')
partner_pool = self.pool.get('res.partner')
position_pool = self.pool.get('account.fiscal.position')
- voucher_line_pool = self.pool.get('account.voucher.line')
res = {
- 'tax_amount':False,
- 'amount':False,
+ 'tax_amount': False,
+ 'amount': False,
}
- voucher_total_tax = 0.0
voucher_total = 0.0
voucher_line_ids = []
total = 0.0
total_tax = 0.0
-
for line in line_ids:
line_amount = 0.0
- line_amount = line[2].get('amount')
+ line_amount = line[2] and line[2].get('amount',0.0) or 0.0
voucher_line_ids += [line[1]]
voucher_total += line_amount
tax = tax_pool.browse(cr, uid, taxes)
if not tax[0].price_include:
- for tax_line in tax_pool.compute_all(cr, uid, tax, voucher_total, 1).get('taxes',[]):
+ for tax_line in tax_pool.compute_all(cr, uid, tax, voucher_total, 1).get('taxes', []):
total_tax += tax_line.get('amount')
total += total_tax
return default
- def onchange_partner_id(self, cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, context={}):
+ def onchange_partner_id(self, cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, context=None):
"""price
Returns a dict that contains new values and context
if not journal_id:
return {}
+ if context is None:
+ context = {}
currency_pool = self.pool.get('res.currency')
- move_pool = self.pool.get('account.move')
line_pool = self.pool.get('account.voucher.line')
move_line_pool = self.pool.get('account.move.line')
partner_pool = self.pool.get('res.partner')
return default
if not partner_id and ids:
- line_ids = line_pool.search(cr, uid, [('voucher_id','=',ids[0])])
+ line_ids = line_pool.search(cr, uid, [('voucher_id', '=', ids[0])])
if line_ids:
line_pool.unlink(cr, uid, line_ids)
return default
account_id = journal.default_credit_account_id.id or journal.default_debit_account_id.id
default['value']['account_id'] = account_id
+
if journal.type not in ('cash', 'bank'):
return default
account_type = 'receivable'
if not context.get('move_line_ids', False):
- ids = move_line_pool.search(cr, uid, [('account_id.type','=', account_type), ('reconcile_id','=', False), ('partner_id','=',partner_id)], context=context)
+ ids = move_line_pool.search(cr, uid, [('account_id.type', '=', account_type), ('reconcile_id', '=', False), ('partner_id', '=', partner_id)], context=context)
else:
ids = context['move_line_ids']
ids.reverse()
default['value']['pre_line'] = 1
elif ttype == 'receipt' and len(default['value']['line_dr_ids']) > 0:
default['value']['pre_line'] = 1
+
return default
def onchange_date(self, cr, user, ids, date, context={}):
@return: Returns a dict which contains new values, and context
"""
period_pool = self.pool.get('account.period')
- pids = period_pool.search(cr, user, [('date_start','<=',date), ('date_stop','>=',date)])
+ pids = period_pool.search(cr, user, [('date_start', '<=', date), ('date_stop', '>=', date)])
if not pids:
return {}
return {
def proforma_voucher(self, cr, uid, ids, context=None):
self.action_move_line_create(cr, uid, ids, context=context)
return True
+ #return {'type' : 'ir.actions.act_window_close' }
+
def action_cancel_draft(self, cr, uid, ids, context={}):
wf_service = netsvc.LocalService("workflow")
def cancel_voucher(self, cr, uid, ids, context={}):
reconcile_pool = self.pool.get('account.move.reconcile')
move_pool = self.pool.get('account.move')
- voucher_line_pool = self.pool.get('account.voucher.line')
for voucher in self.browse(cr, uid, ids):
recs = []
context = {}
move_pool = self.pool.get('account.move')
move_line_pool = self.pool.get('account.move.line')
- analytic_pool = self.pool.get('account.analytic.line')
currency_pool = self.pool.get('res.currency')
- invoice_pool = self.pool.get('account.invoice')
+ tax_obj = self.pool.get('account.tax')
for inv in self.browse(cr, uid, ids):
if inv.move_id:
continue
raise osv.except_osv(_('Error !'), _('Please define a sequence on the journal !'))
move = {
- 'name' : name,
+ 'name': name,
'journal_id': inv.journal_id.id,
- 'narration' : inv.narration,
+ 'narration': inv.narration,
'date':inv.date,
'ref':inv.reference,
'period_id': inv.period_id and inv.period_id.id or False
credit = 0.0
move_line = {
- 'name':inv.name or '/',
- 'debit':debit,
- 'credit':credit,
- 'account_id':inv.account_id.id,
- 'move_id':move_id ,
- 'journal_id':inv.journal_id.id,
- 'period_id':inv.period_id.id,
- 'partner_id':inv.partner_id.id,
- 'currency_id':inv.currency_id.id,
- 'amount_currency':inv.amount,
- 'date':inv.date,
- 'date_maturity':inv.date_due
+ 'name': inv.name or '/',
+ 'debit': debit,
+ 'credit': credit,
+ 'account_id': inv.account_id.id,
+ 'move_id': move_id,
+ 'journal_id': inv.journal_id.id,
+ 'period_id': inv.period_id.id,
+ 'partner_id': inv.partner_id.id,
+ 'currency_id': inv.currency_id.id,
+ 'amount_currency': inv.amount,
+ 'date': inv.date,
+ 'date_maturity': inv.date_due
}
if (debit == 0.0 or credit == 0.0 or debit+credit > 0) and (debit > 0.0 or credit > 0.0):
if not line.amount:
continue
amount = currency_pool.compute(cr, uid, inv.currency_id.id, company_currency, line.amount)
-
move_line = {
- 'journal_id':inv.journal_id.id,
- 'period_id':inv.period_id.id,
- 'name':line.name and line.name or '/',
- 'account_id':line.account_id.id,
- 'move_id':move_id,
- 'partner_id':inv.partner_id.id,
- 'currency_id':inv.currency_id.id,
- 'amount_currency':line.amount,
- 'analytic_account_id':line.account_analytic_id and line.account_analytic_id.id or False,
- 'quantity':1,
- 'credit':0.0,
- 'debit':0.0,
- 'date':inv.date
+ 'journal_id': inv.journal_id.id,
+ 'period_id': inv.period_id.id,
+ 'name': line.name and line.name or '/',
+ 'account_id': line.account_id.id,
+ 'move_id': move_id,
+ 'partner_id': inv.partner_id.id,
+ 'currency_id': inv.currency_id.id,
+ 'amount_currency': line.amount,
+ 'analytic_account_id': line.account_analytic_id and line.account_analytic_id.id or False,
+ 'quantity': 1,
+ 'credit': 0.0,
+ 'debit': 0.0,
+ 'date': inv.date
}
if amount < 0:
amount = -amount
if inv.tax_id and inv.type in ('sale', 'purchase'):
move_line.update({
- 'account_tax_id':inv.tax_id.id,
+ 'account_tax_id': inv.tax_id.id,
})
+ if move_line.get('account_tax_id', False):
+ tax_data = tax_obj.browse(cr, uid, [move_line['account_tax_id']], context=context)[0]
+ if not (tax_data.base_code_id and tax_data.tax_code_id):
+ raise osv.except_osv(_('No Account Base Code and Account Tax Code!'),_("You have to configure account base code and account tax code on the '%s' tax!") % (tax_data.name))
master_line = move_line_pool.create(cr, uid, move_line)
if line.move_line_id.id:
rec_ids = [master_line, line.move_line_id.id]
if not self.pool.get('res.currency').is_zero(cr, uid, inv.currency_id, line_total):
diff = line_total
move_line = {
- 'name':name,
- 'account_id':False,
- 'move_id':move_id ,
- 'partner_id':inv.partner_id.id,
- 'date':inv.date,
- 'credit':diff>0 and diff or 0.0,
- 'debit':diff<0 and -diff or 0.0,
+ 'name': name,
+ 'account_id': False,
+ 'move_id': move_id,
+ 'partner_id': inv.partner_id.id,
+ 'date': inv.date,
+ 'credit': diff > 0 and diff or 0.0,
+ 'debit': diff < 0 and -diff or 0.0,
}
account_id = False
if inv.type in ('sale', 'receipt'):
else:
account_id = inv.partner_id.property_account_payable.id
move_line['account_id'] = account_id
- move_line_id = move_line_pool.create(cr, uid, move_line)
+
+ move_line_pool.create(cr, uid, move_line)
self.write(cr, uid, [inv.id], {
'move_id': move_id,
def copy(self, cr, uid, id, default={}, context=None):
default.update({
- 'state':'draft',
- 'number':False,
- 'move_id':False,
- 'line_cr_ids':False,
- 'line_dr_ids':False,
- 'reference':False
+ 'state': 'draft',
+ 'number': False,
+ 'move_id': False,
+ 'line_cr_ids': False,
+ 'line_dr_ids': False,
+ 'reference': False
})
if 'date' not in default:
default['date'] = time.strftime('%Y-%m-%d')
'company_id': fields.related('voucher_id','company_id', relation='res.company', string='Company', store=True),
}
_defaults = {
- 'name': lambda *a: ''
+ 'name': ''
}
def onchange_move_line_id(self, cr, user, ids, move_line_id, context={}):
move_line_pool = self.pool.get('account.move.line')
if move_line_id:
move_line = move_line_pool.browse(cr, user, move_line_id, context=context)
- move_id = move_line.move_id.id
if move_line.credit:
- ttype='dr'
- amount = move_line.credit
+ ttype = 'dr'
else:
- ttype='cr'
- amount = move_line.debit
+ ttype = 'cr'
account_id = move_line.account_id.id
res.update({
'account_id':account_id,
class account_bank_statement(osv.osv):
_inherit = 'account.bank.statement'
+ def button_cancel(self, cr, uid, ids, context=None):
+ for st in self.browse(cr, uid, ids, context):
+ voucher_ids = []
+ for line in st.line_ids:
+ if line.voucher_id:
+ voucher_ids.append(line.voucher_id.id)
+ self.pool.get('account.voucher').cancel_voucher(cr, uid, voucher_ids, context)
+ return super(account_bank_statement, self).button_cancel(cr, uid, ids, context=context)
+
def create_move_from_st_line(self, cr, uid, st_line_id, company_currency_id, next_number, context=None):
voucher_obj = self.pool.get('account.voucher')
wf_service = netsvc.LocalService("workflow")
- st_line = self.pool.get('account.bank.statement.line').browse(cr, uid, st_line_id, context=context)
+ bank_st_line_obj = self.pool.get('account.bank.statement.line')
+ st_line = bank_st_line_obj.browse(cr, uid, st_line_id, context=context)
if st_line.voucher_id:
voucher_obj.write(cr, uid, [st_line.voucher_id.id], {'number': next_number}, context=context)
+ if st_line.voucher_id.state == 'cancel':
+ voucher_obj.action_cancel_draft(cr, uid, [st_line.voucher_id.id], context=context)
wf_service.trg_validate(uid, 'account.voucher', st_line.voucher_id.id, 'proforma_voucher', cr)
- return self.pool.get('account.move.line').write(cr, uid, [x.id for x in st_line.voucher_id.move_ids], {'statement_id': st_line.statement_id.id}, context=context)
- return super(account_bank_statement, self).create_move_from_st_line(cr, uid, st_line, company_currency_id, next_number, context=context)
+
+ v = voucher_obj.browse(cr, uid, st_line.voucher_id.id, context=context)
+ bank_st_line_obj.write(cr, uid, [st_line_id], {
+ 'move_ids': [(4, v.move_id.id, False)]
+ })
+
+ return self.pool.get('account.move.line').write(cr, uid, [x.id for x in v.move_ids], {'statement_id': st_line.statement_id.id}, context=context)
+ return super(account_bank_statement, self).create_move_from_st_line(cr, uid, st_line.id, company_currency_id, next_number, context=context)
account_bank_statement()
if not ids:
return {}
- res_currency_obj = self.pool.get('res.currency')
res = {}
- company_currency_id = False
+# company_currency_id = False
for line in self.browse(cursor, user, ids, context=context):
# if not company_currency_id:
# company_currency_id = line.company_id.id
statement_line = self.browse(cr, uid, ids, context)
unlink_ids = []
for st_line in statement_line:
- unlink_ids.append(st_line.voucher_id.id)
+ if st_line.voucher_id:
+ unlink_ids.append(st_line.voucher_id.id)
self.pool.get('account.voucher').unlink(cr, uid, unlink_ids, context=context)
return super(account_bank_statement_line, self).unlink(cr, uid, ids, context=context)
account_bank_statement_line()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:=======