mirror of
https://github.com/bringout/oca-ocb-vertical-industry.git
synced 2026-04-23 02:52:09 +02:00
Initial commit: Vertical Industry packages
This commit is contained in:
commit
d5567a0017
766 changed files with 733028 additions and 0 deletions
7
odoo-bringout-oca-ocb-lunch/lunch/tests/__init__.py
Normal file
7
odoo-bringout-oca-ocb-lunch/lunch/tests/__init__.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import common
|
||||
from . import test_alert
|
||||
from . import test_supplier
|
||||
from . import test_ui
|
||||
117
odoo-bringout-oca-ocb-lunch/lunch/tests/common.py
Normal file
117
odoo-bringout-oca-ocb-lunch/lunch/tests/common.py
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from datetime import datetime
|
||||
from freezegun import freeze_time
|
||||
from odoo.tests import common, new_test_user
|
||||
|
||||
|
||||
class TestsCommon(common.TransactionCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.fakenow = datetime(2021, 1, 29, 12, 20, 0)
|
||||
cls.startClassPatcher(freeze_time(cls.fakenow))
|
||||
|
||||
def setUp(self):
|
||||
super(TestsCommon, self).setUp()
|
||||
|
||||
self.env['lunch.cashmove'].create({
|
||||
'amount': 100,
|
||||
})
|
||||
|
||||
self.manager = new_test_user(self.env, 'cle-lunch-manager', 'base.group_user,base.group_partner_manager,lunch.group_lunch_manager')
|
||||
with self.with_user('cle-lunch-manager'):
|
||||
|
||||
self.location_office_1 = self.env['lunch.location'].create({
|
||||
'name' : 'Farm 1',
|
||||
})
|
||||
|
||||
self.location_office_2 = self.env['lunch.location'].create({
|
||||
'name': 'Farm 2',
|
||||
})
|
||||
|
||||
self.partner_pizza_inn = self.env['res.partner'].create({
|
||||
'name': 'Pizza Inn',
|
||||
})
|
||||
|
||||
self.supplier_pizza_inn = self.env['lunch.supplier'].create({
|
||||
'partner_id': self.partner_pizza_inn.id,
|
||||
'send_by': 'mail',
|
||||
'automatic_email_time': 11,
|
||||
'available_location_ids': [
|
||||
(6, 0, [self.location_office_1.id, self.location_office_2.id])
|
||||
],
|
||||
})
|
||||
|
||||
self.partner_kothai = self.env['res.partner'].create({
|
||||
'name': 'Kothai',
|
||||
})
|
||||
|
||||
self.supplier_kothai = self.env['lunch.supplier'].create({
|
||||
'partner_id': self.partner_kothai.id,
|
||||
'send_by': 'mail',
|
||||
'automatic_email_time': 10,
|
||||
'tz': 'America/New_York',
|
||||
})
|
||||
|
||||
self.partner_coin_gourmand = self.env['res.partner'].create({
|
||||
'name': 'Coin Gourmand',
|
||||
})
|
||||
|
||||
self.supplier_coin_gourmand = self.env['lunch.supplier'].create({
|
||||
'partner_id': self.partner_coin_gourmand.id,
|
||||
'send_by': 'phone',
|
||||
'available_location_ids': [
|
||||
(6, 0, [self.location_office_1.id, self.location_office_2.id])
|
||||
],
|
||||
})
|
||||
|
||||
self.category_pizza = self.env['lunch.product.category'].create({
|
||||
'name': 'Pizza',
|
||||
})
|
||||
|
||||
self.category_sandwich = self.env['lunch.product.category'].create({
|
||||
'name': 'Sandwich',
|
||||
})
|
||||
|
||||
self.product_pizza = self.env['lunch.product'].create({
|
||||
'name': 'Pizza',
|
||||
'category_id': self.category_pizza.id,
|
||||
'price': 9,
|
||||
'supplier_id': self.supplier_pizza_inn.id,
|
||||
})
|
||||
|
||||
self.product_sandwich_tuna = self.env['lunch.product'].create({
|
||||
'name': 'Tuna Sandwich',
|
||||
'category_id': self.category_sandwich.id,
|
||||
'price': 3,
|
||||
'supplier_id': self.supplier_coin_gourmand.id,
|
||||
})
|
||||
|
||||
self.topping_olives = self.env['lunch.topping'].create({
|
||||
'name': 'Olives',
|
||||
'price': 0.3,
|
||||
'supplier_id': self.supplier_pizza_inn.id,
|
||||
})
|
||||
|
||||
self.env['lunch.cashmove'].create({
|
||||
'amount': 100,
|
||||
})
|
||||
|
||||
self.alert_ny = self.env['lunch.alert'].create({
|
||||
'name': 'New York UTC-5',
|
||||
'mode': 'chat',
|
||||
'notification_time': 10,
|
||||
'notification_moment': 'am',
|
||||
'tz': 'America/New_York',
|
||||
'message': "",
|
||||
}).with_context(tz='America/New_York')
|
||||
|
||||
self.alert_tokyo = self.env['lunch.alert'].create({
|
||||
'name': 'Tokyo UTC+9',
|
||||
'mode': 'chat',
|
||||
'notification_time': 8,
|
||||
'notification_moment': 'am',
|
||||
'tz': 'Asia/Tokyo',
|
||||
'message': "",
|
||||
}).with_context(tz='Asia/Tokyo')
|
||||
60
odoo-bringout-oca-ocb-lunch/lunch/tests/test_alert.py
Normal file
60
odoo-bringout-oca-ocb-lunch/lunch/tests/test_alert.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from datetime import datetime, timedelta
|
||||
from odoo import fields
|
||||
from odoo.tests import common
|
||||
from odoo.addons.lunch.tests.common import TestsCommon
|
||||
|
||||
|
||||
class TestAlarm(TestsCommon):
|
||||
@common.users('cle-lunch-manager')
|
||||
def test_cron_sync_create(self):
|
||||
cron_ny = self.alert_ny.cron_id
|
||||
self.assertTrue(cron_ny.active)
|
||||
self.assertEqual(cron_ny.name, "Lunch: alert chat notification (New York UTC-5)")
|
||||
self.assertEqual(
|
||||
[line for line in cron_ny.code.splitlines() if not line.lstrip().startswith("#")],
|
||||
["env['lunch.alert'].browse([%i])._notify_chat()" % self.alert_ny.id])
|
||||
self.assertEqual(cron_ny.nextcall, datetime(2021, 1, 29, 15, 0)) # New-york is UTC-5
|
||||
|
||||
tokyo_cron = self.alert_tokyo.cron_id
|
||||
self.assertEqual(tokyo_cron.nextcall, datetime(2021, 1, 29, 23, 0)) # Tokyo is UTC+9 but the cron is posponed
|
||||
|
||||
@common.users('cle-lunch-manager')
|
||||
def test_cron_sync_active(self):
|
||||
cron_ny = self.alert_ny.cron_id
|
||||
|
||||
self.alert_ny.active = False
|
||||
self.assertFalse(cron_ny.active)
|
||||
self.alert_ny.active = True
|
||||
self.assertTrue(cron_ny.active)
|
||||
|
||||
self.alert_ny.mode = 'alert'
|
||||
self.assertFalse(cron_ny.active)
|
||||
self.alert_ny.mode = 'chat'
|
||||
self.assertTrue(cron_ny.active)
|
||||
|
||||
ctx_today = fields.Date.context_today(self.alert_ny, self.fakenow)
|
||||
self.alert_ny.until = ctx_today - timedelta(days=1)
|
||||
self.assertFalse(cron_ny.active)
|
||||
self.alert_ny.until = ctx_today + timedelta(days=2)
|
||||
self.assertTrue(cron_ny.active)
|
||||
self.alert_ny.until = False
|
||||
self.assertTrue(cron_ny.active)
|
||||
|
||||
@common.users('cle-lunch-manager')
|
||||
def test_cron_sync_nextcall(self):
|
||||
cron_ny = self.alert_ny.cron_id
|
||||
old_nextcall = cron_ny.nextcall
|
||||
|
||||
self.alert_ny.notification_time -= 5
|
||||
self.assertEqual(cron_ny.nextcall, old_nextcall - timedelta(hours=5) + timedelta(days=1))
|
||||
|
||||
# Simulate cron execution
|
||||
cron_ny.sudo().lastcall = old_nextcall - timedelta(hours=5)
|
||||
cron_ny.sudo().nextcall += timedelta(days=1)
|
||||
|
||||
self.alert_ny.notification_time += 7
|
||||
self.assertEqual(cron_ny.nextcall, old_nextcall + timedelta(days=1, hours=2))
|
||||
|
||||
self.alert_ny.notification_time -= 1
|
||||
self.assertEqual(cron_ny.nextcall, old_nextcall + timedelta(days=1, hours=1))
|
||||
188
odoo-bringout-oca-ocb-lunch/lunch/tests/test_supplier.py
Normal file
188
odoo-bringout-oca-ocb-lunch/lunch/tests/test_supplier.py
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import pytz
|
||||
|
||||
from datetime import datetime, time, timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
from odoo import fields
|
||||
from odoo.tests import common
|
||||
|
||||
from odoo.addons.lunch.tests.common import TestsCommon
|
||||
|
||||
|
||||
class TestSupplier(TestsCommon):
|
||||
def setUp(self):
|
||||
super(TestSupplier, self).setUp()
|
||||
|
||||
self.monday_1am = datetime(2018, 10, 29, 1, 0, 0)
|
||||
self.monday_10am = datetime(2018, 10, 29, 10, 0, 0)
|
||||
self.monday_1pm = datetime(2018, 10, 29, 13, 0, 0)
|
||||
self.monday_8pm = datetime(2018, 10, 29, 20, 0, 0)
|
||||
|
||||
self.saturday_3am = datetime(2018, 11, 3, 3, 0, 0)
|
||||
self.saturday_10am = datetime(2018, 11, 3, 10, 0, 0)
|
||||
self.saturday_1pm = datetime(2018, 11, 3, 13, 0, 0)
|
||||
self.saturday_8pm = datetime(2018, 11, 3, 20, 0, 0)
|
||||
|
||||
@common.users('cle-lunch-manager')
|
||||
def test_send_email_cron(self):
|
||||
self.supplier_kothai.cron_id.ensure_one()
|
||||
self.assertEqual(self.supplier_kothai.cron_id.nextcall.time(), time(15, 0))
|
||||
self.assertEqual(self.supplier_kothai.cron_id.code, f"""\
|
||||
# This cron is dynamically controlled by Lunch Supplier.
|
||||
# Do NOT modify this cron, modify the related record instead.
|
||||
env['lunch.supplier'].browse([{self.supplier_kothai.id}])._send_auto_email()""")
|
||||
|
||||
cron_id = self.supplier_kothai.cron_id.id
|
||||
self.supplier_kothai.unlink()
|
||||
self.assertFalse(self.env['ir.cron'].sudo().search([('id', '=', cron_id)]))
|
||||
|
||||
@common.users('cle-lunch-manager')
|
||||
def test_compute_available_today(self):
|
||||
tests = [(self.monday_1am, True), (self.monday_10am, True),
|
||||
(self.monday_1pm, True), (self.monday_8pm, True),
|
||||
(self.saturday_3am, False), (self.saturday_10am, False),
|
||||
(self.saturday_1pm, False), (self.saturday_8pm, False)]
|
||||
|
||||
for value, result in tests:
|
||||
with patch.object(fields.Datetime, 'now', return_value=value) as _:
|
||||
assert self.supplier_pizza_inn.available_today == result,\
|
||||
'supplier pizza inn should %s considered available on %s' % ('be' if result else 'not be', value)
|
||||
|
||||
self.supplier_pizza_inn.invalidate_recordset(['available_today'])
|
||||
|
||||
@common.users('cle-lunch-manager')
|
||||
def test_search_available_today(self):
|
||||
'''
|
||||
This test checks that _search_available_today returns a valid domain
|
||||
'''
|
||||
self.env.user.tz = 'Europe/Brussels'
|
||||
Supplier = self.env['lunch.supplier']
|
||||
|
||||
tests = [(self.monday_1am, 1.0, 'mon'), (self.monday_10am, 10.0, 'mon'),
|
||||
(self.monday_1pm, 13.0, 'mon'), (self.monday_8pm, 20.0, 'mon'),
|
||||
(self.saturday_3am, 3.0, 'sat'), (self.saturday_10am, 10.0, 'sat'),
|
||||
(self.saturday_1pm, 13.0, 'sat'), (self.saturday_8pm, 20.0, 'sat')]
|
||||
|
||||
# It should return an empty domain if we compare to values other than datetime
|
||||
assert Supplier._search_available_today('>', 7) == []
|
||||
assert Supplier._search_available_today('>', True) == []
|
||||
|
||||
for value, rvalue, dayname in tests:
|
||||
with patch.object(fields.Datetime, 'now', return_value=value) as _:
|
||||
assert Supplier._search_available_today('=', True) == ['&', '|', ('recurrency_end_date', '=', False),
|
||||
('recurrency_end_date', '>', value.replace(tzinfo=pytz.UTC).astimezone(pytz.timezone(self.env.user.tz))),
|
||||
(dayname, '=', True)],\
|
||||
'Wrong domain generated for values (%s, %s)' % (value, rvalue)
|
||||
|
||||
with patch.object(fields.Datetime, 'now', return_value=self.monday_10am) as _:
|
||||
assert self.supplier_pizza_inn in Supplier.search([('available_today', '=', True)])
|
||||
|
||||
@common.users('cle-lunch-manager')
|
||||
def test_auto_email_send(self):
|
||||
with patch.object(fields.Datetime, 'now', return_value=self.monday_1pm) as _:
|
||||
with patch.object(fields.Date, 'today', return_value=self.monday_1pm.date()) as _:
|
||||
with patch.object(fields.Date, 'context_today', return_value=self.monday_1pm.date()) as _:
|
||||
line = self.env['lunch.order'].create({
|
||||
'product_id': self.product_pizza.id,
|
||||
'date': self.monday_1pm.date(),
|
||||
'supplier_id': self.supplier_pizza_inn.id,
|
||||
})
|
||||
|
||||
line.action_order()
|
||||
assert line.state == 'ordered'
|
||||
|
||||
self.supplier_pizza_inn._send_auto_email()
|
||||
|
||||
assert line.state == 'sent'
|
||||
|
||||
line = self.env['lunch.order'].create({
|
||||
'product_id': self.product_pizza.id,
|
||||
'topping_ids_1': [(6, 0, [self.topping_olives.id])],
|
||||
'date': self.monday_1pm.date(),
|
||||
'supplier_id': self.supplier_pizza_inn.id,
|
||||
})
|
||||
line2 = self.env['lunch.order'].create({
|
||||
'product_id': self.product_sandwich_tuna.id,
|
||||
'date': self.monday_1pm.date(),
|
||||
'supplier_id': self.supplier_coin_gourmand.id,
|
||||
})
|
||||
|
||||
(line | line2).action_order()
|
||||
assert line.state == 'ordered'
|
||||
assert line2.state == 'ordered'
|
||||
|
||||
self.supplier_pizza_inn._send_auto_email()
|
||||
|
||||
assert line.state == 'sent'
|
||||
assert line2.state == 'ordered'
|
||||
|
||||
line_1 = self.env['lunch.order'].create({
|
||||
'product_id': self.product_pizza.id,
|
||||
'quantity': 2,
|
||||
'date': self.monday_1pm.date(),
|
||||
'supplier_id': self.supplier_pizza_inn.id,
|
||||
})
|
||||
|
||||
line_2 = self.env['lunch.order'].create({
|
||||
'product_id': self.product_pizza.id,
|
||||
'topping_ids_1': [(6, 0, [self.topping_olives.id])],
|
||||
'date': self.monday_1pm.date(),
|
||||
'supplier_id': self.supplier_pizza_inn.id,
|
||||
})
|
||||
|
||||
line_3 = self.env['lunch.order'].create({
|
||||
'product_id': self.product_sandwich_tuna.id,
|
||||
'quantity': 2,
|
||||
'date': self.monday_1pm.date(),
|
||||
'supplier_id': self.supplier_coin_gourmand.id,
|
||||
})
|
||||
|
||||
(line_1 | line_2 | line_3).action_order()
|
||||
|
||||
assert all(line.state == 'ordered' for line in [line_1, line_2, line_3])
|
||||
|
||||
self.supplier_pizza_inn._send_auto_email()
|
||||
|
||||
@common.users('cle-lunch-manager')
|
||||
def test_cron_sync_create(self):
|
||||
cron_ny = self.supplier_kothai.cron_id # I am at New-York
|
||||
self.assertTrue(cron_ny.active)
|
||||
self.assertEqual(cron_ny.name, "Lunch: send automatic email to Kothai")
|
||||
self.assertEqual(
|
||||
[line for line in cron_ny.code.splitlines() if not line.lstrip().startswith("#")],
|
||||
["env['lunch.supplier'].browse([%i])._send_auto_email()" % self.supplier_kothai.id])
|
||||
self.assertEqual(cron_ny.nextcall, datetime(2021, 1, 29, 15, 0)) # New-york is UTC-5
|
||||
|
||||
@common.users('cle-lunch-manager')
|
||||
def test_cron_sync_active(self):
|
||||
cron_ny = self.supplier_kothai.cron_id
|
||||
|
||||
self.supplier_kothai.active = False
|
||||
self.assertFalse(cron_ny.active)
|
||||
self.supplier_kothai.active = True
|
||||
self.assertTrue(cron_ny.active)
|
||||
|
||||
self.supplier_kothai.send_by = 'phone'
|
||||
self.assertFalse(cron_ny.active)
|
||||
self.supplier_kothai.send_by = 'mail'
|
||||
self.assertTrue(cron_ny.active)
|
||||
|
||||
@common.users('cle-lunch-manager')
|
||||
def test_cron_sync_nextcall(self):
|
||||
cron_ny = self.supplier_kothai.cron_id
|
||||
old_nextcall = cron_ny.nextcall
|
||||
|
||||
self.supplier_kothai.automatic_email_time -= 5
|
||||
self.assertEqual(cron_ny.nextcall, old_nextcall - timedelta(hours=5) + timedelta(days=1))
|
||||
|
||||
# Simulate cron execution
|
||||
cron_ny.sudo().lastcall = old_nextcall - timedelta(hours=5)
|
||||
cron_ny.sudo().nextcall += timedelta(days=1)
|
||||
|
||||
self.supplier_kothai.automatic_email_time += 7
|
||||
self.assertEqual(cron_ny.nextcall, old_nextcall + timedelta(days=1, hours=2))
|
||||
|
||||
self.supplier_kothai.automatic_email_time -= 1
|
||||
self.assertEqual(cron_ny.nextcall, old_nextcall + timedelta(days=1, hours=1))
|
||||
51
odoo-bringout-oca-ocb-lunch/lunch/tests/test_ui.py
Normal file
51
odoo-bringout-oca-ocb-lunch/lunch/tests/test_ui.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests import HttpCase, tagged
|
||||
from freezegun import freeze_time
|
||||
|
||||
@tagged('-at_install', 'post_install')
|
||||
class TestUi(HttpCase):
|
||||
def test_01_ui(self):
|
||||
self.location_office = self.env['lunch.location'].create({
|
||||
'name' : 'Farm 1',
|
||||
})
|
||||
|
||||
self.partner_pizza_inn = self.env['res.partner'].create({
|
||||
'name': 'Pizza Inn',
|
||||
})
|
||||
|
||||
self.supplier_pizza_inn = self.env['lunch.supplier'].create({
|
||||
'partner_id': self.partner_pizza_inn.id,
|
||||
'send_by': 'phone',
|
||||
'mon': True,
|
||||
'tue': True,
|
||||
'wed': True,
|
||||
'thu': True,
|
||||
'fri': True,
|
||||
'sat': True,
|
||||
'sun': True,
|
||||
'available_location_ids': [
|
||||
(6, 0, [self.location_office.id])
|
||||
],
|
||||
})
|
||||
|
||||
self.category_pizza = self.env['lunch.product.category'].create({
|
||||
'name': 'Test category',
|
||||
})
|
||||
|
||||
self.product_pizza = self.env['lunch.product'].create({
|
||||
'name': "Aaron's Pizza",
|
||||
'category_id': self.category_pizza.id,
|
||||
'price': 9,
|
||||
'supplier_id': self.supplier_pizza_inn.id,
|
||||
})
|
||||
|
||||
user_admin = self.env.ref('base.user_admin')
|
||||
self.env['lunch.cashmove'].create({
|
||||
'user_id': user_admin.id,
|
||||
'amount': 10,
|
||||
})
|
||||
|
||||
with freeze_time("2022-04-19 10:00"):
|
||||
self.start_tour("/", 'order_lunch_tour', login='admin', timeout=180)
|
||||
Loading…
Add table
Add a link
Reference in a new issue