ACCOUNT, HR_TIMESHEET_INVOICE: add to_invoice to supplier invoice
bzr revid: ced-ee7364eccbfd449150f3ff9211ba0d4d4f972c17
This commit is contained in:
parent
b903472529
commit
7f462a3b63
|
@ -292,6 +292,33 @@ class account_invoice(osv.osv):
|
|||
ait_obj.create(cr, uid, compute_taxes[key])
|
||||
return True
|
||||
|
||||
def _get_analityc_lines(self, cr, uid, id):
|
||||
inv = self.browse(cr, uid, [id])[0]
|
||||
cur_obj = self.pool.get('res.currency')
|
||||
|
||||
company_currency = inv.company_id.currency_id.id
|
||||
if inv.type in ('out_invoice', 'in_refund'):
|
||||
sign = 1
|
||||
else:
|
||||
sign = -1
|
||||
|
||||
iml = self.pool.get('account.invoice.line').move_line_get(cr, uid, inv.id)
|
||||
for il in iml:
|
||||
if il['account_analytic_id']:
|
||||
il['analytic_lines'] = [(0,0, {
|
||||
'name': il['name'],
|
||||
'date': inv['date_invoice'],
|
||||
'account_id': il['account_analytic_id'],
|
||||
'unit_amount': il['quantity'],
|
||||
'amount': cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, il['price'], context={'date': inv.date_invoice}) * sign,
|
||||
'product_id': il['product_id'],
|
||||
'product_uom_id': il['uos_id'],
|
||||
'general_account_id': il['account_id'],
|
||||
'journal_id': self._get_journal_analytic(cr, uid, inv.type),
|
||||
'ref': inv['number'],
|
||||
})]
|
||||
return iml
|
||||
|
||||
def action_move_create(self, cr, uid, ids, *args):
|
||||
ait_obj = self.pool.get('account.invoice.tax')
|
||||
cur_obj = self.pool.get('res.currency')
|
||||
|
@ -305,27 +332,8 @@ class account_invoice(osv.osv):
|
|||
# create the analytical lines
|
||||
line_ids = self.read(cr, uid, [inv.id], ['invoice_line'])[0]['invoice_line']
|
||||
ils = self.pool.get('account.invoice.line').read(cr, uid, line_ids)
|
||||
if inv.type in ('out_invoice', 'in_refund'):
|
||||
sign = 1
|
||||
else:
|
||||
sign = -1
|
||||
# one move line per invoice line
|
||||
iml = self.pool.get('account.invoice.line').move_line_get(cr, uid, inv.id)
|
||||
for il in iml:
|
||||
if il['account_analytic_id']:
|
||||
il['analytic_lines'] = [(0,0, {
|
||||
'name': il['name'],
|
||||
'date': inv['date_invoice'],
|
||||
'account_id': il['account_analytic_id'],
|
||||
'unit_amount': il['quantity'],
|
||||
'amount': cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, il['price'], context={'date': inv.date_invoice}) * sign,
|
||||
'product_id': il['product_id'],
|
||||
'product_uom_id': il['uos_id'],
|
||||
'general_account_id': il['account_id'],
|
||||
'journal_id': self._get_journal_analytic(cr, uid, inv.type),
|
||||
'ref': inv['number'],
|
||||
})]
|
||||
|
||||
iml = self._get_analityc_lines(cr, uid, inv.id)
|
||||
# check if taxes are all computed
|
||||
compute_taxes = ait_obj.compute(cr, uid, inv.id)
|
||||
if not inv.tax_line:
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
{
|
||||
"name" : "Invoice on timesheet",
|
||||
"name" : "Invoice on analytic lines",
|
||||
"version" : "1.0",
|
||||
"author" : "Tiny",
|
||||
"category" : "Generic Modules/Human Resources",
|
||||
"website" : "http://tinyerp.com/module_hr.html",
|
||||
"category" : "Generic Modules/Accounting",
|
||||
"website" : "http://tinyerp.com/",
|
||||
"depends" : ["account",'hr_timesheet'],
|
||||
"description": """
|
||||
Module to generate invoices based on costs (human ressources, expenses, ...).
|
||||
|
|
|
@ -74,8 +74,7 @@ class account_analytic_line(osv.osv):
|
|||
}
|
||||
account_analytic_line()
|
||||
|
||||
class account_analytic_line(osv.osv):
|
||||
_name = "hr.analytic.timesheet"
|
||||
class hr_analytic_timesheet(osv.osv):
|
||||
_inherit = "hr.analytic.timesheet"
|
||||
def on_change_account_id(self, cr, uid, ids, account_id):
|
||||
res = super(account_analytic_line,self).on_change_account_id(cr, uid, ids, account_id)
|
||||
|
@ -85,5 +84,20 @@ class account_analytic_line(osv.osv):
|
|||
st = self.pool.get('account.analytic.account').browse(cr, uid, account_id).to_invoice.id
|
||||
res['value']['to_invoice'] = st or False
|
||||
return res
|
||||
account_analytic_line()
|
||||
hr_analytic_timesheet()
|
||||
|
||||
class account_invoice(osv.osv):
|
||||
_inherit = "account.invoice"
|
||||
|
||||
def _get_analityc_lines(self, cr, uid, id):
|
||||
iml = super(account_invoice, self)._get_analityc_lines(cr, uid, id)
|
||||
|
||||
inv = self.browse(cr, uid, [id])[0]
|
||||
if inv.type == 'in_invoice':
|
||||
for il in iml:
|
||||
if il['account_analytic_id']:
|
||||
to_invoice = self.pool.get('account.analytic.account').read(cr, uid, [il['account_analytic_id']], ['to_invoice'])[0]['to_invoice']
|
||||
if to_invoice:
|
||||
il['analytic_lines'][0][2]['to_invoice'] = to_invoice[0]
|
||||
return iml
|
||||
account_invoice()
|
||||
|
|
Loading…
Reference in New Issue