Skip to content

Commit

Permalink
Merge pull request #1 from REVLOCK/master
Browse files Browse the repository at this point in the history
Adding changes for configurable and optional tracking fields for loca…
  • Loading branch information
hsyyid authored Dec 17, 2021
2 parents 603fb76 + 3e9b930 commit a27e8cc
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions target_xero/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def load_journal_entries(config, accounts, categories):
df = pd.read_csv(input_path)
# Verify it has required columns
cols = list(df.columns)
REQUIRED_COLS = ["Transaction Date", "Journal Entry Id", "Customer Name",
"Class", "Account Number", "Account Name", "Posting Type", "Description"]
REQUIRED_COLS = ["Transaction Date", "Journal Entry Id", "Class",
"Account Number", "Account Name", "Posting Type", "Description"]

if not all(col in cols for col in REQUIRED_COLS):
logger.error(
Expand All @@ -72,6 +72,12 @@ def load_journal_entries(config, accounts, categories):
journal_entries = []
errored = False

def add_tracking(line_item, tracking):
if "Tracking" in line_item:
line_item["Tracking"].append(tracking)
else:
line_item["Tracking"] = [tracking]

def build_lines(x):
# Get the journal entry id
je_id = x['Journal Entry Id'].iloc[0]
Expand Down Expand Up @@ -109,11 +115,43 @@ def build_lines(x):
tracking = categories.get(class_name)

if tracking is not None:
line_item["Tracking"] = [tracking]
add_tracking(line_item, tracking)
else:
logger.warning(
f"Class is missing on Journal Entry {je_id}! Name={class_name}")

# Get and set department if present
if 'department' in config and config['department'] in row.index:
dept_name = row[config['department']]
tracking = categories.get(dept_name)

if tracking is not None:
add_tracking(line_item, tracking)

# Get and set location if present
if 'location' in config and config['location'] in row.index:
location = row[config['location']]
tracking = categories.get(location)

if tracking is not None:
add_tracking(line_item, tracking)

# Get and set customer_id if present
if 'customer_id' in config and config['customer_id'] in row.index:
customer_id = row[config['customer_id']]
tracking = categories.get(customer_id)

if tracking is not None:
add_tracking(line_item, tracking)

# Get and set customer_name if present
if 'customer_name' in config and config['customer_name'] in row.index:
customer_name = row[config['customer_name']]
tracking = categories.get(customer_name)

if tracking is not None:
add_tracking(line_item, tracking)

# Create the line item
line_items.append(line_item)

Expand Down

0 comments on commit a27e8cc

Please sign in to comment.