def test_20_export_sale_comment(self):
        """ Test export of sale order comment"""
        response = {
            'sales_order.addComment': True,
        }
        cr = self.cr
        uid = self.uid
        with mock_api(response, key_func=lambda m, a: m) as calls_done:
            mag_comment_model = self.registry('magento.sale.comment')
            mail_message_model = self.registry('mail.message')

            comment_id = mail_message_model.create(
                cr, uid, {
                    'res_id': self.mag_order.openerp_id.id,
                    'body': 'Test me I famous',
                    'model': 'sale.order',
                    'subtype_id': 1,
                })

            mag_comment_id = mag_comment_model.search(cr, uid, [
                ('backend_id', '=', self.backend_id),
                ('openerp_id', '=', comment_id),
            ])[0]

            export_record(self.session, 'magento.sale.comment', mag_comment_id)

            self.assertEqual(len(calls_done), 1)

            method, (mag_order_id, state, comment, notif) = calls_done[0]
            self.assertEqual(method, 'sales_order.addComment')
            self.assertEqual(mag_order_id, '900000691')
            self.assertEqual(comment, 'Test me I famous')
    def test_20_export_sale_comment(self):
        """ Test export of sale order comment"""
        response = {
            'sales_order.addComment': True,
        }
        cr = self.cr
        uid = self.uid
        with mock_api(response, key_func=lambda m, a: m) as calls_done:
            mag_comment_model = self.registry('magento.sale.comment')
            mail_message_model = self.registry('mail.message')

            comment_id = mail_message_model.create(cr, uid, {
                'res_id': self.mag_order.openerp_id.id,
                'body': 'Test me I famous',
                'model': 'sale.order',
                'subtype_id': 1,
                })

            mag_comment_id = mag_comment_model.search(cr, uid, [
                ('backend_id', '=', self.backend_id),
                ('openerp_id', '=', comment_id),
                ])[0]

            export_record(self.session, 'magento.sale.comment', mag_comment_id)

            self.assertEqual(len(calls_done), 1)

            method, (mag_order_id, state, comment, notif) = calls_done[0]
            self.assertEqual(method, 'sales_order.addComment')
            self.assertEqual(mag_order_id, '900000691')
            self.assertEqual(comment, 'Test me I famous')
    def test_40_export_attribute_char_linked_to_an_attribute_set(self):
        response = {
            'product_attribute.create':
                self.get_magento_helper('magento.product.attribute').get_next_id,
            'product_attribute_set.attributeAdd': True,
        }
        attr_binder = self.get_binder('magento.product.attribute')
        with mock_api(response, key_func=lambda m, a: m) as calls_done:
            attr_id, bind_attr_id, code = self.add_attribute(
                'char', 'My Test Char', 'x_test_char')
            self.registry('attribute.location').create(self.cr, self.uid, {
                'attribute_id': attr_id,
                'attribute_group_id': self.attr_group_id,
                })

            export_record(self.session, 'magento.product.attribute',
                          bind_attr_id)
            self.assertEqual(len(calls_done), 2)
            method, (data,) = calls_done[0]
            self.assertEqual(method, 'product_attribute.create')

            method, (mag_attr_id, mag_attr_set_id) = calls_done[1]
            self.assertEqual(method, 'product_attribute_set.attributeAdd')
            self.assertEqual(mag_attr_set_id, self.default_mag_attr_set_id)
            expected_mag_attr_id = attr_binder.to_backend(bind_attr_id)
            self.assertEqual(mag_attr_id, expected_mag_attr_id)
    def test_70_export_attribute_option_with_dependency(self):
        option_model = self.registry('attribute.option')
        binding_option_model = self.registry('magento.attribute.option')
        response = {
            'product_attribute.create':
                self.get_magento_helper('magento.product.attribute').get_next_id,
            'oerp_product_attribute.addOption':
                self.get_magento_helper('magento.attribute.option').get_next_id
        }
        with mock_api(response, key_func=lambda m, a: m) as calls_done:
            attr_id, bind_attr_id, code = self.add_attribute(
                'select', 'My Test Select', 'x_test_select')
            option_id = option_model.create(self.cr, self.uid, {
                'attribute_id': attr_id,
                'name': 'My Option',
                })

            option = option_model.browse(self.cr, self.uid, option_id)
            export_record(self.session, 'magento.attribute.option',
                          option.magento_bind_ids[0].id)
            
            self.assertEqual(len(calls_done), 2)
            method, (data,) = calls_done[0]
            self.assertEqual(method, 'product_attribute.create')
            method, (mag_attr_id, data) = calls_done[1]
            self.assertEqual(method, 'oerp_product_attribute.addOption')
    def test_2_export_partner_address(self):
        """ Test export of address"""
        partner_helper = self.get_magento_helper('magento.res.partner')
        address_helper = self.get_magento_helper('magento.address')
        response = {
            'customer_address.create': address_helper.get_next_id,
        }
        cr = self.cr
        uid = self.uid
        with mock_api(response, key_func=lambda m, a: m) as calls_done:
            mag_address_model = self.registry('magento.address')
            mag_partner_model = self.registry('magento.res.partner')
            mag_partner_id = mag_partner_model.create(cr, uid, {
                'website_id': self.website_id,
                'openerp_id': self.partner_id2,
                'magento_id': partner_helper.get_next_id(),
                })
            mag_address_id = mag_address_model.create(cr, uid, {
                'magento_partner_id': mag_partner_id,
                'openerp_id': self.address,
                })
            export_record(self.session, 'magento.address', mag_address_id)

            self.assertEqual(len(calls_done), 1)

            method, [partner, values] = calls_done[0]
            self.assertEqual(method, 'customer_address.create')
            self.assertEqual(values['postcode'], '11112')
            self.assertEqual(values['city'], 'City contact test2')
            self.assertEqual(values['street'], '15, contact test street2')
            self.assertEqual(values['country_id'], 'BE')
            self.assertEqual(values['telephone'], '111111112')
    def test_2_export_partner_address(self):
        """ Test export of address"""
        partner_helper = self.get_magento_helper('magento.res.partner')
        address_helper = self.get_magento_helper('magento.address')
        response = {
            'customer_address.create': address_helper.get_next_id,
        }
        cr = self.cr
        uid = self.uid
        with mock_api(response, key_func=lambda m, a: m) as calls_done:
            mag_address_model = self.registry('magento.address')
            mag_partner_model = self.registry('magento.res.partner')
            mag_partner_id = mag_partner_model.create(
                cr, uid, {
                    'website_id': self.website_id,
                    'openerp_id': self.partner_id2,
                    'magento_id': partner_helper.get_next_id(),
                })
            mag_address_id = mag_address_model.create(
                cr, uid, {
                    'magento_partner_id': mag_partner_id,
                    'openerp_id': self.address,
                })
            export_record(self.session, 'magento.address', mag_address_id)

            self.assertEqual(len(calls_done), 1)

            method, [partner, values] = calls_done[0]
            self.assertEqual(method, 'customer_address.create')
            self.assertEqual(values['postcode'], '11112')
            self.assertEqual(values['city'], 'City contact test2')
            self.assertEqual(values['street'], '15, contact test street2')
            self.assertEqual(values['country_id'], 'BE')
            self.assertEqual(values['telephone'], '111111112')
    def test_20_export_attribute_set(self):
        """ Test export of attribute set"""
        response = {
            'product_attribute_set.create': 69,
        }
        cr = self.cr
        uid = self.uid
        with mock_api(response, key_func=lambda m, a: m) as calls_done:
            mag_attr_set_model = self.registry('magento.attribute.set')
            attr_set_model = self.registry('attribute.set')

            attr_set_id = attr_set_model.create(cr, uid, {
                'name': 'Test Export Attribute',
                }, {'force_model': 'product.template'})
            mag_attr_set_id = mag_attr_set_model.create(cr, uid, {
                'attribute_set_name': 'Test Export Attribute',
                'openerp_id': attr_set_id,
                'backend_id': self.backend_id,
                })
            
            export_record(self.session, 'magento.attribute.set',
                          mag_attr_set_id)

            self.assertEqual(len(calls_done), 1)

            method, (data, skeleton_id) = calls_done[0]
            self.assertEqual(method, 'product_attribute_set.create')
            self.assertEqual(skeleton_id, '9')
    def test_export_super_attribute_price(self):
        """ Export Super Attribute Price: check """

        response = {'ol_catalog_product_link.updateSuperAttributeValues': True}
        cr = self.cr
        uid = self.uid
        with mock_api(response, key_func=lambda m, a: m) as calls_done:
            dimension_value_model = self.registry('dimension.value')
            mag_super_attribute_model = self.registry(
                'magento.super.attribute')
            mag_attribute_option_model = self.registry(
                'magento.attribute.option')
            dim_value_id = dimension_value_model.create(
                cr, uid, {
                    'dimension_id': 2,
                    'option_id': 7,
                    'price_extra': 0.0,
                    'product_tmpl_id': 56,
                })

            dimension_value_model.write(cr, uid, dim_value_id, {
                'price_extra': 8.0,
            })
            dim_value = dimension_value_model.browse(cr, uid, dim_value_id)

            super_attribute_id = mag_super_attribute_model.search(
                cr, uid, [
                    ('attribute_id', '=', dim_value.dimension_id.id),
                    ('mag_product_display_id.product_tmpl_id', '=',
                     dim_value.product_tmpl_id.id),
                ])[0]
            super_attribute = mag_super_attribute_model.browse(
                cr, uid, super_attribute_id)

            attribute_option_id = mag_attribute_option_model.search(
                cr, uid, [
                    ('openerp_id', '=', dim_value.option_id.id),
                ])[0]
            attribute_option = mag_attribute_option_model.browse(
                cr, uid, attribute_option_id)

            export_record(self.session, 'magento.super.attribute',
                          super_attribute_id)

            self.assertEqual(len(calls_done), 1)

            method, data = calls_done[0]
            magento_super_attribute_id = data[0]
            value_index = data[1][4]['value_index']
            pricing_value = data[1][4]['pricing_value']

            self.assertEqual(
                method, 'ol_catalog_product_link.updateSuperAttributeValues')
            self.assertEqual(magento_super_attribute_id,
                             int(super_attribute.magento_id))
            self.assertEqual(value_index, attribute_option.magento_id)
            self.assertEqual(pricing_value, dim_value.price_extra)
    def test_30_export_attribute_char(self):
        response = {
            'product_attribute.create':
                self.get_magento_helper('magento.product.attribute').get_next_id,
        }
        with mock_api(response, key_func=lambda m, a: m) as calls_done:
            attr_id, bind_attr_id, code = self.add_attribute(
                'char', 'My Test Char', 'x_test_char')
   
            export_record(self.session, 'magento.product.attribute',
                          bind_attr_id)

            self.assertEqual(len(calls_done), 1)
            method, (data,) = calls_done[0]
            self.assertEqual(method, 'product_attribute.create')
            self.assertEqual(data['attribute_code'], code)
            self.assertEqual(data['frontend_input'], 'text')
Exemplo n.º 10
0
    def test_30_export_category_with_openerp_parent_dependency(self):
        """ Test export of category"""
        response = {
            'catalog_category.create':
            self.get_magento_helper('magento.product.category').get_next_id,
        }
        cr = self.cr
        uid = self.uid
        with mock_api(response, key_func=lambda m, a: m) as calls_done:
            mag_categ_model = self.registry('magento.product.category')

            parent_mag_categ_id = mag_categ_model.create(
                cr, uid, {
                    'name': 'My Parent Category',
                    'backend_id': self.backend_id,
                })

            parent_mag_categ = mag_categ_model.browse(cr, uid,
                                                      parent_mag_categ_id)

            mag_categ_id = mag_categ_model.create(
                cr, uid, {
                    'name': 'My Category',
                    'backend_id': self.backend_id,
                    'parent_id': parent_mag_categ.openerp_id.id,
                })

            export_record(self.session, 'magento.product.category',
                          mag_categ_id)

            parent_mag_categ = parent_mag_categ.browse()[0]

            self.assertEqual(len(calls_done), 2)

            method, (parent_id, data) = calls_done[0]
            self.assertEqual(method, 'catalog_category.create')
            self.assertEqual(parent_id, 1)
            self.assertEqual(data['name'], 'My Parent Category')

            method, (parent_id, data) = calls_done[1]
            self.assertEqual(method, 'catalog_category.create')
            self.assertEqual(parent_id, parent_mag_categ.magento_id)
            self.assertEqual(data['name'], 'My Category')
Exemplo n.º 11
0
    def test_20_export_category_with_image(self):
        """ Test export of category"""
        response = {
            'catalog_category.create':
            self.get_magento_helper('magento.product.category').get_next_id,
            'ol_catalog_category_media.create':
            'true',
        }
        cr = self.cr
        uid = self.uid
        with mock_api(response, key_func=lambda m, a: m) as calls_done:
            mag_categ_model = self.registry('magento.product.category')
            mag_categ_id = mag_categ_model.create(
                cr, uid, {
                    'name': 'My Category',
                    'image': IMAGE,
                    'image_name': 'myimage.png',
                    'backend_id': self.backend_id,
                })

            export_record(self.session, 'magento.product.category',
                          mag_categ_id, 'image')
            export_product_category_image(self.session,
                                          'magento.product.category',
                                          mag_categ_id, 'image')

            self.assertEqual(len(calls_done), 2)
            method, (parent_id, data) = calls_done[0]
            self.assertEqual(method, 'catalog_category.create')
            self.assertEqual(parent_id, 1)
            self.assertEqual(data['image'], 'myimage.png')
            self.assertEqual(data['thumbnail'], 'myimage.png')
            self.assertEqual(data['name'], 'My Category')

            method, (image_name, image_data) = calls_done[1]
            self.assertEqual(method, 'ol_catalog_category_media.create')
            self.assertEqual(parent_id, 1)
            self.assertEqual(image_name, 'myimage.png')
            self.assertEqual(image_data, IMAGE)
Exemplo n.º 12
0
 def _export_dependencies(self):
     """ Export the dependencies for the product"""
     #TODO add export of category
     attribute_binder = self.get_binder_for_model(
         'magento.product.attribute')
     option_binder = self.get_binder_for_model('magento.attribute.option')
     record = self.binding_record
     for group in record.attribute_group_ids:
         for attribute in group.attribute_ids:
             attribute_ext_id = attribute_binder.to_backend(
                 attribute.attribute_id.id, wrap=True)
             if attribute_ext_id:
                 options = []
                 if (attribute.ttype == 'many2one'
                         and record[attribute.name]):
                     options = [record[attribute.name]]
                 elif attribute.ttype == 'many2many':
                     options = record[attribute.name]
                 for option in options:
                     if not option_binder.to_backend(option.id, wrap=True):
                         ctx = self.session.context.copy()
                         ctx['connector_no_export'] = True
                         #TODO FIXME
                         if not option.magento_bind_ids:
                             binding_id = self.session.pool[
                                 'magento.attribute.option'].create(
                                     self.session.cr,
                                     self.session.uid, {
                                         'backend_id':
                                         self.backend_record.id,
                                         'openerp_id': option.id,
                                         'name': option.name,
                                     },
                                     context=ctx)
                         else:
                             binding_id = option.magento_bind_ids[0].id
                         export_record(self.session,
                                       'magento.attribute.option',
                                       binding_id)
Exemplo n.º 13
0
    def test_export_configurable_product(self):
        """ Export a Configurable Product: check """

        response = {'ol_catalog_product.create': '217'}
        with mock_api(response, key_func=lambda m, a: m) as calls_done:
            mag_product_model = self.registry('magento.product.product')

            mag_product_id = mag_product_model.create(
                self.cr, self.uid, {
                    'product_type': 'configurable',
                    'attribute_set_id': self.default_attr_set_id,
                    'default_code': 't-shirt',
                    'description': False,
                    'visibility': '1',
                    'price': 10.0,
                    'weight': 0.0,
                    'website_ids': (),
                    'updated_at': '1970-01-01',
                    'categories': (),
                    'status': '1',
                    'created_at': False,
                    'name': 't-shirt',
                    'description_sale': False,
                    'backend_id': self.backend_id
                })

            export_record(self.session, 'magento.product.product',
                          mag_product_id)
            self.assertEqual(len(calls_done), 1)

            method, data = calls_done[0]
            product_type = data[0]
            attribute_set_id = data[1]
            name = data[2]
            self.assertEqual(method, 'ol_catalog_product.create')
            self.assertEqual(product_type, 'configurable')
            self.assertEqual(attribute_set_id, '9')
            self.assertEqual(name, 't-shirt')
Exemplo n.º 14
0
    def test_10_export_one_image(self):
        """ Export one Image """
        response = {
            'catalog_product_attribute_media.create':
            self.image_helper.get_next_id,
        }

        with mock_api(response, key_func=lambda m, a: m) as calls_done:
            export_record(self.session, 'magento.product.image',
                          self.mag_image_1_id)

            self.assertEqual(len(calls_done), 1)
            result_expected = {
                'file': {
                    'content': IMAGE,
                    'name': 'image_1',
                    'mime': 'image/jpeg',
                },
                'label': 'image_1',
                'types': ['image', 'small_image', 'thumbnail'],
                'position': 1,
            }
            self.check_image_call(calls_done[0], result_expected)
Exemplo n.º 15
0
    def test_10_export_category(self):
        """ Test export of category"""
        response = {
            'catalog_category.create':
            self.get_magento_helper('magento.product.category').get_next_id,
        }
        cr = self.cr
        uid = self.uid
        with mock_api(response, key_func=lambda m, a: m) as calls_done:
            mag_categ_model = self.registry('magento.product.category')
            mag_categ_id = mag_categ_model.create(
                cr, uid, {
                    'name': 'My Category',
                    'backend_id': self.backend_id,
                })

            export_record(self.session, 'magento.product.category',
                          mag_categ_id)

            self.assertEqual(len(calls_done), 1)
            method, (parent_id, data) = calls_done[0]
            self.assertEqual(method, 'catalog_category.create')
            self.assertEqual(parent_id, 1)
 def test_1_export_partner(self):
     """ Test export of partner"""
     partner_helper = self.get_magento_helper('magento.res.partner')
     address_helper = self.get_magento_helper('magento.address')
     response = {
         'customer.create': partner_helper.get_next_id,
         'customer_address.create': address_helper.get_next_id,
     }
     cr = self.cr
     uid = self.uid
     with mock_api(response, key_func=lambda m, a: m) as calls_done:
         mag_partner_model = self.registry('magento.res.partner')
         mag_partner_id = mag_partner_model.create(cr, uid, {
             'website_id': self.website_id,
             'openerp_id': self.partner_id,
             })
         export_record(self.session, 'magento.res.partner', mag_partner_id)
         self.assertEqual(len(calls_done), 3)
         method, [values] = calls_done[0]
         self.assertEqual(method, 'customer.create')
         self.assertEqual(values['email'], '*****@*****.**')
         self.assertEqual(values['firstname'], 'Partner')
         self.assertEqual(values['lastname'], 'Partnerbis')
 def test_1_export_partner(self):
     """ Test export of partner"""
     partner_helper = self.get_magento_helper('magento.res.partner')
     address_helper = self.get_magento_helper('magento.address')
     response = {
         'customer.create': partner_helper.get_next_id,
         'customer_address.create': address_helper.get_next_id,
     }
     cr = self.cr
     uid = self.uid
     with mock_api(response, key_func=lambda m, a: m) as calls_done:
         mag_partner_model = self.registry('magento.res.partner')
         mag_partner_id = mag_partner_model.create(
             cr, uid, {
                 'website_id': self.website_id,
                 'openerp_id': self.partner_id,
             })
         export_record(self.session, 'magento.res.partner', mag_partner_id)
         self.assertEqual(len(calls_done), 3)
         method, [values] = calls_done[0]
         self.assertEqual(method, 'customer.create')
         self.assertEqual(values['email'], '*****@*****.**')
         self.assertEqual(values['firstname'], 'Partner')
         self.assertEqual(values['lastname'], 'Partnerbis')
Exemplo n.º 18
0
    def _export_dependencies(self):
        """ Export the dependencies for the product"""
        if not self.binding_record.magento_id:
            export_record(
                self.session, 'magento.product.product', self.binding_record.id)
        record = self.binding_record

        #Check and update configurable params
        super_attribute_adapter = self.get_connector_unit_for_model(
            GenericAdapter, 'magento.super.attribute')

        magento_attr_ids = []
        data = super_attribute_adapter.list(record.magento_id)
        res = {x['attribute_id']: x['product_super_attribute_id'] for x in data}
        attr_binder = self.get_binder_for_model('magento.product.attribute')
        for dimension in record.dimension_ids:
            value_ids = self.session.search('dimension.value', [
                ('dimension_id', '=', dimension.id),
                ('product_tmpl_id', '=', record.product_tmpl_id.id),
                ])
            if value_ids and not record.openerp_id[dimension.name]:
                magento_attr_id = attr_binder.to_backend(
                        dimension.id, wrap=True)
                if magento_attr_id in res:
                    #TODO REFACTORME
                    bind_attribute_ids = self.session.search(
                        'magento.product.attribute',[
                            ['magento_id', '=', magento_attr_id],
                            ])
                    bind_attribute = self.session.browse(
                        'magento.product.attribute', bind_attribute_ids[0])

                    if not self.session.search('magento.super.attribute', [
                        ['backend_id', '=', self.backend_record.id],
                        ['magento_id', '=', res[magento_attr_id]],
                        ['mag_product_display_id', '=', record.id],
                        ['attribute_id', '=', bind_attribute.openerp_id.id],
                        ]):

                        self.session.create('magento.super.attribute',{
                            'backend_id': self.backend_record.id,
                            'magento_id': res[magento_attr_id],
                            'mag_product_display_id': record.id,
                            'attribute_id': bind_attribute.openerp_id.id,
                            })
                    del res[magento_attr_id]
                else:
                    magento_attr_ids.append(magento_attr_id)
        for magento_attr_id in magento_attr_ids:
            #TODO REFACTORME
            bind_attribute_ids = self.session.search(
                'magento.product.attribute',[
                    ['magento_id', '=', magento_attr_id],
                    ])
            bind_attribute = self.session.browse(
                'magento.product.attribute', bind_attribute_ids[0])
            labels = {}
            storeview_ids = self.session.search(
                'magento.storeview',
                [('backend_id', '=', self.backend_record.id)])
            for storeview in self.session.browse('magento.storeview', storeview_ids):
                labels[storeview.magento_id] = bind_attribute.openerp_id.field_description
            mag_id = super_attribute_adapter.create(
                self.binding_record.magento_id, magento_attr_id, '0', labels)
            self.session.create('magento.super.attribute',{
                'backend_id':  self.backend_record.id,
                'magento_id': mag_id,
                'mag_product_display_id': record.id,
                'attribute_id': bind_attribute.openerp_id.id,
                })
        for magento_attr_id, super_attribute_id in res.items():
            super_attribute_adapter.unlink(super_attribute_id)




        #Export simple product if necessary
        for product in record.display_for_product_ids:
            binding_id = self.session.search(self.model._name, [
                ['openerp_id', '=', product.id],
                ['backend_id', '=', self.backend_record.id],
            ])
            if binding_id:
                if not self.binder.to_backend(binding_id[0]):
                    export_record(
                        self.session, 'magento.product.product', binding_id[0])
            elif self.backend_record.export_simple_product_on_fly\
                 and product.sale_ok: #TODO FIXME
                vals = self._prepare_magento_binding(product)
                sess = self.session
                context = sess.context.copy()
                context['connector_no_export'] = True
                binding_id = sess.pool['magento.product.product'].\
                        create(sess.cr, sess.uid, vals, context=context)
                export_record(
                    self.session, 'magento.product.product', binding_id)