odoo/addons/stock_planning/test/stock_planning.yml

258 lines
12 KiB
YAML

-
In order to test the flow of stock planning module. I will create forecast periods,
stock forecast and then with master procurement schedule.
-
I create weekly stock periods for the month of July.
-
I create stock period for the first week of July.
-
!record {model: stock.period, id: stock_period_01}:
date_start: !eval "'%s-07-01 00:00:00' %(datetime.now().year)"
date_stop: !eval "'%s-07-06 23:59:00' %(datetime.now().year)"
name: !eval "'%s, week 27' %(datetime.now().year)"
-
I create stock period for the second week of July.
-
!record {model: stock.period, id: stock_period_02}:
date_start: !eval "'%s-07-07 00:00:00' %(datetime.now().year)"
date_stop: !eval "'%s-07-12 23:59:00' %(datetime.now().year)"
name: !eval "'%s, week 28' %(datetime.now().year)"
-
I create stock period for the third week of July.
-
!record {model: stock.period, id: stock_period_03}:
date_start: !eval "'%s-07-15 00:00:00' %(datetime.now().year)"
date_stop: !eval "'%s-07-20 23:59:00' %(datetime.now().year)"
name: !eval "'%s, week 29' %(datetime.now().year)"
-
I create stock period for the fourth week of July.
-
!record {model: stock.period, id: stock_period_04}:
date_start: !eval "'%s-07-22 00:00:00' %(datetime.now().year)"
date_stop: !eval "'%s-07-27 23:59:00' %(datetime.now().year)"
name: !eval "'%s, week 30' %(datetime.now().year)"
-
I create stock period for the fifth week of July.
-
!record {model: stock.period, id: stock_period_05}:
date_start: !eval "'%s-07-29 00:00:00' %(datetime.now().year)"
date_stop: !eval "'%s-07-31 23:59:00' %(datetime.now().year)"
name: !eval "'%s, week 31' %(datetime.now().year)"
-
I validate in open state module stock.period
-
!python {model: stock.period}: |
self.button_open(cr, uid, [ref("stock_period_01")], {"lang": 'en_GB', "tz": False, "active_model": 'ir.ui.menu', "active_id": ref("stock_planning.menu_stock_period_main"), "active_ids": [ref("stock_planning.menu_stock_period_main")], "department_id": False})
-
I validate in close state module stock.period
-
!python {model: stock.period}: |
self.button_close(cr, uid, [ref("stock_period_01")], {"lang": 'en_GB', "tz": False, "active_model": 'ir.ui.menu', "active_id": ref("stock_planning.menu_stock_period_main"), "active_ids": [ref("stock_planning.menu_stock_period_main")], "department_id": False})
-
Now I create the forecast for this period for all PCs.
-
!record {model: stock.sale.forecast.createlines, id: stock_sale_forecast_createlines_0}:
company_id: base.main_company
period_id: stock_period_03
product_categ_id: product.product_category_4
warehouse_id: stock.warehouse0
-
Performing an osv_memory action create_forecast on module stock.sale.forecast.createlines
-
!python {model: stock.sale.forecast.createlines}: |
self.create_forecast(cr, uid, [ref("stock_sale_forecast_createlines_0")], {"lang":
'en_US', "active_model": "ir.ui.menu", "active_ids": [ref("stock_planning.menu_stock_sale_forecast_createlines")],
"tz": False, "active_id": ref("stock_planning.menu_stock_sale_forecast_createlines"),
})
-
I create stock.period.createlines for the first week of August.
-
!record {model: stock.period.createlines, id: stock_period_createlines_week01}:
date_start: !eval "'%s-08-01' %(datetime.now().year)"
date_stop: !eval "'%s-08-06' %(datetime.now().year)"
name: !eval "'%s, week 31' %(datetime.now().year)"
-
Performing an osv_memory action create_stock_periods on module stock.period.createlines
-
!python {model: stock.period.createlines}: |
self.create_stock_periods(cr, uid, [ref("stock_period_createlines_week01")], {"lang":
'en_US', "name": 'Weekly', "interval": 6, "active_model": "ir.ui.menu", "active_ids": [ref("stock_planning.menu_stock_period_creatlines")],
"tz": False, "active_id": ref("stock_planning.menu_stock_period_creatlines"),
})
-
I create stock.period.createlines for the month of August - September
-
!record {model: stock.period.createlines, id: stock_period_createlines_month01}:
date_start: !eval "'%s-08-01' %(datetime.now().year)"
date_stop: !eval "'%s-09-01' %(datetime.now().year)"
name: !eval "'%s, month 8' %(datetime.now().year)"
-
Performing an osv_memory action create_stock_periods on module stock.period.createlines
-
!python {model: stock.period.createlines}: |
self.create_stock_periods(cr, uid, [ref("stock_period_createlines_month01")], {"lang":
'en_US', "name": 'Monthly', "interval": 6, "active_model": "ir.ui.menu", "active_ids": [ref("stock_planning.menu_stock_period_creatlines")],
"tz": False, "active_id": ref("stock_planning.menu_stock_period_creatlines"),
})
-
I create stock.period.createlines for the Day of August
-
!record {model: stock.period.createlines, id: stock_period_createlines_day01}:
date_start: !eval "'%s-08-01' %(datetime.now().year)"
date_stop: !eval "'%s-08-01' %(datetime.now().year)"
name: !eval "'%s, day 01' %(datetime.now().year)"
-
Performing an osv_memory action create_stock_periods on module stock.period.createlines
-
!python {model: stock.period.createlines}: |
self.create_stock_periods(cr, uid, [ref("stock_period_createlines_day01")], {"lang":
'en_US', "name": 'Daily', "interval": 6, "active_model": "ir.ui.menu", "active_ids": [ref("stock_planning.menu_stock_period_creatlines")],
"tz": False, "active_id": ref("stock_planning.menu_stock_period_creatlines"),
})
-
I Read date_start on module stock.period.createlines.
-
!python {model: stock.period.createlines }: |
self._get_new_period_start(cr, uid,{"lang":'en_US', "active_model": "ir.ui.menu",
"active_ids": [ref("stock_planning.menu_stock_period_creatlines")],
"tz": False, "active_id": ref("stock_planning.menu_stock_period_creatlines"),"department_id": False
})
-
I create a sale order for PC and Laptop.
-
!record {model: sale.order, id: sale_order_so0}:
date_order: !eval time.strftime('%Y-07-20')
invoice_quantity: order
name: TESTSO006
order_line:
- name: '[PC200] PC Assemble + 2GB RAM'
price_unit: 750.0
product_uom: product.product_uom_unit
product_uom_qty: 5.0
state: draft
delay: 2.0
product_id: product.product_product_4
product_uos_qty: 5.0
th_weight: 0.0
type: make_to_stock
- name: '[LAP-E5] Laptop E5023'
price_unit: 2950.0
product_uom: product.product_uom_unit
product_uom_qty: 12.0
state: draft
delay: 3.0
product_id: product.product_product_25
product_uos_qty: 12.0
th_weight: 0.0
type: make_to_stock
order_policy: manual
partner_id: base.res_partner_7
partner_invoice_id: base.res_partner_address_13
partner_shipping_id: base.res_partner_address_13
picking_policy: direct
pricelist_id: product.list0
shop_id: sale.sale_shop_1
-
Now I want to calculate sales history for both the products PC and Laptop and forecast the quantity.
-
!python {model: stock.sale.forecast}: |
forecast_ids = self.search(cr, uid, [('product_id','=',ref('product.product_product_4'))])
write_dict = {'product_qty': 30.0,
'analyzed_period1_id': ref("stock_period_03"),
'analyzed_user_id': ref("base.user_root"),
'analyzed_warehouse_id': ref("stock.warehouse0")}
context = {"lang": "en_US", "tz":False, "search_default_create_uid": 1, "active_model": "ir.ui.menu",
"department_id": False, "active_ids": [ref("stock_planning.menu_stock_sale_forecast_all")],
"active_id": ref("stock_planning.menu_stock_sale_forecast_all"), }
self.write(cr, uid, forecast_ids, write_dict)
self.calculate_sales_history(cr, uid, forecast_ids, context)
self.action_validate(cr, uid, forecast_ids, context)
-
Now I applying onchange and unlink forecast record for the product PC.
-
!python {model: stock.sale.forecast}: |
forecast_ids = self.search(cr, uid, [('product_id','=',ref('product.product_product_5'))])
self.unlink(cr, uid, forecast_ids, {"lang": "en_US", "tz":
False, "search_default_create_uid": 1, "active_model": "ir.ui.menu", "department_id":
False, "active_ids": [ref("stock_planning.menu_stock_sale_forecast_all")], "active_id":
ref("stock_planning.menu_stock_sale_forecast_all"), })
self.product_id_change(cr, uid, forecast_ids, ref('product.product_product_20'))
self.onchange_uom(cr, uid, forecast_ids, ref('product.product_uom_unit'), False, ref('product.product_uom_unit'), ref('product.product_product_20'))
self.product_amt_change(cr, uid, forecast_ids, 5.0, ref('product.product_uom_unit'), ref('product.product_product_20'))
self.product_amt_change(cr, uid, forecast_ids, 5.0, ref('product.product_uom_unit'), ref('product.product_product_20'))
self._to_default_uom_factor(cr, uid, ref('product.product_product_20'), ref('product.product_uom_unit'), {})
self.onchange_company(cr, uid, forecast_ids, ref('base.res_partner_2'))
-
I create Master procurement schedule for the third week of July.
-
!record {model: stock.planning.createlines, id: stock_planning_createlines_0}:
company_id: base.main_company
period_id: stock_period_03
product_categ_id: product.product_category_4
warehouse_id: stock.warehouse0
-
I create source warehouse for supply from another warehouse.
-
!record {model: stock.warehouse, id: stock_warehouse_0}:
name: shop1
company_id: base.main_company
lot_input_id: stock.stock_location_stock
lot_stock_id: stock.stock_location_stock
lot_output_id: stock.stock_location_output
-
Performing an osv_memory action create_planning on module stock.planning.createlines
-
!python {model: stock.planning.createlines}: |
self.onchange_company(cr, uid, ref("stock_planning_createlines_0"), ref('base.res_partner_2'))
self.create_planning(cr, uid, [ref("stock_planning_createlines_0")], {"lang":
"en_US", "tz": False, "active_model": "ir.ui.menu", "active_ids": [ref("stock_planning.menu_stock_planning_createlines")],
"active_id": ref("stock_planning.menu_stock_planning_createlines"), "department_id":
False, })
-
I calculate the planning in master procurement schedule.
-
!python {model: stock.planning}: |
planning_ids = self.search(cr, uid, [('product_id','=',ref('product.product_product_3')),('period_id','=',ref('stock_period_03'))])
self.write(cr, uid, planning_ids, {'to_procure': 30.0,'planned_outgoing': 40.0,'supply_warehouse_id': ref("stock_warehouse_0")})
self.onchange_company(cr, uid, planning_ids, ref('base.res_partner_2'))
self.onchange_uom(cr, uid, planning_ids, ref('product.product_uom_unit'), ref('product.product_product_3'),ref('product.product_uom_unit'), False, False)
self.product_id_change(cr, uid, planning_ids, ref('product.product_product_20'))
context = {"lang": "en_US", "tz": False, "active_model": "ir.ui.menu",
"active_ids": [ref("stock_planning.menu_stock_planning")],
"active_id": ref("stock_planning.menu_stock_planning"), "department_id": False,
}
self.calculate_planning(cr, uid, planning_ids, context)
self.internal_supply(cr, uid, planning_ids, context)
-
I create a procurement order for the incoming products left.
-
!python {model: stock.planning}: |
planning_ids = self.search(cr, uid, [('product_id','=',ref('product.product_product_3')),('period_id','=',ref('stock_period_03'))])
plann = self.browse(cr, uid, planning_ids)
assert plann[0].incoming_left, 'Incoming Left must be greater than 0 !'
self.procure_incomming_left(cr, uid, planning_ids, {"lang": 'en_US', "tz":
False, "active_model": "ir.ui.menu", "active_ids": [ref("stock_planning.menu_stock_planning")],
"active_id": ref("stock_planning.menu_stock_planning"), "department_id": False,
})
-
I check whether the procurement orders are created or not.
-
!python {model: procurement.order}: |
import datetime
proc_ids = self.search(cr, uid, [('origin','=','MPS(admin) %s, week 29' % (datetime.datetime.now().year)),('product_id','=',ref("product.product_product_3"))])
assert proc_ids,'No Procurements!'