Changeset 6ce4b59 in rattail-corepos


Ignore:
Timestamp:
07/07/20 19:58:57 (6 weeks ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
a32753a
Parents:
4402d79
git-author:
Lance Edgar <lance@…> (07/06/20 21:16:01)
git-committer:
Lance Edgar <lance@…> (07/07/20 19:58:57)
Message:

Add more schema extensions; importing support

Location:
rattail_corepos
Files:
3 added
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • rattail_corepos/db/model/people.py

    r4402d79 r6ce4b59  
    2929
    3030from rattail.db import model
    31 
    32 
    33 __all__ = ['CorePerson', 'CoreVendor']
    3431
    3532
     
    6966
    7067
    71 class CoreVendor(model.Base):
     68class CoreCustomer(model.Base):
    7269    """
    73     CORE-specific extensions to :class:`rattail:rattail.db.model.Vendor`.
     70    CORE-specific extensions to :class:`rattail:rattail.db.model.Customer`.
    7471    """
    75     __tablename__ = 'corepos_vendor'
     72    __tablename__ = 'corepos_customer'
    7673    __table_args__ = (
    77         sa.ForeignKeyConstraint(['uuid'], ['vendor.uuid'],
    78                                 name='corepos_vendor_fk_vendor'),
     74        sa.ForeignKeyConstraint(['uuid'], ['customer.uuid'],
     75                                name='corepos_customer_fk_customer'),
    7976    )
    8077    __versioned__ = {}
    8178
    8279    uuid = model.uuid_column(default=None)
    83     vendor = orm.relationship(
    84         model.Vendor,
     80    customer = orm.relationship(
     81        model.Customer,
    8582        doc="""
    86         Reference to the actual vendor record, which this one extends.
     83        Reference to the actual customer record, which this one extends.
    8784        """,
    8885        backref=orm.backref(
     
    9188            cascade='all, delete-orphan',
    9289            doc="""
    93             Reference to the CORE-POS extension record for this vendor.
     90            Reference to the CORE-POS extension record for this customer.
    9491            """))
    9592
    96     corepos_id = sa.Column(sa.Integer(), nullable=False, doc="""
    97     ``vendorID`` value for the vendor, within CORE-POS.
     93    corepos_account_id = sa.Column(sa.Integer(), nullable=False, doc="""
     94    ``Customers.customerAccountID`` value for this customer, within CORE-POS.
    9895    """)
    9996
    10097    def __str__(self):
    101         return str(self.vendor)
     98        return str(self.customer)
    10299
    103 CoreVendor.make_proxy(model.Vendor, '_corepos', 'corepos_id')
     100CoreCustomer.make_proxy(model.Customer, '_corepos', 'corepos_account_id')
     101
     102
     103class CoreMember(model.Base):
     104    """
     105    CORE-specific extensions to :class:`rattail:rattail.db.model.Member`.
     106    """
     107    __tablename__ = 'corepos_member'
     108    __table_args__ = (
     109        sa.ForeignKeyConstraint(['uuid'], ['member.uuid'],
     110                                name='corepos_member_fk_member'),
     111    )
     112    __versioned__ = {}
     113
     114    uuid = model.uuid_column(default=None)
     115    member = orm.relationship(
     116        model.Member,
     117        doc="""
     118        Reference to the actual member record, which this one extends.
     119        """,
     120        backref=orm.backref(
     121            '_corepos',
     122            uselist=False,
     123            cascade='all, delete-orphan',
     124            doc="""
     125            Reference to the CORE-POS extension record for this member.
     126            """))
     127
     128    corepos_account_id = sa.Column(sa.Integer(), nullable=False, doc="""
     129    ``Customers.customerAccountID`` value for this member, within CORE-POS.
     130    """)
     131
     132    def __str__(self):
     133        return str(self.member)
     134
     135CoreMember.make_proxy(model.Member, '_corepos', 'corepos_account_id')
  • rattail_corepos/importing/corepos/api.py

    r4402d79 r6ce4b59  
    8282
    8383
    84 class CustomerImporter(FromCOREPOSAPI, importing.model.CustomerImporter):
     84class CustomerImporter(FromCOREPOSAPI, corepos_importing.model.CustomerImporter):
    8585    """
    8686    Importer for customer data from CORE POS API.
    8787    """
    88     key = 'number'
    89     supported_fields = [
     88    key = 'corepos_account_id'
     89    supported_fields = [
     90        'corepos_account_id',
    9091        'id',
    9192        'number',
     
    127128
    128129        return {
     130            'corepos_account_id': int(member['customerAccountID']),
    129131            'id': member['customerAccountID'],
    130132            'number': int(member['cardNo']),
     
    257259        model = self.config.get_model()
    258260
    259         self.customers = self.cache_model(model.Customer, key='id')
     261        query = self.session.query(model.Customer)\
     262                            .join(model.CoreCustomer)
     263        self.customers = self.cache_model(model.Customer, query=query,
     264                                          key='corepos_account_id')
    260265
    261266        query = self.session.query(model.Person)\
     
    280285            for i, customer in enumerate(customers, 1):
    281286                normalized.append({
    282                     'customer_account_id': member['customerAccountID'],
     287                    'customer_account_id': int(member['customerAccountID']),
    283288                    'person_customer_id': customer['customerID'],
    284289                    'ordinal': i,
     
    289294        return normalized
    290295
    291     def get_customer(self, id):
     296    def get_customer(self, account_id):
    292297        if hasattr(self, 'customers'):
    293             return self.customers.get(id)
     298            return self.customers.get(account_id)
    294299
    295300        try:
    296301            return self.session.query(model.Customer)\
    297                                .filter(model.Customer.id == id)\
     302                               .join(model.CoreCustomer)\
     303                               .filter(model.CoreCustomer.corepos_account_id == account_id)\
    298304                               .one()
    299305        except NoResultFound:
     
    334340
    335341
    336 class DepartmentImporter(FromCOREPOSAPI, importing.model.DepartmentImporter):
     342class DepartmentImporter(FromCOREPOSAPI, corepos_importing.model.DepartmentImporter):
    337343    """
    338344    Importer for department data from CORE POS API.
    339345    """
    340     key = 'number'
    341     supported_fields = [
     346    key = 'corepos_number'
     347    supported_fields = [
     348        'corepos_number',
    342349        'number',
    343350        'name',
     
    349356    def normalize_host_object(self, department):
    350357        return {
     358            'corepos_number': int(department['dept_no']),
    351359            'number': int(department['dept_no']),
    352360            'name': department['dept_name'],
     
    354362
    355363
    356 class SubdepartmentImporter(FromCOREPOSAPI, importing.model.SubdepartmentImporter):
     364class SubdepartmentImporter(FromCOREPOSAPI, corepos_importing.model.SubdepartmentImporter):
    357365    """
    358366    Importer for subdepartment data from CORE POS API.
    359367    """
    360     key = 'number'
    361     supported_fields = [
     368    key = 'corepos_number'
     369    supported_fields = [
     370        'corepos_number',
    362371        'number',
    363372        'name',
     
    374383
    375384        return {
     385            'corepos_number': int(subdepartment['subdept_no']),
    376386            'number': int(subdepartment['subdept_no']),
    377387            'name': subdepartment['subdept_name'],
     
    410420
    411421
    412 class ProductImporter(FromCOREPOSAPI, importing.model.ProductImporter):
     422class ProductImporter(FromCOREPOSAPI, corepos_importing.model.ProductImporter):
    413423    """
    414424    Importer for product data from CORE POS API.
    415425    """
    416     key = 'item_id'
    417     supported_fields = [
     426    key = 'corepos_id'
     427    supported_fields = [
     428        'corepos_id',
    418429        'item_id',
    419430        'upc',
     
    457468
    458469        return {
     470            'corepos_id': int(product['id']),
    459471            'item_id': product['upc'],
    460472            'upc': upc,
     
    477489
    478490
    479 class MemberImporter(FromCOREPOSAPI, importing.model.MemberImporter):
     491class MemberImporter(FromCOREPOSAPI, corepos_importing.model.MemberImporter):
    480492    """
    481493    Importer for member data from CORE POS API.
    482494    """
    483     key = 'number'
    484     supported_fields = [
     495    key = 'corepos_account_id'
     496    supported_fields = [
     497        'corepos_account_id',
    485498        'number',
    486499        'id',
     
    556569
    557570        return {
     571            'corepos_account_id': int(member['customerAccountID']),
    558572            'number': int(member['cardNo']),
    559573            'id': str(member['customerAccountID']),
  • rattail_corepos/importing/corepos/db.py

    r4402d79 r6ce4b59  
    116116
    117117
    118 class DepartmentImporter(FromCOREPOS, importing.model.DepartmentImporter):
     118class DepartmentImporter(FromCOREPOS, corepos_importing.model.DepartmentImporter):
    119119    """
    120120    Importer for department data from CORE POS.
    121121    """
    122122    host_model_class = corepos.Department
    123     key = 'number'
    124     supported_fields = [
     123    key = 'corepos_number'
     124    supported_fields = [
     125        'corepos_number',
    125126        'number',
    126127        'name',
     
    129130    def normalize_host_object(self, department):
    130131        return {
     132            'corepos_number': department.number,
    131133            'number': department.number,
    132134            'name': department.name,
     
    134136
    135137
    136 class SubdepartmentImporter(FromCOREPOS, importing.model.SubdepartmentImporter):
     138class SubdepartmentImporter(FromCOREPOS, corepos_importing.model.SubdepartmentImporter):
    137139    """
    138140    Importer for subdepartment data from CORE POS.
    139141    """
    140142    host_model_class = corepos.Subdepartment
    141     key = 'number'
    142     supported_fields = [
     143    key = 'corepos_number'
     144    supported_fields = [
     145        'corepos_number',
    143146        'number',
    144147        'name',
     
    148151    def normalize_host_object(self, subdepartment):
    149152        return {
     153            'corepos_number': subdepartment.number,
    150154            'number': subdepartment.number,
    151155            'name': subdepartment.name,
     
    154158
    155159
    156 class ProductImporter(FromCOREPOS, importing.model.ProductImporter):
     160class ProductImporter(FromCOREPOS, corepos_importing.model.ProductImporter):
    157161    """
    158162    Importer for product data from CORE POS.
    159163    """
    160164    host_model_class = corepos.Product
    161     key = 'item_id'
    162     supported_fields = [
     165    key = 'corepos_id'
     166    supported_fields = [
     167        'corepos_id',
    163168        'item_id',
    164169        'upc',
     
    191196
    192197        return {
     198            'corepos_id': product.id,
    193199            'item_id': product.upc,
    194200            'upc': upc,
  • rattail_corepos/importing/model.py

    r4402d79 r6ce4b59  
    5151
    5252
     53class CustomerImporter(importing.model.CustomerImporter):
     54
     55    extension_attr = '_corepos'
     56    extension_fields = [
     57        'corepos_account_id',
     58    ]
     59
     60
     61class MemberImporter(importing.model.MemberImporter):
     62
     63    extension_attr = '_corepos'
     64    extension_fields = [
     65        'corepos_account_id',
     66    ]
     67
     68
     69class DepartmentImporter(importing.model.DepartmentImporter):
     70
     71    extension_attr = '_corepos'
     72    extension_fields = [
     73        'corepos_number',
     74    ]
     75
     76
     77class SubdepartmentImporter(importing.model.SubdepartmentImporter):
     78
     79    extension_attr = '_corepos'
     80    extension_fields = [
     81        'corepos_number',
     82    ]
     83
     84
    5385class VendorImporter(importing.model.VendorImporter):
    5486
     
    5789        'corepos_id',
    5890    ]
     91
     92
     93class ProductImporter(importing.model.ProductImporter):
     94
     95    extension_attr = '_corepos'
     96    extension_fields = [
     97        'corepos_id',
     98    ]
     99
     100    def cache_query(self):
     101        query = super(ProductImporter, self).cache_query()
     102        model = self.config.get_model()
     103
     104        # we want to ignore products with no CORE ID, if that's (part of) our key
     105        if 'corepos_id' in self.key:
     106            query = query.join(model.CoreProduct)\
     107                         .filter(model.CoreProduct.corepos_id != None)
     108
     109        return query
  • rattail_corepos/importing/versions.py

    r4402d79 r6ce4b59  
    3636        importers = super(FromRattailToRattailVersions, self).get_importers()
    3737        importers['CorePerson'] = CorePersonImporter
     38        importers['CoreCustomer'] = CoreCustomerImporter
     39        importers['CoreMember'] = CoreMemberImporter
     40        importers['CoreDepartment'] = CoreDepartmentImporter
     41        importers['CoreSubdepartment'] = CoreSubdepartmentImporter
    3842        importers['CoreVendor'] = CoreVendorImporter
     43        importers['CoreProduct'] = CoreProductImporter
    3944        return importers
    4045
     
    4853
    4954
     55class CoreCustomerImporter(base.VersionImporter):
     56
     57    @property
     58    def host_model_class(self):
     59        model = self.config.get_model()
     60        return model.CoreCustomer
     61
     62
     63class CoreMemberImporter(base.VersionImporter):
     64
     65    @property
     66    def host_model_class(self):
     67        model = self.config.get_model()
     68        return model.CoreMember
     69
     70
     71class CoreDepartmentImporter(base.VersionImporter):
     72
     73    @property
     74    def host_model_class(self):
     75        model = self.config.get_model()
     76        return model.CoreDepartment
     77
     78
     79class CoreSubdepartmentImporter(base.VersionImporter):
     80
     81    @property
     82    def host_model_class(self):
     83        model = self.config.get_model()
     84        return model.CoreSubdepartment
     85
     86
    5087class CoreVendorImporter(base.VersionImporter):
    5188
     
    5491        model = self.config.get_model()
    5592        return model.CoreVendor
     93
     94
     95class CoreProductImporter(base.VersionImporter):
     96
     97    @property
     98    def host_model_class(self):
     99        model = self.config.get_model()
     100        return model.CoreProduct
Note: See TracChangeset for help on using the changeset viewer.