コード例 #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)
コード例 #2
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)
コード例 #3
0
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.addons.connector.event import on_record_create, on_record_write, \
    on_record_unlink
from openerp.addons.connector.queue.job import job
from .utils import _get_exporter
from ..backend import middleware
from openerp.addons.connector.unit.synchronizer import Exporter
from ..unit.backend_adapter import GenericAdapter
from .rma_events import export_rmaproduct
from openerp.addons.connector.event import Event

on_stock_move_change = Event()


@middleware
class ProductExporter(Exporter):

    _model_name = ['product.product', 'product.template']

    def update(self, binding_id, mode):
        if self.model == self.env["product.template"]:
            products = self.env["product.product"].\
                search([('product_tmpl_id', '=', binding_id)])
        else:
            products = [self.model.browse(binding_id)]
        for product in products:
            vals = {'name': product.name,
コード例 #4
0
class test_event(common.TransactionCase):
    """ Test Event """
    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)

    def test_subscribe(self):
        self.event.subscribe(self.consumer1)
        self.assertIn(self.consumer1, self.event._consumers[None])

    def test_subscribe_decorator(self):
        @self.event
        def consumer():
            pass

        self.assertIn(consumer, self.event._consumers[None])

    def test_subscribe_model(self):
        self.event.subscribe(self.consumer1, model_names=['res.users'])
        self.assertIn(self.consumer1, self.event._consumers['res.users'])

    def test_subscribe_decorator_model(self):
        @self.event(model_names=['res.users'])
        def consumer():
            pass

        self.assertIn(consumer, self.event._consumers['res.users'])

    def test_unsubscribe(self):
        self.event.subscribe(self.consumer1)
        self.event.unsubscribe(self.consumer1)
        self.assertNotIn(self.consumer1, self.event._consumers[None])

    def test_unsubscribe_model(self):
        self.event.subscribe(self.consumer1, model_names=['res.users'])
        self.event.unsubscribe(self.consumer1, model_names=['res.users'])
        self.assertNotIn(self.consumer1, self.event._consumers['res.users'])

    def test_unsubscribe_not_existing(self):
        """ Discard without error """
        self.event.unsubscribe(self.consumer1)

    def test_unsubscribe_not_existing_model(self):
        """ Discard without error """
        self.event.unsubscribe(self.consumer1, model_names=['res.users'])

    def test_replacing(self):
        self.event.subscribe(self.consumer1)
        self.event.subscribe(self.consumer2, replacing=self.consumer1)
        self.assertNotIn(self.consumer1, self.event._consumers[None])
        self.assertIn(self.consumer2, self.event._consumers[None])

    def test_replacing_decorator(self):
        @self.event
        def consumer1(session, model_name):
            pass

        @self.event(replacing=consumer1)
        def consumer2(session, model_name):
            pass

        self.assertNotIn(consumer1, self.event._consumers[None])
        self.assertIn(consumer2, self.event._consumers[None])

    def test_replacing_model(self):
        self.event.subscribe(self.consumer1, model_names=['res.users'])
        self.event.subscribe(self.consumer2,
                             replacing=self.consumer1,
                             model_names=['res.users'])
        self.assertNotIn(self.consumer1, self.event._consumers['res.users'])
        self.assertIn(self.consumer2, self.event._consumers['res.users'])

    def test_fire(self):
        """ Fire a consumer """
        class Recipient(object):
            def __init__(self):
                self.message = None

            def set_message(self, message):
                self.message = message

        @self.event
        def set_message(session, model_name, recipient, message):
            recipient.set_message(message)

        recipient = Recipient()
        # an event is fired on a model name
        session = mock.Mock()
        self.event.fire(session, 'res.users', recipient, 'success')
        self.assertEquals(recipient.message, 'success')

    def test_fire_several_consumers(self):
        """ Fire several consumers """
        class Recipient(object):
            def __init__(self):
                self.message = None

            def set_message(self, message):
                self.message = message

        recipient = Recipient()
        recipient2 = Recipient()

        @self.event
        def set_message(session, model_name, message):
            recipient.set_message(message)

        @self.event
        def set_message2(session, model_name, message):
            recipient2.set_message(message)

        # an event is fired on a model name
        session = mock.Mock()
        self.event.fire(session, 'res.users', 'success')
        self.assertEquals(recipient.message, 'success')
        self.assertEquals(recipient2.message, 'success')

    def test_has_consumer_for(self):
        @self.event(model_names=['product.product'])
        def consumer1(session, model_name):
            pass

        self.assertTrue(
            self.event.has_consumer_for(self.session, 'product.product'))
        self.assertFalse(
            self.event.has_consumer_for(self.session, 'res.partner'))

    def test_has_consumer_for_global(self):
        @self.event
        def consumer1(session, model_name):
            pass

        self.assertTrue(
            self.event.has_consumer_for(self.session, 'product.product'))
        self.assertTrue(
            self.event.has_consumer_for(self.session, 'res.partner'))

    def test_consumer_uninstalled_module(self):
        """A consumer in a uninstalled module should not be fired"""
        @self.event
        def consumer1(session, model_name):
            pass

        # devious way to test it: the __module__ of a mock is 'mock'
        # and we use __module__ to know the module of the event
        # so, here func is considered to be in a uninstalled module
        func = mock.Mock()
        func.side_effect = Exception('Should not be called')
        self.event(func)
        self.event.fire(self.session, 'res.users')
コード例 #5
0
class test_event(common.TransactionCase):
    """ Test Event """

    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)

    def test_subscribe(self):
        self.event.subscribe(self.consumer1)
        self.assertIn(self.consumer1, self.event._consumers[None])

    def test_subscribe_decorator(self):
        @self.event
        def consumer():
            pass
        self.assertIn(consumer, self.event._consumers[None])

    def test_subscribe_model(self):
        self.event.subscribe(self.consumer1, model_names=['res.users'])
        self.assertIn(self.consumer1, self.event._consumers['res.users'])

    def test_subscribe_decorator_model(self):
        @self.event(model_names=['res.users'])
        def consumer():
            pass
        self.assertIn(consumer, self.event._consumers['res.users'])

    def test_unsubscribe(self):
        self.event.subscribe(self.consumer1)
        self.event.unsubscribe(self.consumer1)
        self.assertNotIn(self.consumer1, self.event._consumers[None])

    def test_unsubscribe_model(self):
        self.event.subscribe(self.consumer1, model_names=['res.users'])
        self.event.unsubscribe(self.consumer1, model_names=['res.users'])
        self.assertNotIn(self.consumer1, self.event._consumers['res.users'])

    def test_unsubscribe_not_existing(self):
        """ Discard without error """
        self.event.unsubscribe(self.consumer1)

    def test_unsubscribe_not_existing_model(self):
        """ Discard without error """
        self.event.unsubscribe(self.consumer1, model_names=['res.users'])

    def test_replacing(self):
        self.event.subscribe(self.consumer1)
        self.event.subscribe(self.consumer2, replacing=self.consumer1)
        self.assertNotIn(self.consumer1, self.event._consumers[None])
        self.assertIn(self.consumer2, self.event._consumers[None])

    def test_replacing_decorator(self):
        @self.event
        def consumer1(session, model_name):
            pass
        @self.event(replacing=consumer1)
        def consumer2(session, model_name):
            pass
        self.assertNotIn(consumer1, self.event._consumers[None])
        self.assertIn(consumer2, self.event._consumers[None])

    def test_replacing_model(self):
        self.event.subscribe(self.consumer1, model_names=['res.users'])
        self.event.subscribe(self.consumer2, replacing=self.consumer1,
                             model_names=['res.users'])
        self.assertNotIn(self.consumer1, self.event._consumers['res.users'])
        self.assertIn(self.consumer2, self.event._consumers['res.users'])

    def test_fire(self):
        """ Fire a consumer """
        class Recipient(object):
            def __init__(self):
                self.message = None
            def set_message(self, message):
                self.message = message

        @self.event
        def set_message(session, model_name, recipient, message):
            recipient.set_message(message)
        recipient = Recipient()
        # an event is fired on a model name
        session = mock.Mock()
        self.event.fire(session, 'res.users', recipient, 'success')
        self.assertEquals(recipient.message, 'success')

    def test_fire_several_consumers(self):
        """ Fire several consumers """
        class Recipient(object):
            def __init__(self):
                self.message = None
            def set_message(self, message):
                self.message = message

        recipient = Recipient()
        recipient2 = Recipient()

        @self.event
        def set_message(session, model_name, message):
            recipient.set_message(message)

        @self.event
        def set_message2(session, model_name, message):
            recipient2.set_message(message)

        # an event is fired on a model name
        session = mock.Mock()
        self.event.fire(session, 'res.users', 'success')
        self.assertEquals(recipient.message, 'success')
        self.assertEquals(recipient2.message, 'success')

    def test_has_consumer_for(self):
        @self.event(model_names=['product.product'])
        def consumer1(session, model_name):
            pass
        self.assertTrue(self.event.has_consumer_for(self.session,
                                                    'product.product'))
        self.assertFalse(self.event.has_consumer_for(self.session,
                                                     'res.partner'))

    def test_has_consumer_for_global(self):
        @self.event
        def consumer1(session, model_name):
            pass
        self.assertTrue(self.event.has_consumer_for(self.session,
                                                    'product.product'))
        self.assertTrue(self.event.has_consumer_for(self.session,
                                                    'res.partner'))

    def test_consumer_uninstalled_module(self):
        """A consumer in a uninstalled module should not be fired"""
        @self.event
        def consumer1(session, model_name):
            pass
        # devious way to test it: the __module__ of a mock is 'mock'
        # and we use __module__ to know the module of the event
        # so, here func is considered to be in a uninstalled module
        func = mock.Mock()
        func.side_effect = Exception('Should not be called')
        self.event(func)
        self.event.fire(self.session, 'res.users')
コード例 #6
0
ファイル: event.py プロジェクト: muralikrishnareddy/wms
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.addons.connector.event import Event

on_picking_out_done = Event()
"""
``on_picking_out_done`` is fired when an outgoing picking has been
marked as done.

Listeners should take the following arguments:

 * session: `connector.session.ConnectorSession` object
 * model_name: name of the model
 * record_id: id of the record
"""

on_picking_out_available = Event()
"""
``on_picking_out_available`` is fired when an outgoing picking has been
marked as available.
コード例 #7
0
# -*- coding: utf-8 -*-
# © 2013 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from openerp.addons.connector.event import Event

on_picking_out_done = Event()
"""
``on_picking_out_done`` is fired when an outgoing picking has been
marked as done.

Listeners should take the following arguments:

 * session: `connector.session.ConnectorSession` object
 * model_name: name of the model
 * record_id: id of the record
 * type: 'partial' or 'complete' depending on the picking done
"""

on_tracking_number_added = Event()
"""
``on_tracking_number_added`` is fired when a picking has been marked as
 done and a tracking number has been added to it (write).

Listeners should take the following arguments:

 * session: `connector.session.ConnectorSession` object
 * model_name: name of the model
 * record_id: id of the record
"""