-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvDemanBegActual.py
58 lines (41 loc) · 1.67 KB
/
InvDemanBegActual.py
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
from openpyxl import load_workbook
from datetime import date
import datetime
import shutil as sh
import os
##THE FORMAT FOR THESE 2 FILES MUST BE THE SAME!!!
def getCurrentMonth():
today = datetime.date.today()
first = today.replace(day=1)
currentMonth = first.strftime("%Y_%m")
return currentMonth
def getLastMonth():
today = datetime.date.today()
first = today.replace(day=1)
lastMonth = (first - datetime.timedelta(days=1)).strftime("%Y_%m")
return lastMonth
inventoryTemplateFileDest = r"MonthlyInventory\InventoryTemplate.xlsx"
oldExcelFileDest = r"MonthlyInventory\Inventory" + str(getLastMonth()) + ".xlsx"
newExcelFileDest = r"MonthlyInventory\Inventory" + str(getCurrentMonth()) + ".xlsx"
print(oldExcelFileDest)
def moveValues(template, oldFile, newFile):
"""This function copies the needed values from the old file
to the new monthly excel file"""
oldWorkBook = load_workbook(filename= oldFile, data_only=True)
oldWorkBook.sheetnames
newWorkBook = load_workbook(filename= template)
newWorkBook.sheetnames
oldInventory = oldWorkBook['Inventory']
newInventory = newWorkBook['Inventory']
#From Sold Qty to Demand
i = 2
while oldInventory.cell(row=i, column=1).value != None:
newInventory.cell(row= i, column= 10).value = oldInventory.cell(row= i, column= 4).value
i += 1
#From Stock to Inv Beg
i = 2
while oldInventory.cell(row=i, column=1).value != None:
newInventory.cell(row= i, column= 6).value = oldInventory.cell(row= i, column= 5).value
i += 1
newWorkBook.save(newFile)
moveValues(inventoryTemplateFileDest, oldExcelFileDest, newExcelFileDest)