-
  In order to test hr_timesheet_invoice in OpenERP, I create account line to manage invoice based on costs.
-
  I create an account analytic line.
-
  !record {model: account.analytic.line, id: account_analytic_line_developyamlforhrmodule0}:
    account_id: account.analytic_sednacom
    amount: -1.0
    company_id: base.main_company
    date: !eval time.strftime('%Y-%m-%d')
    general_account_id: account.a_expense
    journal_id: hr_timesheet.analytic_journal
    name: develop yaml for hr module
    product_id: hr_timesheet.product_consultant
    product_uom_id: product.uom_hour
    to_invoice: hr_timesheet_invoice.timesheet_invoice_factor2
    unit_amount: 5.00
    user_id: base.user_root

-
  Assign partner name and price list in analytic account.
-
  !record {model: account.analytic.account, id: account.analytic_sednacom}:
    partner_id: base.res_partner_desertic_hispafuentes
    pricelist_id: product.list0

-
  I create invoice on analytic Line using "Invoice analytic Line" wizard.
-
  !record {model: hr.timesheet.invoice.create, id: hr_timesheet_invoice_create_0}:
    date: 1
    name: 1
    price: 1
    product: hr_timesheet.product_consultant
    time: 1

-
  I click on "Create Invoice" button of "Invoice analytic Line" wizard to create invoice.
-
  !python {model: hr.timesheet.invoice.create}: |
    self.do_create(cr, uid, [ref("hr_timesheet_invoice_create_0")], {"active_ids": [ref("hr_timesheet_invoice.account_analytic_line_developyamlforhrmodule0")]})

-
  I check that Invoice is created for this timesheet.
-
  !python {model: account.analytic.line}: |
    aline = self.browse(cr, uid, ref('account_analytic_line_developyamlforhrmodule0'))
    analytic_account_obj = self.pool.get('account.analytic.account')
    data = self.pool.get('hr.timesheet.invoice.create').read(cr, uid, [ref("hr_timesheet_invoice_create_0")], [], context)[0]
    partner = aline.account_id.partner_id.id

    invoice_obj = self.pool.get('account.invoice')
    invoice_ids = invoice_obj.search(cr, uid, [('partner_id', '=', partner)])
    invoice_id = invoice_obj.browse(cr, uid, invoice_ids)[0]

    for invoice in invoice_id.invoice_line:
      product = invoice.product_id.id

    product_exp = data['product'][0]

    assert product == product_exp
    assert aline.invoice_id, "Invoice created, but analytic line wasn't updated."
    assert aline.invoice_id == invoice_id, "Invoice doesn't match the one at analytic line"
    # The expected amount is hard coded here, please keep updated:
    assert invoice_id.amount_untaxed == 187.5, "Invoice amount mismatch: %s" % invoice_id.amount_untaxed
-
  I create final invoice for this analytic account.
-
  !record {model: hr.timesheet.invoice.create.final, id: hr_timesheet_invoice_create_final_0}:
    balance_product: hr_timesheet.product_consultant
    date: 1
    name: 1
    price: 1
    time: 1
-
  I click on "Create Invoice" button to create Invoice.
-
  !python {model: hr.timesheet.invoice.create.final}: |
    self.do_create(cr, uid, [ref("hr_timesheet_invoice_create_final_0")], {"active_ids": [ref("account.analytic_sednacom")]})

-
  I can also make some theoretical revenue reports.
-
  I can also see timesheet profit using Timesheet profit report.
