Exemple #1
0
 def setUp(self):
     super(test_event, self).setUp()
     self.consumer1 = lambda session, model_name: None
     self.consumer2 = lambda session, model_name: None
     self.event = Event()
     self.session = ConnectorSession(self.cr,
                                     self.uid)
Exemple #2
0
 def setUp(self):
     super(SetUpMagentoBase, self).setUp()
     self.backend_model = self.env['magento.backend']
     self.session = ConnectorSession(self.env.cr,
                                     self.env.uid,
                                     context=self.env.context)
     warehouse = self.env.ref('stock.warehouse0')
     self.backend = self.backend_model.create({
         'name': 'Test Magento',
         'version': '1.7',
         'location': 'http://anyurl',
         'username': '******',
         'warehouse_id': warehouse.id,
         'password': '******'
     })
     self.backend_id = self.backend.id
     # payment method needed to import a sale order
     workflow = self.env.ref('sale_automatic_workflow.manual_validation')
     journal = self.env.ref('account.check_journal')
     self.payment_term = self.env.ref('account.'
                                      'account_payment_term_advance')
     self.env['payment.method'].create({
         'name':
         'checkmo',
         'workflow_process_id':
         workflow.id,
         'import_rule':
         'always',
         'days_before_cancel':
         0,
         'payment_term_id':
         self.payment_term.id,
         'journal_id':
         journal.id
     })
Exemple #3
0
 def setUp(self):
     super(TestJobChannels, self).setUp()
     self.function_model = self.env['queue.job.function']
     self.channel_model = self.env['queue.job.channel']
     self.job_model = self.env['queue.job']
     self.root_channel = self.env.ref('connector.channel_root')
     self.session = ConnectorSession(self.cr, self.uid, context={})
    def _price_changed(self, vals):
        """ Fire the ``on_product_price_changed`` on all the variants of
        the template if the price of the product could have changed.

        If one of the field used in a sale pricelist item has been
        modified, we consider that the price could have changed.

        There is no guarantee that's the price actually changed,
        because it depends on the pricelists.
        """
        price_fields = self._price_changed_fields()
        if any(field in vals for field in price_fields):
            product_model = self.env['product.product']
            session = ConnectorSession.from_env(self.env)
            products = product_model.search([('product_tmpl_id', 'in',
                                              self.ids)])
            # when the write is done on the product.product, avoid
            # to fire the event 2 times
            if self.env.context.get('from_product_ids'):
                from_product_ids = self.env.context['from_product_ids']
                remove_products = product_model.browse(from_product_ids)
                products -= remove_products
            for product in products:
                on_product_price_changed.fire(session, product_model._name,
                                              product.id)
Exemple #5
0
 def setUp(self):
     super(test_backend_register, self).setUp()
     self.service = 'calamitorium'
     self.version = '1.14'
     self.parent = Backend(self.service)
     self.backend = Backend(parent=self.parent, version=self.version)
     self.session = ConnectorSession(self.cr, self.uid)
Exemple #6
0
 def write(self, vals):
     res = super(StockPicking, self).write(vals)
     if vals.get('carrier_tracking_ref'):
         session = ConnectorSession.from_env(self.env)
         for record_id in self.ids:
             on_tracking_number_added.fire(session, self._name, record_id)
     return res
Exemple #7
0
 def test_change_context_uninitialized(self):
     """ Change the context on a session not initialized with a context """
     session = ConnectorSession.from_env(self.env)
     test_key = 'test_key'
     with session.change_context({test_key: 'value'}):
         self.assertEqual(session.context.get('test_key'), 'value')
     self.assertNotIn(test_key, session.context)
Exemple #8
0
 def test_from_env(self):
     """ ConnectorSession.from_env(env) """
     session = ConnectorSession.from_env(self.env)
     self.assertEqual(session.cr, self.env.cr)
     self.assertEqual(session.uid, self.env.uid)
     self.assertEqual(session.context, self.env.context)
     self.assertEqual(session.pool, self.env.registry)
Exemple #9
0
 def setUp(self):
     super(TestJobStorageMultiCompany, self).setUp()
     self.session = ConnectorSession(self.cr, self.uid, context={})
     self.queue_job = self.env['queue.job']
     grp_connector_manager = self.ref("connector.group_connector_manager")
     User = self.env['res.users']
     Company = self.env['res.company']
     Partner = self.env['res.partner']
     self.other_partner_a = Partner.create(
         {"name": "My Company a",
          "is_company": True,
          "email": "*****@*****.**",
          })
     self.other_company_a = Company.create(
         {"name": "My Company a",
          "partner_id": self.other_partner_a.id,
          "rml_header1": "My Company Tagline",
          "currency_id": self.ref("base.EUR")
          })
     self.other_user_a = User.create(
         {"partner_id": self.other_partner_a.id,
          "company_id": self.other_company_a.id,
          "company_ids": [(4, self.other_company_a.id)],
          "login": "******",
          "name": "my user",
          "groups_id": [(4, grp_connector_manager)]
          })
     self.other_partner_b = Partner.create(
         {"name": "My Company b",
          "is_company": True,
          "email": "*****@*****.**",
          })
     self.other_company_b = Company.create(
         {"name": "My Company b",
          "partner_id": self.other_partner_b.id,
          "rml_header1": "My Company Tagline",
          "currency_id": self.ref("base.EUR")
          })
     self.other_user_b = User.create(
         {"partner_id": self.other_partner_b.id,
          "company_id": self.other_company_b.id,
          "company_ids": [(4, self.other_company_b.id)],
          "login": "******",
          "name": "my user 1",
          "groups_id": [(4, grp_connector_manager)]
          })
Exemple #10
0
def mock_connector_unit(env):
    session = ConnectorSession(env.cr, env.uid, context=env.context)
    backend_record = mock.Mock(name='BackendRecord')
    backend = mock.Mock(name='Backend')
    backend_record.get_backend.return_value = backend
    connector_env = connector.ConnectorEnvironment(backend_record, session,
                                                   'res.users')
    return ConnectorUnit(connector_env)
Exemple #11
0
 def _get_base_adapter(self):
     """
     Get an adapter to test the backend connection
     """
     self.ensure_one()
     env = self.env
     session = ConnectorSession(env.cr, env.uid, context=env.context)
     environment = ConnectorEnvironment(self, session, None)
     return DmsAdapter(environment)
Exemple #12
0
 def setUp(self):
     super(test_mapper_recordsets, self).setUp()
     self.session = ConnectorSession(self.cr, self.uid)
     self.backend = mock.Mock(wraps=Backend('x', version='y'),
                              name='backend')
     backend_record = mock.Mock()
     backend_record.get_backend.return_value = self.backend
     self.connector_env = ConnectorEnvironment(backend_record, self.session,
                                               'res.partner')
 def setUp(self):
     super(SetUpEasypostBase, self).setUp()
     self.backend_model = self.env['easypost.backend']
     self.session = ConnectorSession(
         self.env.cr,
         self.env.uid,
         context=self.env.context,
     )
     self.backend = self.get_easypost_backend()
     self.backend_id = self.backend.id
Exemple #14
0
 def create_new_database(self, async_=None, **kwargs):
     if async_:
         session = ConnectorSession(self._cr, self._uid, self._context)
         job_uuid = async_client_create.delay(session,
                                              self._name,
                                              self.id,
                                              async_=async_,
                                              **kwargs)
     else:
         res = super(SaasPortalPlan,
                     self)._create_new_database(async_=async_, **kwargs)
         return res
Exemple #15
0
    def _price_changed(self, vals):
        """ Fire the ``on_product_price_changed`` if the price
        of the product could have changed.

        If one of the field used in a sale pricelist item has been
        modified, we consider that the price could have changed.

        There is no guarantee that's the price actually changed,
        because it depends on the pricelists.
        """
        price_fields = self._price_changed_fields()
        if any(field in vals for field in price_fields):
            session = ConnectorSession.from_env(self.env)
            for prod_id in self.ids:
                on_product_price_changed.fire(session, self._name, prod_id)
 def enqueue(self, name, action, clouder_job_id):
     session = ConnectorSession(self.env.cr,
                                self.env.uid,
                                context=self.env.context)
     job_uuid = connector_enqueue.delay(session,
                                        self._name,
                                        self.id,
                                        'do_exec',
                                        action,
                                        clouder_job_id,
                                        self.env.context,
                                        description=name,
                                        max_retries=0)
     job_id = self.env['queue.job'].search([('uuid', '=', job_uuid)])[0]
     clouder_job = self.env['clouder.job'].browse(clouder_job_id)
     clouder_job.write({'job_id': job_id.id})
class SaasPortalPlan(models.Model):
    _inherit = 'saas_portal.plan'

    @api.multi
    def create_new_database(self, async=None, **kwargs):
        if async:
            session = ConnectorSession(self._cr, self._uid, self._context)
            job_uuid = async_client_create.delay(session,
                                                 self._name,
                                                 self.id,
                                                 async=async,
                                                 **kwargs)
        else:
            res = super(SaasPortalPlan, self)._create_new_database(async=async,
                                                                   **kwargs)
            return res
Exemple #18
0
 def check_sii(self):
     queue_obj = self.env['queue.job']
     for order in self:
         company = order.company_id
         if company.sii_enabled:
             if not company.use_connector:
                 order._check_simplified()
             else:
                 eta = company._get_sii_eta()
                 session = ConnectorSession.from_env(self.env)
                 new_delay = check_one_simplified.delay(
                     session, 'pos.order', order.id, eta=eta)
                 queue_ids = queue_obj.search([
                     ('uuid', '=', new_delay)
                 ], limit=1)
                 order.simplified_jobs_ids |= queue_ids
Exemple #19
0
    def do_transfer(self):
        # The key in the context avoid the event to be fired in
        # StockMove.action_done(). Allow to handle the partial pickings
        self_context = self.with_context(__no_on_event_out_done=True)
        result = super(StockPicking, self_context).do_transfer()
        session = ConnectorSession.from_env(self.env)
        for picking in self:
            if picking.picking_type_id.code != 'outgoing':
                continue
            if picking.related_backorder_ids:
                method = 'partial'
            else:
                method = 'complete'
            on_picking_out_done.fire(session, 'stock.picking', picking.id,
                                     method)

        return result
Exemple #20
0
 def send_sii(self):
     queue_obj = self.env['queue.job']
     for order in self:
         company = order.company_id
         if company.sii_enabled and company.sii_method == 'auto' and \
                 order.simplified_invoice:
             if not company.use_connector:
                 order._send_simplified_to_sii()
             else:
                 eta = company._get_sii_eta()
                 session = ConnectorSession.from_env(self.env)
                 new_delay = confirm_one_simplified.delay(
                     session, 'pos.order', order.id, eta=eta)
                 queue_ids = queue_obj.search([
                     ('uuid', '=', new_delay)
                 ], limit=1)
                 order.simplified_jobs_ids |= queue_ids
 def update_all_prices(self, cr, uid, ids, context=None):
     """ Update the prices of all the products linked to the
     website. """
     if not hasattr(ids, '__iter__'):
         ids = [ids]
     for website in self.browse(cr, uid, ids, context=context):
         session = ConnectorSession(cr, uid, context=context)
         if website.magento_id == '0':
             # 'Admin' website -> default values
             # Update the default prices on all the products.
             binding_ids = website.backend_id.product_binding_ids
         else:
             binding_ids = website.product_binding_ids
         for binding in binding_ids:
             export_product_price.delay(session,
                                        'magento.product.product',
                                        binding.id,
                                        website_id=website.id)
     return True
Exemple #22
0
    def action_done(self):
        fire_event = not self.env.context.get('__no_on_event_out_done')
        if fire_event:
            pickings = self.mapped('picking_id')
            states = {p.id: p.state for p in pickings}

        result = super(StockMove, self).action_done()

        if fire_event:
            session = ConnectorSession.from_env(self.env)
            for picking in pickings:
                if states[picking.id] != 'done' and picking.state == 'done':
                    if picking.picking_type_id.code != 'outgoing':
                        continue
                    # partial pickings are handled in
                    # StockPicking.do_transfer()
                    on_picking_out_done.fire(session, 'stock.picking',
                                             picking.id, 'complete')

        return result
Exemple #23
0
 def copy_quotation(self):
     self_copy = self.with_context(__copy_from_quotation=True)
     result = super(SaleOrder, self_copy).copy_quotation()
     # link binding of the canceled order to the new order, so the
     # operations done on the new order will be sync'ed with Magento
     new_id = result['res_id']
     binding_model = self.env['magento.sale.order']
     bindings = binding_model.search([('odoo_id', '=', self.id)])
     bindings.write({'odoo_id': new_id})
     session = ConnectorSession(self.env.cr,
                                self.env.uid,
                                context=self.env.context)
     for binding in bindings:
         # the sales' status on Magento is likely 'canceled'
         # so we will export the new status (pending, processing, ...)
         export_state_change.delay(session,
                                   'magento.sale.order',
                                   binding.id,
                                   description="Reopen sales order %s" %
                                   binding.magento_id)
     return result
Exemple #24
0
 def write(self, vals):
     # cancel sales order on Magento (do not export the other
     # state changes, Magento handles them itself)
     if vals.get('state') == 'cancel':
         session = ConnectorSession(self.env.cr,
                                    self.env.uid,
                                    context=self.env.context)
         for order in self:
             old_state = order.state
             if old_state == 'cancel':
                 continue  # skip if already canceled
             for binding in order.magento_bind_ids:
                 export_state_change.delay(
                     session,
                     'magento.sale.order',
                     binding.id,
                     # so if the state changes afterwards,
                     # it won't be exported
                     allowed_states=['cancel'],
                     description="Cancel sales order %s" %
                     binding.magento_id)
     return super(SaleOrder, self).write(vals)
Exemple #25
0
 def setUp(self):
     super(TestRelatedActionStorage, self).setUp()
     backend_model = self.env['magento.backend']
     self.session = ConnectorSession(self.env.cr,
                                     self.env.uid,
                                     context=self.env.context)
     warehouse = self.env.ref('stock.warehouse0')
     self.backend = backend_model.create({
         'name': 'Test Magento',
         'version': '1.7',
         'location': 'http://anyurl',
         'username': '******',
         'warehouse_id': warehouse.id,
         'password': '******'
     })
     # import the base informations
     with mock_api(magento_base_responses):
         import_batch(self.session, 'magento.website', self.backend.id)
         import_batch(self.session, 'magento.store', self.backend.id)
         import_batch(self.session, 'magento.storeview', self.backend.id)
     self.MagentoProduct = self.env['magento.product.product']
     self.QueueJob = self.env['queue.job']
Exemple #26
0
 def startup_import(self, *args, **kwargs):
     tasks = self.search(INITIAL_IMPORT_DOMAIN, order='sequence')
     if tasks:
         # run only one task at a once because execution time
         # is unpredictable: it depends of Google
         tasks[0].run()
     else:
         # when all tasks have been run, the cron can be inactivated
         cron = self.env.ref(
             'connector_google_spreadsheet.ir_cron_spreadsheet_import')
         session = ConnectorSession(
             self.env.cr,
             self.env.uid,
             self.env.context,
         )
         description = "Inactive spreadsheet startup cron"
         # a cron can't change its state itself
         # define a job to unactive the cron
         set_cron_inactive.delay(session,
                                 self._name, {'cron_id': cron.id},
                                 priority=1,
                                 description=description)
         return True
Exemple #27
0
 def setUp(self):
     super(TestImportAddressBook, self).setUp()
     self.backend_model = self.env['magento.backend']
     self.session = ConnectorSession(self.env.cr,
                                     self.env.uid,
                                     context=self.env.context)
     self.model = self.env['magento.res.partner']
     self.address_model = self.env['magento.address']
     warehouse_id = self.env.ref('stock.warehouse0').id
     self.backend_id = self.backend_model.create({
         'name': 'Test Magento Address book',
         'version': '1.7',
         'location': 'http://anyurl',
         'username': '******',
         'warehouse_id': warehouse_id,
         'password': '******'
     }).id
     with mock_api(magento_base_responses):
         import_batch(self.session, 'magento.website', self.backend_id)
         import_batch(self.session, 'magento.store', self.backend_id)
         import_batch(self.session, 'magento.storeview', self.backend_id)
         import_record(self.session, 'magento.res.partner.category',
                       self.backend_id, 1)
    def setUp(self):
        super(TestImportProductImage, self).setUp()
        backend_model = self.env['magento.backend']
        warehouse = self.env.ref('stock.warehouse0')
        self.backend_id = backend_model.create({
            'name': 'Test Magento',
            'version': '1.7',
            'location': 'http://anyurl',
            'username': '******',
            'warehouse_id': warehouse.id,
            'password': '******'
        }).id

        self.session = ConnectorSession(self.env.cr,
                                        self.env.uid,
                                        context=self.env.context)
        with mock_api(magento_base_responses):
            import_batch(self.session, 'magento.website', self.backend_id)
            import_batch(self.session, 'magento.store', self.backend_id)
            import_batch(self.session, 'magento.storeview', self.backend_id)
            import_record(self.session, 'magento.product.category',
                          self.backend_id, 1)

        self.product_model = self.env['magento.product.product']
Exemple #29
0
 def __get_session(self):
     return ConnectorSession(
         self.env.cr,
         self.env.uid,
         context=self.env.context,
     )
Exemple #30
0
 def setUp(self):
     super(test_connector_session, self).setUp()
     self.context = {'lang': 'fr_FR'}
     self.session = ConnectorSession(self.cr,
                                     self.uid,
                                     context=self.context)