Changeset - 2d0cfa30ca40
[Not reviewed]
0 1 0
Lance Edgar - 5 years ago 2020-03-15 15:52:28
lance@edbob.org
Add "set" API methods for Department, Subdepartment, Product
1 file changed with 66 insertions and 0 deletions:
0 comments (0 inline, 0 general) First comment
corepos/api.py
Show inline comments
 
@@ -151,6 +151,28 @@ class CoreWebAPI(object):
 
                log.warning("CORE API returned %s department results", len(result))
 
            return json.loads(result[0])
 

	
 
    def set_department(self, dept_no, **columns):
 
        """
 
        Update an existing Department record in CORE.
 

	
 
        :returns: Boolean indicating success of the operation.
 

	
 
        .. note::
 
           Currently this is being used to create a *new* department also.  CORE's
 
           ``departments`` table does not use auto-increment for its PK, which
 
           means we must provide one even when creating; therefore this method
 
           may be used for that.
 
        """
 
        columns['dept_no'] = dept_no
 
        params = {
 
            'entity': 'Departments',
 
            'submethod': 'set',
 
            'columns': columns,
 
        }
 
        response = self.post(params)
 
        result = self.parse_response(response)
 
        return json.loads(result)
 

	
 
    def get_subdepartments(self, **columns):
 
        """
 
        Fetch some or all of Subdepartment records from CORE.
 
@@ -193,6 +215,28 @@ class CoreWebAPI(object):
 
                log.warning("CORE API returned %s subdepartment results", len(result))
 
            return json.loads(result[0])
 

	
 
    def set_subdepartment(self, subdept_no, **columns):
 
        """
 
        Update an existing Subdepartment record in CORE.
 

	
 
        :returns: Boolean indicating success of the operation.
 

	
 
        .. note::
 
           Currently this is being used to create a *new* subdepartment also.  CORE's
 
           ``subdepartments`` table does not use auto-increment for its PK, which
 
           means we must provide one even when creating; therefore this method
 
           may be used for that.
 
        """
 
        columns['subdept_no'] = subdept_no
 
        params = {
 
            'entity': 'SubDepts',
 
            'submethod': 'set',
 
            'columns': columns,
 
        }
 
        response = self.post(params)
 
        result = self.parse_response(response)
 
        return json.loads(result)
 

	
 
    def get_vendors(self, **columns):
 
        """
 
        Fetch some or all of Vendor records from CORE.
 
@@ -298,3 +342,25 @@ class CoreWebAPI(object):
 
            if len(result) > 1:
 
                log.warning("CORE API returned %s product results", len(result))
 
            return json.loads(result[0])
 

	
 
    def set_product(self, upc, **columns):
 
        """
 
        Update an existing Product record in CORE.
 

	
 
        :returns: Boolean indicating success of the operation.
 

	
 
        .. note::
 
           Currently this is being used to create a *new* product also.  CORE's
 
           ``products`` table does not use auto-increment for its PK, which
 
           means we must provide one even when creating; therefore this method
 
           may be used for that.
 
        """
 
        columns['upc'] = upc
 
        params = {
 
            'entity': 'Products',
 
            'submethod': 'set',
 
            'columns': columns,
 
        }
 
        response = self.post(params)
 
        result = self.parse_response(response)
 
        return json.loads(result)
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now