Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] 10.0 on_product_price_changed event with new API #48

Open
wants to merge 2 commits into
base: 10.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion connector_ecommerce/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _price_changed(self, vals):
remove_products = product_model.browse(from_product_ids)
products -= remove_products
for product in products:
self._event('on_product_price_changed').notify(product)
product._event('on_product_price_changed').notify(product)
# deprecated:
on_product_price_changed.fire(self.env,
product_model._name,
Expand Down
1 change: 1 addition & 0 deletions connector_ecommerce/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from . import test_onchange
from . import test_invoice_event
from . import test_picking_event
from . import test_product_event
42 changes: 42 additions & 0 deletions connector_ecommerce/tests/test_product_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
# © 2018 Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

import mock

import odoo.tests.common as common


class TestProductEvent(common.TransactionCase):
""" Test if the events on the products are fired correctly """

def setUp(self):
super(TestProductEvent, self).setUp()
self.product_product = self.env.ref('product.product_product_6')
self.product_template = self.env.ref(
'product.product_product_11_product_template')

def test_event_on_product_product_price_changed(self):
""" Test if the ``on_product_price_changed`` event is fired
when a product product price is changed"""
event = ('odoo.addons.connector_ecommerce.models.'
'product.on_product_price_changed')
with mock.patch(event) as event_mock:
self.product_product.update({'lst_price': 1000.0})
self.assertEquals(self.product_product.lst_price, 1000.0)
event_mock.fire.assert_called_with(mock.ANY,
'product.product',
self.product_product.id)

def test_event_on_product_template_price_changed(self):
""" Test if the ``on_product_price_changed`` event is fired
when a product template price is changed"""
event = ('odoo.addons.connector_ecommerce.models.'
'product.on_product_price_changed')
with mock.patch(event) as event_mock:
self.product_template.update({'list_price': 1000.0})
self.assertEquals(self.product_template.list_price, 1000.0)
self.assertEquals(event_mock.fire.call_count, 2)
event_mock.fire.assert_called_with(mock.ANY,
'product.product',
mock.ANY)