24
24
import decimal_precision as dp
27
28
from osv import fields, osv, orm
29
29
from tools.translate import _
31
31
class account_invoice(osv.osv):
57
57
('company_id', '=', company_id),
58
58
('refund_journal', '=', refund_journal.get(type_inv, False))],
60
return res and res[0] or False
65
62
def _get_currency(self, cr, uid, context=None):
66
63
user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, [uid])[0]
67
64
if user.company_id:
68
65
return user.company_id.currency_id.id
70
return pooler.get_pool(cr.dbname).get('res.currency').search(cr, uid, [('rate','=',1.0)])[0]
66
return pooler.get_pool(cr.dbname).get('res.currency').search(cr, uid, [('rate','=', 1.0)])[0]
72
68
def _get_journal_analytic(self, cr, uid, type_inv, context=None):
73
69
type2journal = {'out_invoice': 'sale', 'in_invoice': 'purchase', 'out_refund': 'sale', 'in_refund': 'purchase'}
134
130
result = inv.amount_total - amount
135
131
# Use is_zero function to avoid rounding trouble => should be fixed into ORM
136
132
res[inv.id] = not self.pool.get('res.currency').is_zero(cr, uid, inv.company_id.currency_id, result) and result or 0.0
140
135
# Give Journal Items related to the payment reconciled to this invoice
359
354
res['arch'] = etree.tostring(doc)
357
def get_log_context(self, cr, uid, context=None):
360
mob_obj = self.pool.get('ir.model.data')
361
res = mob_obj.get_object_reference(cr, uid, 'account', 'invoice_form') or False
362
view_id = res and res[1] or False
363
context.update({'view_id': view_id})
362
366
def create(self, cr, uid, vals, context=None):
364
370
res = super(account_invoice, self).create(cr, uid, vals, context)
365
371
for inv_id, name in self.name_get(cr, uid, [res], context=context):
373
if vals.get('type', 'in_invoice') in ('out_invoice', 'out_refund'):
374
ctx = self.get_log_context(cr, uid, context=ctx)
366
375
message = _("Invoice '%s' is waiting for validation.") % name
367
self.log(cr, uid, inv_id, message)
376
self.log(cr, uid, inv_id, message, context=ctx)
369
378
except Exception, e:
370
379
if '"journal_id" viol' in e.args[0]:
491
500
res = {'value':{'date_due': pterm_list[-1]}}
493
502
raise osv.except_osv(_('Data Insufficient !'), _('The Payment Term of Supplier does not have Payment Term Lines(Computation) defined !'))
497
505
def onchange_invoice_line(self, cr, uid, ids, lines):
506
514
obj_journal = self.pool.get('account.journal')
515
account_obj = self.pool.get('account.account')
516
inv_line_obj = self.pool.get('account.invoice.line')
507
517
if company_id and part_id and type:
509
519
partner_obj = self.pool.get('res.partner').browse(cr,uid,part_id)
539
548
if not result_id:
540
549
raise osv.except_osv(_('Configuration Error !'),
541
550
_('Can not find account chart for this company in invoice line account, Please Create account.'))
542
self.pool.get('account.invoice.line').write(cr, uid, [line.id], {'account_id': result_id[0]})
551
inv_line_obj.write(cr, uid, [line.id], {'account_id': result_id[0]})
545
554
for inv_line in invoice_line:
581
590
val['currency_id'] = company.currency_id.id
583
return {'value': val, 'domain': dom }
592
return {'value': val, 'domain': dom}
585
594
# go from canceled state to draft state
586
595
def action_cancel_draft(self, cr, uid, ids, *args):
967
975
'analytic_account_id':x.get('account_analytic_id',False),
970
def action_number(self, cr, uid, ids, *args):
978
def action_number(self, cr, uid, ids, context=None):
971
981
#TODO: not correct fix but required a frech values before reading it.
972
982
self.write(cr, uid, ids, {})
981
991
self.write(cr, uid, ids, {'internal_number':number})
983
993
if invtype in ('in_invoice', 'in_refund'):
995
ref = self._convert_ref(cr, uid, number)
986
999
ref = self._convert_ref(cr, uid, number)
1000
1013
for inv_id, name in self.name_get(cr, uid, [id]):
1014
ctx = context.copy()
1015
if obj_inv.type in ('out_invoice', 'out_refund'):
1016
ctx = self.get_log_context(cr, uid, context=ctx)
1001
1017
message = _('Invoice ') + " '" + name + "' "+ _("is validated.")
1002
self.log(cr, uid, inv_id, message)
1018
self.log(cr, uid, inv_id, message, context=ctx)
1006
1021
def action_cancel(self, cr, uid, ids, *args):
1489
1504
taxes = self.pool.get('account.account').browse(cr, uid, account_id).tax_ids
1490
1505
fpos = fposition_id and self.pool.get('account.fiscal.position').browse(cr, uid, fposition_id) or False
1491
1506
res = self.pool.get('account.fiscal.position').map_tax(cr, uid, fpos, taxes)
1492
r = {'value':{'invoice_line_tax_id': res}}
1507
return {'value':{'invoice_line_tax_id': res}}
1494
1509
account_invoice_line()
1496
1511
class account_invoice_tax(osv.osv):
1522
1537
'amount': fields.float('Amount', digits_compute=dp.get_precision('Account')),
1523
1538
'manual': fields.boolean('Manual'),
1524
1539
'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of invoice tax."),
1526
1540
'base_code_id': fields.many2one('account.tax.code', 'Base Code', help="The account basis of the tax declaration."),
1527
1541
'base_amount': fields.float('Base Code Amount', digits_compute=dp.get_precision('Account')),
1528
1542
'tax_code_id': fields.many2one('account.tax.code', 'Tax Code', help="The tax basis of the tax declaration."),
1561
1575
_order = 'sequence'
1563
'manual': lambda *a: 1,
1564
'base_amount': lambda *a: 0.0,
1565
'tax_amount': lambda *a: 0.0,
1567
1581
def compute(self, cr, uid, invoice_id, context={}):
1568
1582
tax_grouped = {}