コード例 #1
0
    def export(self):
        context = self.env.context or {}

        res = False
        if context.get('active_ids'):
            res = context['active_ids']
        model = context.get('active_model')
        products = self.env[model].browse(res)
        for product in products:
            if product.product_type == 'configurable':
                for child in product.magento_product_ids:
                    if not child.magento_sku:
                        raise ValidationError(
                            "Sku is not set for the variant of %s" %
                            child.name)
                    if not child.attribute_set_id:
                        raise ValidationError(
                            "Attribute set is not selected for %s" %
                            child.name)
            if not product.magento_sku:
                raise ValidationError("Sku is not set for %s" % product.name)
            if not product.attribute_set_id:
                raise ValidationError("Attribute set is not set for %s" %
                                      product.name)

        session = ConnectorSession(self.env.cr,
                                   self.env.uid,
                                   context=self.env.context)

        for record_id in res:
            on_export_product_to_magento.fire(session, model, record_id)
コード例 #2
0
 def import_partners(self):
     session = ConnectorSession(self.env.cr,
                                self.env.uid,
                                context=self.env.context)
     import_start_time = datetime.now()
     for website in self:
         backend_id = website.backend_id.id
         if website.import_partners_from_date:
             from_string = fields.Datetime.from_string
             from_date = from_string(website.import_partners_from_date)
         else:
             from_date = None
         partner_import_batch.delay(
             session, 'res.partner', backend_id, {
                 'magento_website_id': website.magento_id,
                 'from_date': from_date,
                 'to_date': import_start_time
             })
     # Records from Magento are imported based on their `created_at`
     # date.  This date is set on Magento at the beginning of a
     # transaction, so if the import is run between the beginning and
     # the end of a transaction, the import of a record may be
     # missed.  That's why we add a small buffer back in time where
     # the eventually missed records will be retrieved.  This also
     # means that we'll have jobs that import twice the same records,
     # but this is not a big deal because they will be skipped when
     # the last `sync_date` is the same.
     next_time = import_start_time - timedelta(seconds=IMPORT_DELTA_BUFFER)
     next_time = fields.Datetime.to_string(next_time)
     self.write({'import_partners_from_date': next_time})
     return True
コード例 #3
0
 def export_shipment_to_magento(self,backends):
     session = ConnectorSession(self.env.cr, self.env.uid,context=self.env.context)
     pickings = self.search([('is_magento_picking','=',True),('is_exported_to_magento','=',False),('state','in',['done']),('backend_id','in',backends.ids)])
     for picking in pickings:
         if picking.picking_type_id.code != 'outgoing':
             continue
         export_picking_done.delay(session,'stock.picking',picking.id)
コード例 #4
0
    def import_sale_order_by_number(self, increment_id):
        session = ConnectorSession(self.env.cr,
                                   self.env.uid,
                                   context=self.env.context)
        for storeview in self:
            if storeview.no_sales_order_sync:
                _logger.debug(
                    "The storeview '%s' is active in Magento "
                    "but is configured not to import the "
                    "sales orders", storeview.name)
                continue
            try:
                backend_id = storeview.backend_id.id
                self = SaleOrderBatchImport
                filters = {
                    'magento_storeview_id': storeview.magento_id,
                    'increment_id': increment_id
                }
                env = get_environment(session, 'magento.sale.order',
                                      backend_id)
                importer = env.get_connector_unit(SaleOrderBatchImport)
                importer.run(filters)
            except FailedJobError as error:
                raise ValidationError("Error While importing sale order " +
                                      "\n" + str(error))

        return True
コード例 #5
0
 def _after_export(self):
     backend = self.binding_record.backend_id
     session = ConnectorSession(self.env.cr,
                                self.env.uid,
                                context=self.env.context)
     env = get_environment(session, 'magento.attribute.set', backend.id)
     importer = env.get_connector_unit(AttributeSetImporter)
     importer.run(self.magento_id)
コード例 #6
0
 def import_attribute_set(self, backends):
     for backend in backends:
         backend.check_magento_structure()
         session = ConnectorSession(self.env.cr, self.env.uid,
                                    self.env.context)
         import_batch.delay(session, 'magento.attribute.set', backend.id)
         backend.write({'last_attribute_set_import_date': datetime.now()})
     return True
コード例 #7
0
 def import_customer_group(self, backends):
     session = ConnectorSession(self.env.cr,
                                self.env.uid,
                                context=self.env.context)
     for backend in backends:
         backend.check_magento_structure()
         import_batch.delay(session, 'magento.res.partner.category',
                            backend.id)
     return True
コード例 #8
0
 def import_attribute_sets(self):
     if not hasattr(self.ids, '__iter__'):
         ids = [self.ids]
     self.check_magento_structure()
     session = ConnectorSession(self.env.cr, self.env.uid, self.env.context)
     for backend in self:
         import_batch.delay(session, 'magento.attribute.set', backend.id)
         backend.write({'last_attribute_set_import_date': datetime.now()})
     return True
コード例 #9
0
 def unlink(self):
     session = ConnectorSession(self.env.cr, self.env.uid, self.env.context)
     if self.backend_id.image_delete_on_magento:
         env = get_environment(session, 'magento.product.image',
                               self.backend_id.id)
         image_deleter = env.get_connector_unit(ProductImageAdapter)
         image_deleter.delete(self.magento_id,
                              self.magento_product_id.magento_sku)
     res = super(MagentoProductImage, self).unlink()
     return res
コード例 #10
0
 def synchronize_metadata(self):
     session = ConnectorSession(self.env.cr,
                                self.env.uid,
                                context=self.env.context)
     for backend in self:
         for model in ('magento.website', 'magento.store',
                       'magento.storeview'):  #Import directly without Delay
             import_batch(session, model, backend.id)
         backend.import_attribute_sets()
         backend.import_payment_method()
         backend.import_delivery_method()
     return True
コード例 #11
0
ファイル: model.py プロジェクト: westlyou/odoo-magento2
 def open_related_action(self):
     """ Open the related action associated to the job """
     self.ensure_one()
     session = ConnectorSession(self.env.cr,
                                self.env.uid,
                                context=self.env.context)
     storage = OpenERPJobStorage(session)
     job = storage.load(self.uuid)
     action = job.related_action(session)
     if action is None:
         raise exceptions.Warning(_('No action available for this job'))
     return action
コード例 #12
0
    def import_sale_orders(self):
        session = ConnectorSession(self.env.cr,
                                   self.env.uid,
                                   context=self.env.context)
        import_start_time = datetime.now()
        for storeview in self:
            if storeview.no_sales_order_sync:
                _logger.debug(
                    "The storeview '%s' is active in Magento "
                    "but is configured not to import the "
                    "sales orders", storeview.name)
                continue
            backend_id = storeview.backend_id.id
            if storeview.import_orders_from_date:
                from_string = fields.Datetime.from_string
                from_date = from_string(storeview.import_orders_from_date)
            else:
                from_date = None

            filters = {
                'magento_storeview_id': storeview.magento_id,
                'from_date': from_date,
                'to_date': import_start_time
            }

            if storeview.backend_id.allow_so_import_on_fly:
                try:
                    env = get_environment(session, 'magento.sale.order',
                                          backend_id)
                    importer = env.get_connector_unit(SaleOrderBatchImport)
                    importer.run(filters)
                except Exception as error:
                    raise ValidationError(
                        "Error While Preparing batch for sale order" + "\n" +
                        str(error))
            else:
                sale_order_import_batch.delay(session,
                                              'magento.sale.order',
                                              backend_id,
                                              filters,
                                              priority=1)
        # Records from Magento are imported based on their `created_at`
        # date.  This date is set on Magento at the beginning of a
        # transaction, so if the import is run between the beginning and
        # the end of a transaction, the import of a record may be
        # missed.  That's why we add a small buffer back in time where
        # the eventually missed records will be retrieved.  This also
        # means that we'll have jobs that import twice the same records,
        # but this is not a big deal because the sales orders will be
        # imported the first time and the jobs will be skipped on the
        # subsequent imports
        return True
コード例 #13
0
 def import_product_category(self,backends):
     session = ConnectorSession(self.env.cr, self.env.uid,self.env.context)
     for backend in backends:
         backend.check_magento_structure()
         from_date = getattr(backend, 'last_product_category_import_date')
         if from_date:
             from_date = fields.Datetime.from_string(from_date)
         else:
             from_date = None
         import_batch.delay(session, 'magento.product.category',
                            backend.id,
                            filters={'from_date': from_date,
                                     'to_date': datetime.now()})
         backend.write({'last_product_category_import_date' : datetime.now()})
     return True
コード例 #14
0
ファイル: model.py プロジェクト: westlyou/odoo-magento2
 def _change_job_state(self, state, result=None):
     """ Change the state of the `Job` object itself so it
     will change the other fields (date, result, ...)
     """
     session = ConnectorSession(self.env.cr,
                                self.env.uid,
                                context=self.env.context)
     storage = OpenERPJobStorage(session)
     for job in self:
         job = storage.load(job.uuid)
         if state == DONE:
             job.set_done(result=result)
         elif state == PENDING:
             job.set_pending(result=result)
         else:
             raise ValueError('State not supported: %s' % state)
         storage.store(job)
コード例 #15
0
 def _import_from_date(self, model, from_date_field):
     session = ConnectorSession(self.env.cr,
                                self.env.uid,
                                context=self.env.context)
     import_start_time = datetime.now()
     for backend in self:
         backend.check_magento_structure()
         from_date = getattr(backend, from_date_field)
         if from_date:
             from_date = fields.Datetime.from_string(from_date)
         else:
             from_date = None
         import_batch.delay(session,
                            model,
                            backend.id,
                            filters={
                                'from_date': from_date,
                                'to_date': import_start_time
                            })
コード例 #16
0
 def import_attribute(self, backends):
     session = ConnectorSession(self.env.cr, self.env.uid, self.env.context)
     for backend in backends:
         backend.check_magento_structure()
         for backend in backends:
             from_date = backend.last_attribute_import_date or False
             if from_date:
                 from_date = datetime.strptime(
                     from_date, DEFAULT_SERVER_DATETIME_FORMAT)
             else:
                 from_date = None
             import_batch.delay(
                 session,
                 'magento.product.attribute',
                 backend.id,
                 filters=[
                     from_date
                     and from_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
                     or ''
                 ])
             backend.write({'last_attribute_import_date': datetime.now()})
     return True
コード例 #17
0
    def test_connection(self):
        self.ensure_one()
        try:
            context = self._context
            session = ConnectorSession(self._cr, self._uid, context=context)
            backend_id = self.id
            mage_env = get_environment(session, "magento.website", backend_id)
            adapter = mage_env.get_connector_unit(WebsiteAdapter)
            result = adapter.search()
        except NetworkRetryableError as e:
            raise UserError('A network error caused the failure of the job: '
                            '%s' % e)
        except FailedJobError as e:
            raise UserError(
                'Given Credentials is incorrect, please provide correct Credentials.'
            )
        except Exception as e:
            raise UserError(
                "Connection Test Failed! Here is what we got instead:\n \n%s" %
                ustr(e))

        raise UserError(
            "Connection Test Succeeded! Everything seems properly set up!")
コード例 #18
0
 def update_attribute_set(self):
     session = ConnectorSession(self.env.cr, self.env.uid, self.env.context)
     for record in self:
         export_record.delay(session, 'magento.attribute.set', record.id)
コード例 #19
0
 def update_product_category(self):
     session = ConnectorSession(self.env.cr, self.env.uid,self.env.context)
     for record in self:
         export_record.delay(session,'magento.product.category',record.id)
コード例 #20
0
ファイル: invoice.py プロジェクト: westlyou/odoo-magento2
 def export_invoice_to_magento(self,backends):
     session = ConnectorSession(self.env.cr, self.env.uid,context=self.env.context)
     invoices = self.search([('is_magento_invoice','=',True),('is_exported_to_magento','=',False),('backend_id','in',backends.ids)])
     for invoice in invoices:
         if invoice.magento_payment_method_id.create_invoice_on != 'na':
             export_invoice.delay(session,self._name,invoice.id)
コード例 #21
0
 def export_product_attribute(self):
     session = ConnectorSession(self.env.cr, self.env.uid, self.env.context)
     for record in self:
         export_record.delay(session, 'magento.product.attribute',
                             record.id)