'Sync items with hub.erpnext.com'

def sync(self, verbose=True):

    if (not self.publish):
        if verbose:
            frappe.msgprint(_(u'Publish    to    sync    items'))
        return
    items = frappe.db.get_all(u'Item', fields=[u'name', u'item_name', u'description', u'image', u'item_group'], filters={u'publish_in_hub': 1, u'synced_with_hub': 0})
    for item in items:
        item.item_code = item.name
        if item.image:
            item.image = expand_relative_urls(item.image)
    item_list = frappe.db.sql_list(u'select    name    from    tabItem    where    publish_in_hub=1')
    if items:
        response = requests.post((self.hub_url + u'/api/method/hub.hub.api.sync'), data={u'access_token': self.access_token, u'items': json.dumps(items), u'item_list': json.dumps(item_list)})
        response.raise_for_status()
        for item in items:
            frappe.db.set_value(u'Item', item.name, u'synced_with_hub', 1)
        if verbose:
            frappe.msgprint(_(u'{0}    Items    synced'.format(len(items))))
    elif verbose:
        frappe.msgprint(_(u'Items    already    synced'))
