~akretion-team/magentoerpconnect/kyle_migration

« back to all changes in this revision

Viewing changes to product.py

  • Committer: aliomattux
  • Date: 2011-04-01 18:43:56 UTC
  • Revision ID: gadgetscentralservice@gmail.com-20110401184356-659r7kth83fzuusq
mergeĀ otherĀ branches

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
                    ('name', 'Name'),
76
76
                    ('price', 'Price')
77
77
                    ], 'Default Product Listing Sort (Sort By)'),
78
 
        'magerp_stamp':fields.datetime('Magento stamp')
 
78
        'magerp_stamp':fields.datetime('Magento stamp'),
 
79
        'include_in_menu': fields.boolean('Include in Navigation Menu'),
 
80
        'page_layout': fields.selection([
 
81
                    ('None', 'No layout updates'),
 
82
                    ('empty', 'Empty'),
 
83
                    ('one_column', '1 column'),
 
84
                    ('two_columns_left', '2 columns with left bar'),
 
85
                    ('two_columns_right', '2 columns with right bar'),
 
86
                    ('three_columns', '3 columns'),
 
87
                    ], 'Page Layout'),        
79
88
        }
80
89
    _defaults = {
81
90
        'display_mode':lambda * a:'PRODUCTS',
82
91
        'available_sort_by':lambda * a:'None',
83
92
        'default_sort_by':lambda * a:'None',
84
 
        'level':lambda * a:1
 
93
        'level':lambda * a:1,
 
94
        'include_in_menu': lambda * a:True,
 
95
        'page_layout': lambda * a:'None'
85
96
                 }
86
97
    
87
98
    def write(self, cr, uid, ids, vals, context=None):
900
911
        self.write(cr, uid, oe_id, {'magento_sku': sku})
901
912
        return res
902
913
    
 
914
    def ext_export_configurable(self, cr, uid, id, external_referential_ids=None, defaults=None, context=None):
 
915
        raise osv.except_osv(_("Not Implemented"), _("Configurable products are not implemented."))    
 
916
    
903
917
    def ext_export(self, cr, uid, ids, external_referential_ids=None, defaults=None, context=None):
904
918
        if context is None:
905
919
            context = {}
938
952
            last_updated_time = datetime.datetime.fromtimestamp(time.mktime(time.strptime(last_updated_product, '%Y-%m-%d %H:%M:%S')))
939
953
            if product_read[3] == 'grouped':
940
954
                cr.execute('select * from ir_module_module where name=%s and state=%s', ('mrp','installed'))
941
 
                if cr.fetchone() and 'mrp' in data_record and data_record['mrp']:
 
955
                data_record = cr.fetchone()
 
956
                if 'mrp' in data_record:
942
957
                    cr.execute("select id, write_date, create_date from mrp_bom where product_id = %s", (product_read[0],))
943
958
                    read_bom = cr.fetchall()
944
959
                    for bom in read_bom:
984
999
            product_type = self.read(cr, uid, id, ['product_type'])['product_type']
985
1000
            if product_type == 'grouped': # lookup for Magento "grouped product"
986
1001
                cr.execute('select * from ir_module_module where name=%s and state=%s', ('mrp','installed'))
987
 
                if cr.fetchone() and 'mrp' in data_record and data_record['mrp']:
 
1002
                data_record = cr.fetchone()
 
1003
                if 'mrp' in data_record:
988
1004
                    bom_ids = self.read(cr, uid, id, ['bom_ids'])['bom_ids']
989
1005
                    if len(bom_ids): # it has or is part of a BoM
990
1006
                        cr.execute("SELECT product_id, product_qty FROM mrp_bom WHERE bom_id = %s", (bom_ids[0],)) #FIXME What if there is more than a materials list?
999
1015
                            self.ext_export(cr, uid, child_ids, external_referential_ids, defaults, context) #so we export them
1000
1016
                else:
1001
1017
                    logger.notifyChannel('ext synchro', netsvc.LOG_ERROR, "OpenERP 'grouped' products will export to Magento as 'grouped products' only if they have a BOM and if the 'mrp' BOM module is installed")
 
1018
            elif product_type == 'configurable':
 
1019
                self.ext_export_configurable(cr, uid, id, external_referential_ids, defaults, context)                    
1002
1020
            for context_storeview in context_dic:
1003
1021
                temp_result = super(magerp_osv.magerp_osv, self).ext_export(cr, uid, [id], external_referential_ids, defaults, context_storeview)
1004
1022
                if child_ids: 
1033
1051
                is_in_stock = int(virtual_available > 0)
1034
1052
                context['conn_obj'].call('product_stock.update', [product.magento_sku, {'qty': virtual_available, 'is_in_stock': is_in_stock}])
1035
1053
                logger.notifyChannel('ext synchro', netsvc.LOG_INFO, "Successfully updated stock level at %s for product with SKU %s " %(virtual_available, product.magento_sku))
1036
 
 
 
1054
        return True
 
1055
    
1037
1056
    def ext_grouped_product_assign(self, cr, uid, parent_id, child_ids, quantities, context):
1038
1057
        logger = netsvc.Logger()
1039
1058
        conn = context.get('conn_obj', False)