+ def account_move_get(self, cr, uid, expense_id, context=None):
+ '''
+ This method prepare the creation of the account move related to the given expense.
+
+ :param expense_id: Id of voucher for which we are creating account_move.
+ :return: mapping between fieldname and value of account move to create
+ :rtype: dict
+ '''
+ journal_obj = self.pool.get('account.journal')
+ expense = self.browse(cr, uid, expense_id, context=context)
+ company_id = expense.company_id.id
+ date = expense.date_confirm
+ ref = expense.name
+ journal_id = False
+ if expense.journal_id:
+ journal_id = expense.journal_id.id
+ else:
+ journal_id = journal_obj.search(cr, uid, [('type', '=', 'purchase'), ('company_id', '=', company_id)])
+ if not journal_id:
+ raise osv.except_osv(_('Error!'), _("No expense journal found. Please make sure you have a journal with type 'purchase' configured."))
+ journal_id = journal_id[0]
+ return self.pool.get('account_move').account_move_prepare(cr, uid, journal_id, date=date, ref=ref, company_id=company_id, context=context)
+
+ def line_get_convert(self, cr, uid, x, part, date, context=None):
+ #partner_id = self.pool.get('res.partner')._find_partner(part)
+ partner_id = part.id
+ return {
+ 'date_maturity': x.get('date_maturity', False),
+ 'partner_id': partner_id,
+ 'name': x['name'][:64],
+ 'date': date,
+ 'debit': x['price']>0 and x['price'],
+ 'credit': x['price']<0 and -x['price'],
+ 'account_id': x['account_id'],
+ 'analytic_lines': x.get('analytic_lines', False),
+ 'amount_currency': x['price']>0 and abs(x.get('amount_currency', False)) or -abs(x.get('amount_currency', False)),
+ 'currency_id': x.get('currency_id', False),
+ 'tax_code_id': x.get('tax_code_id', False),
+ 'tax_amount': x.get('tax_amount', False),
+ 'ref': x.get('ref', False),
+ 'quantity': x.get('quantity',1.00),
+ 'product_id': x.get('product_id', False),
+ 'product_uom_id': x.get('uos_id', False),
+ 'analytic_account_id': x.get('account_analytic_id', False),
+ }
+
+ def compute_expense_totals(self, cr, uid, exp, company_currency, ref, account_move_lines, context=None):
+ '''
+ internal method used for computation of total amount of an expense in the company currency and
+ in the expense currency, given the account_move_lines that will be created. It also do some small
+ transformations at these account_move_lines (for multi-currency purposes)
+
+ :param account_move_lines: list of dict
+ :rtype: tuple of 3 elements (a, b ,c)
+ a: total in company currency
+ b: total in hr.expense currency
+ c: account_move_lines potentially modified
+ '''
+ cur_obj = self.pool.get('res.currency')
+ if context is None:
+ context={}
+ context.update({'date': exp.date_confirm or time.strftime('%Y-%m-%d')})
+ total = 0.0
+ total_currency = 0.0
+ for i in account_move_lines:
+ if exp.currency_id.id != company_currency:
+ i['currency_id'] = exp.currency_id.id
+ i['amount_currency'] = i['price']
+ i['price'] = cur_obj.compute(cr, uid, exp.currency_id.id,
+ company_currency, i['price'],
+ context=context)
+ else:
+ i['amount_currency'] = False
+ i['currency_id'] = False
+ total -= i['price']
+ total_currency -= i['amount_currency'] or i['price']
+ return total, total_currency, account_move_lines
+
+
+ def action_move_create(self, cr, uid, ids, context=None):
+ move_obj = self.pool.get('account.move')