- |
  In order to test the Point of Sale in module, I will do a full flow from the sale to the payment and invoicing.
  I will use two products, one with price including a 10% tax, the other one with 5% tax excluded from the price.
- |
  I create a VAT tax of 10%, included in the public price
- 
  !record {model: account.tax, id: account_tax_10_incl}:
    name: VAT 10 perc Incl
    type: percent
    amount: 0.10
    account_paid_id: account.iva
    account_collected_id: account.iva
    price_include: 1
-
  I assign this 10 percent tax on the [PCSC234] PC Assemble SC234 product as a sale tax
-
  !record {model: product.product, id: product.product_product_3, view: False}:
    taxes_id: [account_tax_10_incl]
- |
  I create a VAT tax of 5%, which is added to the public price
- 
  !record {model: account.tax, id: account_tax_05_incl}:
    name: VAT 05 perc Excl
    type: percent
    amount: 0.05
    account_paid_id: account.iva
    account_collected_id: account.iva
    price_include: 0
-
  I will create a second VAT tax of 5% but this time for a child company, to
  ensure that only product taxes of the current session's company are considered
  (this tax should be ignore when computing order's taxes in following tests)
-
  !record {model: account.tax, id: account_tax_05_incl_chicago}:
    name: VAT 05 perc Excl (US)
    type: percent
    amount: 0.05
    account_paid_id: account.iva
    account_collected_id: account.iva
    price_include: 0
    company_id: stock.res_company_1
-
  I assign those 5 percent taxes on the PCSC349 product as a sale taxes
-
  !record {model: product.product, id: product.product_product_4, view: False}:
    taxes_id: [account_tax_05_incl, account_tax_05_incl_chicago]
-
  I create a new session
-
  !record {model: pos.session, id: pos_order_session0}:
    user_id: 1
    config_id: point_of_sale.pos_config_main
-
  I open a new PoS Session wizard
-
  !record {model: pos.session.opening, id: pos_order_session_wizard0}:
    pos_config_id: point_of_sale.pos_config_main
- 
  I click on create a new session button
- 
  !python {model: pos.session.opening}: |
    self.open_existing_session_cb(cr, uid, [ref('pos_order_session_wizard0')])
-
  I open the session after having counted the money
- 
  !workflow {model: pos.session, action: open, ref: pos_order_session0}
-
  I create a PoS order with 2 units of PCSC234 at 450 EUR (Tax Incl) and 3 units of PCSC349 at 300 EUR. (Tax Excl)
-
  !record {model: pos.order, id: pos_order_pos0}:
    company_id: base.main_company
    lines:
      - name: OL/0001
        product_id: product.product_product_3
        price_unit: 450
        discount: 0.0
        qty: 2.0
      - name: OL/0002
        product_id: product.product_product_4
        price_unit: 300
        discount: 0.0
        qty: 3.0
- 
  I check that the total of the order is equal to 450*2 + 300*3*1.05 and the tax of the order is equal to 900 -(450 * 2 / 1.1) + 300*0.05*3
- 
  !python {model: pos.order}: |
    order = self.browse(cr, uid, ref('pos_order_pos0'))
    assert(abs(order.amount_total - (450*2 + 300*3*1.05)) < 0.01), "The order has a wrong amount, tax included"
    assert(abs(order.amount_tax - (900-(450*2/1.1) + 300*0.05*3)) < 0.01), "The order has a wrong tax amount"
- 
  I want to add a global discount of 5 percent using the wizard
- 
  !record {model: pos.discount, id: pos_discount_0}:
    discount: 5.0
- 
  I click the apply button to set the discount on all lines
- 
  !python {model: pos.discount}: |
    self.apply_discount(cr, uid, [ref("pos_discount_0")], {"active_model": "pos.order",
      "active_ids": [ref("pos_order_pos0")], "active_id": ref("pos_order_pos0"), })
- 
  I check that the total of the order is now equal to (450*2 + 300*3*1.05)*0.95
- 
  !python {model: pos.order}: |
    order = self.browse(cr, uid, ref('pos_order_pos0'))
    assert(abs(order.amount_total - (450*2 + 300*3*1.05)*0.95) < 0.01), "The order has a wrong total including tax and discounts"
-
  I click on the "Make Payment" wizard to pay the PoS order with a partial amount of 100.0 EUR
- 
  !record {model: pos.make.payment, id: pos_make_payment_0, context: '{"active_id": ref("pos_order_pos0"), "active_ids": [ref("pos_order_pos0")]}' }:
    amount: 100.0
-
  I click on the validate button to register the payment.
-
  !python {model: pos.make.payment}: |
    self.check(cr, uid, [ref('pos_make_payment_0')], context={'active_id': ref('pos_order_pos0'), 'lang':'en_US', 'active_model': 'pos.order', 'tz': False, 'active_ids': [ref('pos_order_pos0')]} )
- |
  I check that the order is not marked as paid yet
-
  !assert {model: pos.order, id: pos_order_pos0}:
     - state == 'draft'
- |
  On the second payment proposition, I check that it proposes me the remaining balance which is 1790.0 EUR
- 
  !python {model: pos.make.payment}: |
     defs = self.default_get(cr, uid, ['amount'], {'active_id': ref('pos_order_pos0')})
     assert abs(defs['amount'] - ((450*2 + 300*3*1.05)*0.95-100.0)) < 0.01, "The remaining balance is incorrect"
-
  I pay the remaining balance.
- 
  !record {model: pos.make.payment, id: pos_make_payment_1, context: '{"active_id": ref("pos_order_pos0"), "active_ids": [ref("pos_order_pos0")]}' }:
    amount: !eval >
      (450*2 + 300*3*1.05)*0.95-100.0
-
  I click on the validate button to register the payment.
-
  !python {model: pos.make.payment}: |
    self.check(cr, uid, [ref('pos_make_payment_1')], context={'active_id': ref('pos_order_pos0')} )
- |
  I check that the order is marked as paid
-
  !assert {model: pos.order, id: pos_order_pos0}:
     - state == 'paid'
- 
  I generate the journal entries
-
  !python {model: pos.order}: |
    self.create_account_move(cr, uid, [ref('pos_order_pos0')], {})
-
  I test that the generated journal entry is attached to the PoS order
-
  !assert {model: pos.order, id: pos_order_pos0}:
     - bool(account_move)
  



