- voucher = {
- 'name': exp.name,
- 'reference': sequence_obj.get(cr, uid, 'hr.expense.invoice'),
- 'account_id': acc,
- 'type': 'purchase',
- 'partner_id': exp.employee_id.address_home_id.id,
- 'company_id': company_id,
- 'line_ids': lines,
- 'amount': total
- }
- journal = False
- if exp.journal_id:
- voucher['journal_id'] = exp.journal_id.id
- journal = exp.journal_id
- else:
- journal_id = voucher_obj._get_journal(cr, uid, context={'type': 'purchase', 'company_id': company_id})
- if journal_id:
- voucher['journal_id'] = journal_id
- journal = account_journal.browse(cr, uid, journal_id, context=context)
- voucher_id = voucher_obj.create(cr, uid, voucher, context)
- self.write(cr, uid, [exp.id], {'voucher_id': voucher_id, 'state': 'receipted'}, context=context)
- res = voucher_id
+ iml.append({
+ 'type': 'dest',
+ 'name': '/',
+ 'price': total,
+ 'account_id': acc,
+ 'date_maturity': exp.date_confirm,
+ 'amount_currency': diff_currency_p and total_currency or False,
+ 'currency_id': diff_currency_p and exp.currency_id.id or False,
+ 'ref': exp.name
+ })
+
+ lines = map(lambda x:(0,0,self.line_get_convert(cr, uid, x, exp.user_id.partner_id, exp.date_confirm, context=context)),iml)
+ move_obj.write(cr, uid, [move_id], {'line_id': lines}, context=context)
+ self.write(cr, uid, ids, {'account_move_id': move_id, 'state': 'done'}, context=context)
+ return True
+
+ def move_line_get(self, cr, uid, expense_id, context=None):
+ res = []
+ tax_obj = self.pool.get('account.tax')
+ cur_obj = self.pool.get('res.currency')
+ if context is None:
+ context = {}
+ exp = self.browse(cr, uid, expense_id, context=context)
+ company_currency = exp.company_id.currency_id.id
+
+ for line in exp.line_ids:
+ mres = self.move_line_get_item(cr, uid, line, context)
+ if not mres:
+ continue
+ res.append(mres)
+ tax_code_found= False
+
+ #Calculate tax according to default tax on product
+
+ #Taken from product_id_onchange in account.invoice
+ if line.product_id:
+ fposition_id = False
+ fpos_obj = self.pool.get('account.fiscal.position')
+ fpos = fposition_id and fpos_obj.browse(cr, uid, fposition_id, context=context) or False
+ product = line.product_id
+ taxes = product.supplier_taxes_id
+ #If taxes are not related to the product, maybe they are in the account
+ if not taxes:
+ a = product.property_account_expense.id #Why is not there a check here?
+ if not a:
+ a = product.categ_id.property_account_expense_categ.id
+ a = fpos_obj.map_account(cr, uid, fpos, a)
+ taxes = a and self.pool.get('account.account').browse(cr, uid, a, context=context).tax_ids or False
+ tax_id = fpos_obj.map_tax(cr, uid, fpos, taxes)
+ if not taxes:
+ taxes = []
+ #Calculating tax on the line and creating move?
+ for tax in tax_obj.compute_all(cr, uid, taxes,
+ line.unit_amount ,
+ line.unit_quantity, line.product_id,
+ exp.user_id.partner_id)['taxes']:
+ tax_code_id = tax['base_code_id']
+ tax_amount = line.total_amount * tax['base_sign']
+ if tax_code_found:
+ if not tax_code_id:
+ continue
+ res.append(self.move_line_get_item(cr, uid, line, context))
+ res[-1]['price'] = 0.0
+ res[-1]['account_analytic_id'] = False
+ elif not tax_code_id:
+ continue
+ tax_code_found = True
+ res[-1]['tax_code_id'] = tax_code_id
+ res[-1]['tax_amount'] = cur_obj.compute(cr, uid, exp.currency_id.id, company_currency, tax_amount, context={'date': exp.date_confirm})
+
+ #Will create the tax here as we don't have the access
+ assoc_tax = {
+ 'type':'tax',
+ 'name':tax['name'],
+ 'price_unit': tax['price_unit'],
+ 'quantity': 1,
+ 'price': tax['amount'] * tax['base_sign'] or 0.0,
+ 'account_id': tax['account_collected_id'],
+ 'tax_code_id': tax['tax_code_id'],
+ 'tax_amount': tax['amount'] * tax['base_sign'],
+ }
+ res.append(assoc_tax)