コード例 #1
0
ファイル: test_session.py プロジェクト: sc4you/connector
 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)
コード例 #2
0
ファイル: stock.py プロジェクト: esousy/connector-ecommerce
 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
コード例 #3
0
ファイル: test_session.py プロジェクト: sc4you/connector
 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)
コード例 #4
0
ファイル: product.py プロジェクト: esousy/connector-ecommerce
    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)
コード例 #5
0
ファイル: product.py プロジェクト: esousy/connector-ecommerce
    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)
コード例 #6
0
ファイル: pos_order.py プロジェクト: escanerad/odoo-addons
 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
コード例 #7
0
ファイル: pos_order.py プロジェクト: escanerad/odoo-addons
 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
コード例 #8
0
ファイル: stock.py プロジェクト: esousy/connector-ecommerce
    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
コード例 #9
0
ファイル: stock.py プロジェクト: esousy/connector-ecommerce
    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
コード例 #10
0
ファイル: invoice.py プロジェクト: esousy/connector-ecommerce
 def invoice_validate(self):
     res = super(AccountInvoice, self).invoice_validate()
     session = ConnectorSession.from_env(self.env)
     for record_id in self.ids:
         on_invoice_validated.fire(session, self._name, record_id)
     return res
コード例 #11
0
ファイル: invoice.py プロジェクト: esousy/connector-ecommerce
 def confirm_paid(self):
     res = super(AccountInvoice, self).confirm_paid()
     session = ConnectorSession.from_env(self.env)
     for record_id in self.ids:
         on_invoice_paid.fire(session, self._name, record_id)
     return res
コード例 #12
0
 def _get_service(self, record, service_class):
     session = ConnectorSession.from_env(self.env)
     env = get_environment(session, record._name, self.backend_id.id)
     service = env.backend.get_class(service_class, session, record._name)
     return service(env, None, {})