fix: potential errors when fetching response status in invoice processing
This commit is contained in:
@@ -382,16 +382,16 @@ def main(driver: WebDriver, logger = logging.getLogger('main')):
|
||||
|
||||
if (category := categories.get(o := item['category_id'])) is None:
|
||||
if 'error' in (category := fetch(f'{base}/categories/{o}.json?api_token={profile.token}')):
|
||||
error = category['error']
|
||||
code = category['code']
|
||||
logger.warning("Error while fetching field 'category' (code: %s, message: %s); skipping", code, error)
|
||||
error = dict.get(category, 'error')
|
||||
response = dict.get(category, 'status')
|
||||
logger.warning("Error while fetching field 'category' (status: %s, message: %s); skipping", response, error)
|
||||
continue
|
||||
|
||||
if (client := clients.get(o := item['client_id'])) is None:
|
||||
if 'error' in (client := fetch(f'{base}/clients/{o}.json?api_token={profile.token}')):
|
||||
error = client['error']
|
||||
code = client['code']
|
||||
logger.warning("Error while fetching field 'client' (code: %s, message: %s); skipping", code, error)
|
||||
error = dict.get(category, 'error')
|
||||
response = dict.get(category, 'status')
|
||||
logger.warning("Error while fetching field 'client' (status: %s, message: %s); skipping", response, error)
|
||||
continue
|
||||
|
||||
identity = client['shortcut'] if client['company'] else profile.person
|
||||
@@ -446,6 +446,10 @@ def main(driver: WebDriver, logger = logging.getLogger('main')):
|
||||
status = Status.STANDBY
|
||||
continue
|
||||
|
||||
if sheet.max_row < 2:
|
||||
logger.warning("No data; skipping")
|
||||
continue
|
||||
|
||||
try:
|
||||
filename = f'Order-Import-{profile.name}-{datetime.now().strftime('%Y%m%d-%H%M%S-%f')}.xlsx'
|
||||
file = Path(parameters['directory']).joinpath(filename)
|
||||
@@ -475,25 +479,6 @@ def main(driver: WebDriver, logger = logging.getLogger('main')):
|
||||
click(".mm-outside.mm-select-dropdown ul li:nth-child(%d) span" % (1 if options.get('draft') else 6))
|
||||
locate(".big-file-upload input", wait=False).send_keys(str(file))
|
||||
click(".product-import-img-footer button")
|
||||
|
||||
while not flow.react(Wait, Sleep):
|
||||
try:
|
||||
err = locate(".mm-tbody table tbody tr:nth-child(1) td:nth-child(5) .okki-space-item:nth-child(1) button", wait=False)
|
||||
ok = locate(".mm-tbody table tbody tr:nth-child(1) td:nth-child(3) a", wait=False)
|
||||
break
|
||||
except: pass
|
||||
try: click(".product-import-img-footer button.mm-button__primary", wait=False)
|
||||
except: pass
|
||||
try: click(".list-header-wrap button", wait=False)
|
||||
except: pass
|
||||
|
||||
if err.get_attribute('disabled') is None:
|
||||
click(err, condition=None)
|
||||
logger.warning('Incomplete import detected; downloading 1 related document')
|
||||
flow.react(Sleep)
|
||||
|
||||
click(ok, condition=None)
|
||||
flow.react(Sleep)
|
||||
logger.info('Done')
|
||||
except Skip:
|
||||
pass
|
||||
@@ -504,6 +489,25 @@ def main(driver: WebDriver, logger = logging.getLogger('main')):
|
||||
status = Status.STANDBY
|
||||
continue
|
||||
|
||||
while not flow.react(Wait, Sleep):
|
||||
try:
|
||||
err = locate(".mm-tbody table tbody tr:nth-child(1) td:nth-child(5) .okki-space-item:nth-child(1) button", wait=False)
|
||||
break
|
||||
except: pass
|
||||
try: click(".product-import-img-footer button.mm-button__primary", wait=False)
|
||||
except: pass
|
||||
try: click(".list-header-wrap button", wait=False)
|
||||
except: pass
|
||||
|
||||
if err.get_attribute('disabled') is None:
|
||||
click(err, condition=None)
|
||||
logger.warning('Incomplete import detected; downloading 1 related document')
|
||||
flow.react(Sleep)
|
||||
|
||||
try: click(".mm-tbody table tbody tr:nth-child(1) td:nth-child(3) a", wait=False)
|
||||
except: continue
|
||||
flow.react(Sleep)
|
||||
|
||||
class Parse:
|
||||
def __init__(self, url: str):
|
||||
from urllib.parse import urlsplit, parse_qs
|
||||
@@ -640,7 +644,7 @@ def main(driver: WebDriver, logger = logging.getLogger('main')):
|
||||
try:
|
||||
flow.react(Wait)
|
||||
label = locate("label.paas-form-item-label")
|
||||
dropdown = locate("#rc_select_1")
|
||||
dropdown = locate("label.paas-form-item-label[title='商机'] + div input")
|
||||
|
||||
for iteration in count(1):
|
||||
dropdown.click()
|
||||
|
||||
Reference in New Issue
Block a user