Exemple #1
0
    def categories(self, record):
        mag_categories = record['categories']
        binder = self.binder_for('magento.product.category')

        category_ids = []
        main_categ_id = None

        for mag_category_id in mag_categories:
            cat_id = binder.to_odoo(mag_category_id, unwrap=True)
            if cat_id is None:
                raise MappingError("The product category with "
                                   "magento id %s is not imported." %
                                   mag_category_id)

            category_ids.append(cat_id)

        if category_ids:
            main_categ_id = category_ids.pop(0)

        if main_categ_id is None:
            default_categ = self.backend_record.default_category_id
            if default_categ:
                main_categ_id = default_categ.id

        result = {'categ_ids': [(6, 0, category_ids)]}
        if main_categ_id:  # Odoo assign 'All Products' if not specified
            result['categ_id'] = main_categ_id
        return result
Exemple #2
0
 def journal(self, record):
     journal = self.backend_record.refund_journal_id
     if not journal:
         raise MappingError(
             _('The refund journal must be configured on '
               'the PrestaShop Backend.'))
     return {'journal_id': journal.id}
Exemple #3
0
    def categories(self, record):
        if record:
            odoo_categories = record.woo_categ_ids

            need_append = True
            for odoo_category in odoo_categories:
                if odoo_category.id == record.categ_id.id:
                    need_append = False
            if need_append:
                odoo_categories += record.categ_id

            binder = self.binder_for('woo.product.category')
            woo_category_ids = []
            for odoo_category in odoo_categories:
                odoo_category_id = odoo_category.id
                woo_category_id = binder.to_backend(odoo_category_id,
                                                    wrap=True).woo_id
                if woo_category_id is None:
                    raise MappingError("The product category with "
                                       "odoo id %s is not exported." %
                                       odoo_category_id)
                woo_category_ids.append({'id': woo_category_id})

            result = {'categories': woo_category_ids}
            return result
Exemple #4
0
    def categories(self, record):
        """ Fetch categories key for Magento 1.x or category_ids
        for Magento 2.x from product record """
        mag_categories = record.get('category_ids') or record.get(
            'categories', [])
        binder = self.binder_for('magento.product.category')

        category_ids = []
        main_categ_id = None

        for mag_category_id in mag_categories:
            cat = binder.to_internal(mag_category_id, unwrap=True)
            if not cat:
                raise MappingError("The product category with "
                                   "magento id %s is not imported." %
                                   mag_category_id)

            category_ids.append(cat.id)

        if category_ids:
            main_categ_id = category_ids.pop(0)

        if main_categ_id is None:
            default_categ = self.backend_record.default_category_id
            if default_categ:
                main_categ_id = default_categ.id

        result = {'categ_ids': [(6, 0, category_ids)]}
        if main_categ_id:  # OpenERP assign 'All Products' if not specified
            result['categ_id'] = main_categ_id
        return result
Exemple #5
0
 def category(self, record):
     categ_id = record['categ_id']
     binder = self.binder_for('odoo.product.category')
     #binder.model = 'odoo.product.category'
     cat = binder.wrap_binding(categ_id)
     if not cat:
         raise MappingError("The product category with "
                            "odoo id %s is not available." % categ_id)
     return {'categ_id': cat}
    def category(self, record):
        categ_id = record['categ_id']
        binder = self.binder_for('odoo.product.category')

        cat = binder.to_internal(categ_id.id, unwrap=True)
        if not cat:
            raise MappingError("The product category with "
                               "odoo id %s is not imported." % mag_category_id)
        return {'categ_id': cat.id}
Exemple #7
0
 def sale_team(self, record):
     if record.get("odoo_shop_id"):
         crm_team = self.env["crm.team"].search([
             ("prestashop_id", "=", record.get("odoo_shop_id"))
         ])
         if not crm_team:
             raise MappingError(
                 _("CRM team with {} prestashop id not found.").format(
                     record.get("plazo")))
         return {"team_id": crm_team.id}
Exemple #8
0
 def property_payment_term_id(self, record):
     if record.get("plazo") and record.get("plazo") != "0":
         payment_term = self.env["account.payment.term"].search([
             ("prestashop_name", "=", record.get("plazo"))
         ])
         if not payment_term:
             raise MappingError(
                 _("Payment term with {} prestashop name not found.").
                 format(record.get("plazo")))
         return {"property_payment_term_id": payment_term.id}
Exemple #9
0
 def customer_payment_mode_id(self, record):
     if record.get("f_pago") and record.get("f_pago") in ["1", "2"]:
         payment_mode = self.env["account.payment.mode"].search([
             ("prestashop_name", "=", record.get("f_pago"))
         ])
         if not payment_mode:
             raise MappingError(
                 _("Payment mode with {} prestashop name not found.").
                 format(record.get("f_pago")))
         return {"customer_payment_mode_id": payment_mode.id}
     return {}
Exemple #10
0
    def parent_id(self, record):
        if not record.get('parent_id'):
            return
        binder = self.binder_for()
        category_id = binder.to_odoo(record['parent_id'], unwrap=True)
        mag_cat_id = binder.to_odoo(record['parent_id'])

        if category_id is None:
            raise MappingError("The product category with "
                               "magento id %s is not imported." %
                               record['parent_id'])
        return {'parent_id': category_id, 'magento_parent_id': mag_cat_id}
 def parent_id(self, rec):
     if rec:
         if not rec['parent']:
             return
         binder = self.binder_for()
         category_id = binder.to_openerp(rec['parent'], unwrap=True)
         woo_cat_id = binder.to_openerp(rec['parent'])
         if category_id is None:
             raise MappingError("The product category with "
                                "woo id %s is not imported." %
                                rec['parent'])
         return {'parent_id': category_id, 'woo_parent_id': woo_cat_id}
Exemple #12
0
 def author(self, record):
     jira_author = record['author']
     jira_author_key = jira_author['key']
     binder = self.binder_for('jira.res.users')
     user = binder.to_internal(jira_author_key, unwrap=True)
     if not user:
         email = jira_author['emailAddress']
         raise MappingError(
             _('No user found with login "%s" or email "%s".'
               'You must create a user or link it manually if the '
               'login/email differs.') % (jira_author_key, email)
         )
     return {'user_id': user.id}
Exemple #13
0
    def parent_id(self, record):
        if not record.get('parent_id'):
            return
        binder = self.binder_for()
        parent_binding = binder.to_internal(record['parent_id'])

        if not parent_binding:
            raise MappingError("The product category with "
                               "magento id %s is not imported." %
                               record['parent_id'])

        parent = parent_binding.odoo_id
        return {'parent_id': parent.id, 'magento_parent_id': parent_binding.id}
Exemple #14
0
    def customer_group_id(self, record):
        # import customer groups
        binder = self.binder_for(model='magento.res.partner.category')
        category_id = binder.to_odoo(record['group_id'], unwrap=True)

        if category_id is None:
            raise MappingError("The partner category with "
                               "magento id %s does not exist" %
                               record['group_id'])

        # FIXME: should remove the previous tag (all the other tags from
        # the same backend)
        return {'category_id': [(4, category_id)]}
Exemple #15
0
    def categ_ids(self, record):
        categ_ids = []
        for categ in record.get('categ_ids', []):
            binder = self.binder_for('odoo.product.category')
            model_binding = binder.to_internal(categ)

            if not model_binding:
                raise MappingError(
                    "The odoo.product.category with distant Odoo id %s is not import."
                    % (categ))
            else:
                categ_ids.append(model_binding.odoo_id.id)

        return {'categ_ids': [(6, 0, categ_ids)]}
Exemple #16
0
    def picking_id(self, record): 
        if not record.delivery_id:
            return
        binder = self.binder_for('odoo.simple.delivery')
        picking_id = binder.to_external(record.delivery_id.id, wrap=True)

        if not picking_id:
            raise MappingError("The delivery with "
                               "internal Odoo id %s is not export." %
                               record.delivery_id.id)

        return {
            'picking_id': picking_id,
        }
Exemple #17
0
    def partner_id(self, record):
        if not record.partner_id:
            return
        binder = self.binder_for('odoo.res.partner')
        partner_id = binder.to_external(record.partner_id.id, wrap=True)

        if not partner_id:
            raise MappingError("The partner with "
                               "distant Odoo id %s is not export." %
                               record.partner_id.id)

        return {
            'partner_id': partner_id,
        }
Exemple #18
0
 def assignee(self, record):
     assignee = record['fields'].get('assignee')
     if not assignee:
         return {'user_id': False}
     jira_key = assignee['key']
     binder = self.binder_for('jira.res.users')
     user = binder.to_internal(jira_key, unwrap=True)
     if not user:
         email = assignee['emailAddress']
         raise MappingError(
             _('No user found with login "%s" or email "%s".'
               'You must create a user or link it manually if the '
               'login/email differs.') % (jira_key, email))
     return {'user_id': user.id}
Exemple #19
0
 def author(self, record):
     jira_author = record['author']
     jira_author_key = jira_author['key']
     binder = self.binder_for('jira.res.users')
     user = binder.to_internal(jira_author_key, unwrap=True)
     if not user:
         email = jira_author['emailAddress']
         raise MappingError(
             _('No user found with login "%s" or email "%s".'
               'You must create a user or link it manually if the '
               'login/email differs.') % (jira_author_key, email))
     employee = self.env['hr.employee'].with_context(
         active_test=False, ).search([('user_id', '=', user.id)], limit=1)
     return {'user_id': user.id, 'employee_id': employee.id}
Exemple #20
0
    def product_id(self, record):
        if not record.product_id:
            return
        binder = self.binder_for('odoo.product.product')
        product_id = binder.to_external(record.product_id.id, wrap=True)

        if not product_id:
            raise MappingError("The product with "
                               "internal Odoo id %s is not export." %
                               record.product_id.id)

        return {
            'product_id': product_id,
        }
Exemple #21
0
    def category_id(self, record):
        if not record.get('category_id'):
            return
        binder = self.binder_for('odoo.product.uom.categ')
        category_binding = binder.to_internal(record['category_id'][0])

        if not category_binding:
            raise MappingError("The product category with "
                               "distant Odoo id %s is not import." %
                               record['category_id'][0])

        category = category_binding.odoo_id
        return {
            'category_id': category.id,
        }
Exemple #22
0
    def breast_pump_id(self, record):
        if not record.breast_pump_id:
            return

        binder = self.binder_for('odoo.breast.pump')
        breast_pump_id = binder.to_external(record.breast_pump_id.id, wrap=True)

        if not breast_pump_id:
            raise MappingError("The breast pump with "
                               "internal Odoo id %s is not export." %
                               record.breast_pump_id.id)

        return {
            'breast_pump_id': breast_pump_id,
        }
Exemple #23
0
    def lot_id(self, record):
        if not record.get('breast_pump_id'):
            return
        binder = self.binder_for('odoo.breast.pump')
        bp_binder = binder.to_internal(record['breast_pump_id'][0])

        if not bp_binder:
            raise MappingError("The breast pump with "
                               "distant Odoo id %s is not import." %
                               record['breast_pump_id'][0])

        breast_pump = bp_binder.odoo_id
        return {
            'breast_pump_id': breast_pump.id,
        }
Exemple #24
0
    def product_variant_ids(self, record):
        if not record.get('product_variant_ids'):
            return
        binder = self.binder_for('odoo.product.product')
        variant_ids = []
        for variant in record.get('product_variant_ids'):
            variant_binding = binder.to_internal(variant)

            if not variant_binding:
                raise MappingError("The product with "
                                   "distant Odoo id %s is not import." %
                                   variant)

            variant_ids.append(variant_binding.odoo_id)
        return {'product_variant_ids': [(6, 0, variant_ids)]}
Exemple #25
0
    def attribute_id(self, record):
        if not record.get('attribute_id'):
            return
        binder = self.binder_for('odoo.product.attribute')
        attribute_binding = binder.to_internal(record['attribute_id'][0])

        if not attribute_binding:
            raise MappingError("The product attribute with "
                               "distant Odoo id %s is not import." %
                               record['attribute_id'][0])

        attribute = attribute_binding.odoo_id
        return {
            'attribute_id': attribute.id,
        }
Exemple #26
0
    def partner_id(self, record):
        if not record.get('partner_id'):
            return
        binder = self.binder_for('odoo.res.partner')
        partner_binding = binder.to_internal(record['partner_id'][0])

        if not partner_binding:
            raise MappingError("The partner with "
                               "distant Odoo id %s is not import." %
                               record['partner_id'][0])

        partner = partner_binding.odoo_id
        return {
            'partner_id': partner.id,
        }
Exemple #27
0
    def product_id(self, record):
        if not record.get('product_id'):
            return
        binder = self.binder_for('odoo.product.product')
        product_binding = binder.to_internal(record['product_id'][0])

        if not product_binding:
            raise MappingError("The product with "
                               "distant Odoo id %s is not import." %
                               record['product_id'][0])

        product = product_binding.odoo_id
        return {
            'product_id': product.id,
        }
Exemple #28
0
    def customer_group_id(self, record):
        # import customer groups
        if record['group_id'] == 0:
            category = self.env.ref('connector_magento.category_no_account')
        else:
            binder = self.binder_for(model='magento.res.partner.category')
            category = binder.to_internal(record['group_id'], unwrap=True)

        if not category:
            raise MappingError("The partner category with "
                               "magento id %s does not exist" %
                               record['group_id'])

        # FIXME: should remove the previous tag (all the other tags from
        # the same backend)
        return {'category_id': [(4, category.id)]}
 def parent_id(self, record):
     if record['product_category']:
         rec = record['product_category']
         if not rec['parent']:
             return
         binder = self.binder_for()
         # Get id of product.category model
         category_id = binder.to_internal(rec['parent'], unwrap=True)
         # Get id of woo.product.category model
         woo_cat_id = binder.to_internal(rec['parent'])
         if category_id is None:
             raise MappingError("The product category with "
                                "woo id %s is not imported." %
                                rec['parent'])
         return {
             'parent_id': category_id.id,
             'woo_parent_id': woo_cat_id.id
         }
Exemple #30
0
    def owner_id(self, record):
        if not record.get('owner_model') or not record.get('owner_id'):
            return
        binding_model = record.get('owner_model')
        binding_id = record.get('owner_id')
        binder = self.binder_for('odoo.%s' % binding_model)
        if not binder:
            return

        record_binding = binder.to_internal(binding_id)
        if not record_binding:
            raise MappingError("The %s with "
                               "distant Odoo id %s is not import." % (
                                   binding_model,
                                   binding_id,
                               ))

        return {
            'owner_id': record_binding.odoo_id.id,
        }