landed_costs_multicurrency_company.yml 8.4 KB
Newer Older
François C. committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
-
  Setup the Company as CHF (rate 1.3086) while keeping pricelist and price_type as EUR
-
 !record {model: res.currency.rate, id: base.rateCHF}:
    rate: 1.3086
    currency_id: base.CHF
    name: !eval time.strftime('%Y-01-01')
-
 !record {model: res.currency.rate, id: base.rateEUR}:
    rate: 1.0
    currency_id: base.EUR
    name: !eval time.strftime('%Y-01-01')
-
 !record {model: res.company, id: base.main_company}:
    currency_id: base.CHF
-
 !record {model: product.price.type, id: product.standard_price}:
    currency_id: base.EUR
-
 !record {model: product.pricelist, id: purchase.list0}:
    currency_id: base.EUR 
-
  Affect the admin user to the main company
-
 !record {model: res.users, id: base.user_root}:
    company_id: base.main_company 
-
  Create a stock location for the test
-
 !record {model: stock.location, id: location_stock_01}:
    name: Stock for PO
    usage: internal
-
  Create a warehouse for the test
-
 !record {model: stock.warehouse, id: wh_stock_01}:
    name: Warehouse for PO
    lot_output_id: location_stock_01
    lot_stock_id: location_stock_01
    lot_input_id: location_stock_01
    company_id: base.main_company
-
  Create a Supplier for PO
-
  !record {model: res.partner, id: res_partner_supplier_01}:
    name: Supplier 1
    supplier: 1
-
  Create a Supplier for landed cost
-
  !record {model: res.partner, id: res_partner_supplier_02}:
    name: Supplier 2
    supplier: 1
-
  Create a product with landed type Quantity
-
  !record {model: product.product, id: product_product_lcost_01}:
    categ_id: product.product_category_1
    cost_method: standard
    landed_cost_type: per_unit
    name: Transport Poste Express Quantity
    standard_price: 50.0
    list_price: 75.0
    type: service
    uom_id: product.product_uom_unit
    uom_po_id: product.product_uom_unit
    volume: 0.0
    warranty: 0.0
    weight: 0.0
    weight_net: 0.0
-
  Create a wine product H with an avg price of 100
-
  !record {model: product.product, id: product_product_h_avg_01}:
    categ_id: product.product_category_1
    cost_method: standard
    name: Wine H
    standard_price: 100.0
    list_price: 150.0
    type: product
    cost_method: average
    uom_id: product.product_uom_unit
    uom_po_id: product.product_uom_unit
-
  Create a wine product I with an avg price of 200
-
  !record {model: product.product, id: product_product_i_avg_01}:
    categ_id: product.product_category_1
    cost_method: standard
    name: Wine I
    standard_price: 200.0
    list_price: 250.0
    type: product
    cost_method: average
    uom_id: product.product_uom_unit
    uom_po_id: product.product_uom_unit
-
  Create a purchase order with two lines and one landed cost based on quantity
-
  !record {model: purchase.order, id: purchase_order_lcost_05}:
    partner_id: res_partner_supplier_01
    invoice_method: order
    location_id: location_stock_01
    pricelist_id: purchase.list0
    order_line:
      - product_id: product_product_h_avg_01
        price_unit: 100
        product_qty: 15.0
      - product_id: product_product_i_avg_01
        price_unit: 200
        product_qty: 5.0
    landed_cost_line_ids:
      - product_id: product_product_lcost_01
        amount: 50
        partner_id: res_partner_supplier_02
        generate_invoice: 1
        distribution_type_id: dist_unit
-
  Test the landed costs computation by lines
-
  !python {model: purchase.order}: |
    po = self.browse(cr, uid, ref('purchase_order_lcost_05'))
    for line in po.order_line:
      # Compute pro-rata of quantity for line
      value = (line.product_qty / (15+5)) * 50
      assert line.landing_costs_order == value, "The landing cost based on quantity has not been computed correctly"
-
 I confirm the order where invoice control is 'Bases on order'.
-
  !workflow {model: purchase.order, action: purchase_confirm, ref: purchase_order_lcost_05}
-
  I check that the landed cost invoice and PO one is generated from PO confirmation
-
  !python {model: purchase.order}: |
    purchase_order = self.browse(cr, uid, ref("purchase_order_lcost_05"))
    assert len(purchase_order.invoice_ids) == 2, "2 invoices (PO + landed cost) should have been generated on order confirmation."
-
  Reception is ready for process, make it and check moves value
-
  !python {model: stock.partial.picking}: |
    pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_lcost_05")).picking_ids
    partial_id = self.create(cr, uid, {},context={'active_model': 'stock.picking','active_ids': [pick_ids[0].id]})
    self.do_partial(cr, uid, [partial_id])
    picking = self.pool.get('stock.picking').browse(cr, uid, [pick_ids[0].id])[0]
    for move in picking.move_lines:
      if move.product_id.name == 'Wine H':
        assert move.price_unit == 102.5,"Technical field price_unit of Wine H stock move should record the landed_costs, not purchase price"
        assert move.price_unit_net == 100.0,"Technical field price_unit of Wine H stock move should record the purchase price"
      elif move.product_id.name == 'Wine I':
        assert move.price_unit == 202.5,"Technical field price_unit of Wine I stock move should record the landed_costs, not purchase price"
        assert move.price_unit_net == 200.0,"Technical field price_unit_net of Wine I stock move should record the purchase price"
-
  I check that purchase order is shipped.
-
  !python {model: purchase.order}: |
     assert self.browse(cr, uid, ref("purchase_order_lcost_05")).shipped == True,"Purchase order should be delivered"
-
  I check that avg price of products is computed with landed costs
-
  !python {model: product.product}: |
     # computed as : ((15/20) * 50 + 100 * 15) / 15
     value_a = 102.5
     # computed as : ((5/20) * 50 + 200 * 5) / 5
     value_b = 202.5
     print self.browse(cr, uid, ref("product_product_h_avg_01")).standard_price
     print self.browse(cr, uid, ref("product_product_i_avg_01")).standard_price
     assert self.browse(cr, uid, ref("product_product_h_avg_01")).standard_price == value_a,"Avg price for product Wine H is wrongly computed"
     assert self.browse(cr, uid, ref("product_product_i_avg_01")).standard_price == value_b,"Avg price for product Wine I is wrongly computed"
-
  Create a purchase order with two lines
-
  !record {model: purchase.order, id: purchase_order_lcost_05bis}:
    partner_id: res_partner_supplier_01
    invoice_method: order
    location_id: location_stock_01
    pricelist_id: purchase.list0
    order_line:
      - product_id: product_product_h_avg_01
        price_unit: 200
        product_qty: 15.0
      - product_id: product_product_i_avg_01
        price_unit: 400
        product_qty: 5.0
-
 I confirm the order where invoice control is 'Bases on order'.
-
  !workflow {model: purchase.order, action: purchase_confirm, ref: purchase_order_lcost_05bis}
-
  Reception is ready for process, make it and check moves value
-
  !python {model: stock.partial.picking}: |
    pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_lcost_05bis")).picking_ids
    partial_id = self.create(cr, uid, {},context={'active_model': 'stock.picking','active_ids': [pick_ids[0].id]})
    self.do_partial(cr, uid, [partial_id])
    picking = self.pool.get('stock.picking').browse(cr, uid, [pick_ids[0].id])[0]
    for move in picking.move_lines:
      if move.product_id.name == 'Wine H':
        assert move.price_unit == 200.0,"Technical field price_unit of Wine H stock move should record the purchase price"
      elif move.product_id.name == 'Wine I':
        assert move.price_unit == 400.0,"Technical field price_unit_net of Wine I stock move should record the purchase price"
-
  I check that purchase order is shipped.
-
  !python {model: purchase.order}: |
     assert self.browse(cr, uid, ref("purchase_order_lcost_05")).shipped == True,"Purchase order should be delivered"
-
  I check that avg price of products is computed correctly
-
  !python {model: product.product}: |
     xchg_rate_chf = 1.3086
     # Value in stock in EUR
     value_a = 102.5
     value_b = 202.5
     # computed as : (value_a * 15 + (200) * 15) / 30
     value_abis = round((value_a * 15 + (200) * 15) / 30, 2)
     # computed as : (value_b * 5 + (400) * 5) / 10
     value_bbis = round((value_b * 5 + (400) * 5) / 10, 2)

     assert self.browse(cr, uid, ref("product_product_h_avg_01")).standard_price == value_abis,"Avg price for product Wine H is wrongly computed"
     assert self.browse(cr, uid, ref("product_product_i_avg_01")).standard_price == value_bbis,"Avg price for product Wine I is wrongly computed"