-
   Set the context for customer invoices because the 'type' field is readonly in invoice form views, so it value won't be considered by the yaml import
-
  !record {model: account.invoice, id: demo_invoice_1}:
    company_id: base.main_company
    partner_id: base.res_partner_12
    user_id: base.user_demo
    reference_type: none
    payment_term_id: account.account_payment_term
    type: 'out_invoice'
    date_invoice: !eval time.strftime('%Y-%m')+'-01'
    invoice_line_ids:
      - name: 'Dell Inspiron Laptop without OS'
        product_id: product.product_product_49
        price_unit: 642.0
        quantity: 5
      - name: 'Linutop'
        product_id: product.product_product_50
        price_unit: 280.0
        quantity: 5.0
-
  !workflow {model: account.invoice, action: invoice_open, ref: demo_invoice_1}
-
  !record {model: account.invoice, id: demo_invoice_2}:
    company_id: base.main_company
    partner_id: base.res_partner_2
    type: 'out_invoice'
    date_invoice: !eval time.strftime('%Y-%m')+'-08'
    invoice_line_ids:
      - name: '8-port Switch'
        product_id: product.product_product_51
        price_unit: 50.0
        quantity: 3
      - name: '30m RJ45 wire'
        product_id: product.product_product_52
        price_unit: 25
        quantity: 20
-
  !workflow {model: account.invoice, action: invoice_open, ref: demo_invoice_2}
-
  !record {model: account.invoice, id: demo_invoice_3}:
    company_id: base.main_company
    partner_id: base.res_partner_2
    type: 'out_invoice'
    date_invoice: !eval time.strftime('%Y-%m')+'-08'
    invoice_line_ids:
      - name: 'TypeMatrix Dvorak Keyboard'
        product_id: product.product_product_53
        price_unit: 90.0
        quantity: 5
      - name: 'Ergonomic Mouse'
        product_id: product.product_product_54
        price_unit: 15.0
        quantity: 5.0
-
  !workflow {model: account.invoice, action: invoice_open, ref: demo_invoice_3}
-
  !record {model: account.invoice, id: demo_invoice_invest_sale}:
    company_id: base.main_company
    partner_id: base.res_partner_3
    type: 'out_invoice'
    date_invoice: !eval time.strftime('%Y-%m')+'-08'
-
  !python {model: ir.model.data} : |
      account_id = self.pool.get('account.account').search(cr, uid, [('tag_ids', 'in', [ref('account.demo_sale_of_land_account')])])
      line_vals = {
          'invoice_id': ref('demo_invoice_invest_sale'),
          'name': "Land located at '50.635336,4.863298'",
          'price_unit': 210600,
      }
      if account_id:
          line_vals['account_id'] = account_id[0]
          tax_id = self.pool.get('account.tax').search(cr, uid, [('type_tax_use', '=', 'sale'), ('amount', '>', 0)])
          if tax_id:
            line_vals['invoice_line_tax_ids'] = [(6, 0, [tax_id[0]])]
          self._update(cr, uid, 'account.invoice.line', 'account', line_vals, 'sale_of_land_line')
          self.pool.get('account.invoice').browse(cr, uid, ref('demo_invoice_invest_sale'))._onchange_invoice_line_ids()
          self.pool.get('account.invoice').signal_workflow(cr, uid, [ref('demo_invoice_invest_sale')], 'invoice_open')
-
   Set the context for supplier bills because the 'type' field is readonly in invoice form views, so it value won't be considered by the yaml import
-
  !context
    type: 'in_invoice'
-
  !record {model: account.invoice, id: demo_invoice_0}:
    company_id: base.main_company
    partner_id: base.res_partner_12
    user_id: base.user_demo
    reference_type: none
    payment_term_id: account.account_payment_term
    type: 'in_invoice'
    date_invoice: !eval time.strftime('%Y-%m')+'-01'
    invoice_line_ids:
      - name: 'Toner Cartridge'
        price_unit: 10.0
        quantity: 1.0
        product_id: product.product_product_39
        uom_id: product.product_uom_unit
      - name: 'Zed+ Antivirus'
        price_unit: 4.0
        quantity: 1.0
        product_id: product.product_product_43
        uom_id: product.product_uom_unit
-
  !record {model: account.invoice, id: demo_invoice_january_wages}:
    company_id: base.main_company
    partner_id: base.res_partner_12
    type: 'in_invoice'
    date_invoice: !eval time.strftime('%Y-%m')+'-01'
-
  !python {model: ir.model.data} : |
      line_vals = {
          'invoice_id': ref('demo_invoice_january_wages'),
          'name': "CEO wages",
          'price_unit': 10000,
      }
      account_id = self.pool.get('account.account').search(cr, uid, [('tag_ids', 'in', [ref('account.demo_ceo_wages_account')])])
      if not account_id:
          account_id = self.pool.get('account.account').search(cr, uid, [('user_type_id', '=', ref('account.data_account_type_expenses'))])
      if account_id:
          line_vals['account_id'] = account_id[0]
          self._update(cr, uid, 'account.invoice.line', 'account', line_vals, 'ceo_wages_line')
          self.pool.get('account.invoice').signal_workflow(cr, uid, [ref('demo_invoice_january_wages')], 'invoice_open')
-
  !record {model: account.invoice, id: demo_invoice_equipment_purchase}:
    company_id: base.main_company
    partner_id: base.res_partner_1
    type: 'in_invoice'
    date_invoice: !eval time.strftime('%Y-%m')+'-15'
-
  !python {model: ir.model.data} : |
      line_vals = {
          'invoice_id': ref('demo_invoice_equipment_purchase'),
          'name': "Coffee Machine with huge 'employee\'s performances boosting perk'",
          'price_unit': 4999.99,
      }
      account_id = self.pool.get('account.account').search(cr, uid, [('tag_ids', 'in', [ref('account.demo_coffee_machine_account')])])
      if not account_id:
          account_id = self.pool.get('account.account').search(cr, uid, [('user_type_id', '=', ref('account.data_account_type_expenses'))])
      if account_id:
          line_vals['account_id'] = account_id[0]
          tax_id = self.pool.get('account.tax').search(cr, uid, [('type_tax_use', '=', 'purchase'), ('amount', '>', 0)])
          if tax_id:
            line_vals['invoice_line_tax_ids'] = [(6, 0, [tax_id[0]])]
          self._update(cr, uid, 'account.invoice.line', 'account', line_vals, 'coffee_machine_line')
          self.pool.get('account.invoice').browse(cr, uid, ref('demo_invoice_equipment_purchase'))._onchange_invoice_line_ids()
          self.pool.get('account.invoice').signal_workflow(cr, uid, [ref('demo_invoice_equipment_purchase')], 'invoice_open')
-
  !python {model: account.bank.statement.line} : |
      account_ids = self.pool.get('account.account').search(cr, uid, [('user_type_id', '=', ref('account.data_account_type_revenue')), ('tag_ids', 'in', [ref('account.account_tag_financing')])])
      line = self.browse(cr, uid, ref('account.demo_bank_statement_line_5'))
      if not line.journal_entry_ids and account_ids:
          line.write({'account_id': account_ids[0]})
          line.fast_counterpart_creation()
-
  !python {model: ir.model.data} : |
      from datetime import datetime
      from dateutil.relativedelta import relativedelta
      vals = {
          'company_id': ref('base.main_company'),
          'journal_id': self.pool.get('account.journal').search(cr, uid, [('type', '=', 'general')])[0],
          'date': datetime.now().replace(day=1,month=1) - relativedelta(days=1),
          'ref': 'Company Creation',
      }
      self._update(cr, uid, 'account.move', 'account', vals, 'demo_opening_move')
-
  !python {model: ir.model.data} : |
      bank_journal_id = self.pool.get('account.journal').search(cr, uid, [('type', '=', 'bank')])[0]
      if bank_journal_id:
          bank_account_id = self.pool.get('account.journal').browse(cr, uid, bank_journal_id).default_debit_account_id.id
      fixed_asset_account_ids = self.pool.get('account.account').search(cr, uid, [('user_type_id', 'in', (ref('account.data_account_type_fixed_assets'),ref('account.data_account_type_current_assets')))])
      equity_account_ids = self.pool.get('account.account').search(cr, uid, [('user_type_id', '=', ref('account.data_account_type_equity')), ('tag_ids', 'in', [ref('account.demo_capital_account')])])
      if bank_account_id and fixed_asset_account_ids and equity_account_ids:
          self._update(cr, uid, 'account.move.line', 'account', {
              'move_id': ref('account.demo_opening_move'),
              'name': 'Opening Entry',
              'debit': 5103,
              'account_id': bank_account_id}, 'opening_line_1', context={'check_move_validity': False})
          self._update(cr, uid, 'account.move.line', 'account', {
              'move_id': ref('account.demo_opening_move'),
              'name': 'Opening Entry',
              'debit': 13447,
              'account_id': fixed_asset_account_ids[0]}, 'opening_line_2', context={'check_move_validity': False})
          self._update(cr, uid, 'account.move.line', 'account', {
              'move_id': ref('account.demo_opening_move'),
              'name': 'Opening Entry',
              'credit': 18550,
              'account_id': equity_account_ids[0]}, 'opening_line_3', context={'check_move_validity': False})
