mirror of
https://github.com/bringout/oca-ocb-vertical-industry.git
synced 2026-04-22 19:12:03 +02:00
19.0 vanilla
This commit is contained in:
parent
4607ccbd2e
commit
825ff6514e
487 changed files with 184979 additions and 195262 deletions
|
|
@ -5,3 +5,4 @@ from . import common
|
|||
from . import test_alert
|
||||
from . import test_supplier
|
||||
from . import test_ui
|
||||
from . import test_order
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ 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
|
||||
cron_ny = self.alert_ny.cron_id.sudo()
|
||||
self.assertTrue(cron_ny.active)
|
||||
self.assertEqual(cron_ny.name, "Lunch: alert chat notification (New York UTC-5)")
|
||||
self.assertEqual(
|
||||
|
|
@ -16,12 +16,12 @@ class TestAlarm(TestsCommon):
|
|||
["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
|
||||
tokyo_cron = self.alert_tokyo.cron_id.sudo()
|
||||
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
|
||||
cron_ny = self.alert_ny.cron_id.sudo()
|
||||
|
||||
self.alert_ny.active = False
|
||||
self.assertFalse(cron_ny.active)
|
||||
|
|
@ -43,15 +43,15 @@ class TestAlarm(TestsCommon):
|
|||
|
||||
@common.users('cle-lunch-manager')
|
||||
def test_cron_sync_nextcall(self):
|
||||
cron_ny = self.alert_ny.cron_id
|
||||
cron_ny = self.alert_ny.cron_id.sudo()
|
||||
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)
|
||||
cron_ny.lastcall = old_nextcall - timedelta(hours=5)
|
||||
cron_ny.nextcall += timedelta(days=1)
|
||||
|
||||
self.alert_ny.notification_time += 7
|
||||
self.assertEqual(cron_ny.nextcall, old_nextcall + timedelta(days=1, hours=2))
|
||||
|
|
|
|||
41
odoo-bringout-oca-ocb-lunch/lunch/tests/test_order.py
Normal file
41
odoo-bringout-oca-ocb-lunch/lunch/tests/test_order.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests import common
|
||||
from odoo.addons.lunch.tests.common import TestsCommon
|
||||
|
||||
|
||||
class TestOrder(TestsCommon):
|
||||
|
||||
@common.users('cle-lunch-manager')
|
||||
def test_create_only_updates_new_orders(self):
|
||||
"""
|
||||
Test that creating a new order only increments quantity for orders
|
||||
in 'new' state, not 'ordered'.
|
||||
"""
|
||||
order_ordered = self.env['lunch.order'].create({
|
||||
'product_id': self.product_pizza.id,
|
||||
'user_id': self.env.user.id,
|
||||
'lunch_location_id': self.location_office_1.id,
|
||||
'quantity': 1,
|
||||
})
|
||||
order_ordered.action_order()
|
||||
self.assertEqual(order_ordered.state, 'ordered')
|
||||
self.assertEqual(order_ordered.quantity, 1)
|
||||
|
||||
order_new = self.env['lunch.order'].create({
|
||||
'product_id': self.product_pizza.id,
|
||||
'user_id': self.env.user.id,
|
||||
'lunch_location_id': self.location_office_1.id,
|
||||
'quantity': 1,
|
||||
})
|
||||
self.assertEqual(order_new.state, 'new')
|
||||
self.assertEqual(order_new.quantity, 1)
|
||||
|
||||
self.env['lunch.order'].create({
|
||||
'product_id': self.product_pizza.id,
|
||||
'user_id': self.env.user.id,
|
||||
'lunch_location_id': self.location_office_1.id,
|
||||
})
|
||||
|
||||
self.assertEqual(order_new.quantity, 2, "New order should be incremented")
|
||||
self.assertEqual(order_ordered.quantity, 1, "Ordered order should NOT be incremented")
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
import pytz
|
||||
|
||||
from datetime import datetime, time, timedelta
|
||||
from freezegun import freeze_time
|
||||
from unittest.mock import patch
|
||||
|
||||
from odoo import fields
|
||||
|
|
@ -29,7 +30,7 @@ class TestSupplier(TestsCommon):
|
|||
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"""\
|
||||
self.assertEqual(self.supplier_kothai.cron_id.sudo().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()""")
|
||||
|
|
@ -55,7 +56,8 @@ env['lunch.supplier'].browse([{self.supplier_kothai.id}])._send_auto_email()""")
|
|||
@common.users('cle-lunch-manager')
|
||||
def test_search_available_today(self):
|
||||
'''
|
||||
This test checks that _search_available_today returns a valid domain
|
||||
This test checks that _search_available_today returns a valid domain.
|
||||
The field is of type boolean, so it accepts only the '=' operator.
|
||||
'''
|
||||
self.env.user.tz = 'Europe/Brussels'
|
||||
Supplier = self.env['lunch.supplier']
|
||||
|
|
@ -65,83 +67,103 @@ env['lunch.supplier'].browse([{self.supplier_kothai.id}])._send_auto_email()""")
|
|||
(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 self.subTest(value=value), freeze_time(value):
|
||||
self.assertEqual(
|
||||
list(Supplier._search_available_today('in', [True])),
|
||||
['&', '|', ('recurrency_end_date', '=', False),
|
||||
('recurrency_end_date', '>', value.astimezone(pytz.timezone(self.env.user.tz)).date()),
|
||||
(dayname, 'in', [True])],
|
||||
)
|
||||
|
||||
with patch.object(fields.Datetime, 'now', return_value=self.monday_10am) as _:
|
||||
assert self.supplier_pizza_inn in Supplier.search([('available_today', '=', True)])
|
||||
with patch.object(fields.Datetime, 'now', return_value=self.monday_10am):
|
||||
self.assertIn(self.supplier_pizza_inn, 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({
|
||||
line_pizza = 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'
|
||||
line_pizza.action_order()
|
||||
assert line_pizza.state == 'ordered'
|
||||
|
||||
self.supplier_pizza_inn._send_auto_email()
|
||||
|
||||
assert line.state == 'sent'
|
||||
assert line_pizza.state == 'sent'
|
||||
|
||||
line = self.env['lunch.order'].create({
|
||||
line_pizza_olive = 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({
|
||||
line_tuna = 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'
|
||||
(line_pizza_olive | line_tuna).action_order()
|
||||
assert line_pizza_olive.state == 'ordered'
|
||||
assert line_tuna.state == 'ordered'
|
||||
|
||||
self.supplier_pizza_inn._send_auto_email()
|
||||
|
||||
assert line.state == 'sent'
|
||||
assert line2.state == 'ordered'
|
||||
assert line_pizza_olive.state == 'sent'
|
||||
assert line_tuna.state == 'ordered'
|
||||
|
||||
line_1 = self.env['lunch.order'].create({
|
||||
line_pizza_2 = 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({
|
||||
line_pizza_olive_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({
|
||||
line_tuna_2 = 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()
|
||||
######################################################
|
||||
# id: # lines: # state: # quantity:
|
||||
#######################################################
|
||||
# 1 # line_pizza # sent # 1
|
||||
# 2 # line_pizza_olive # sent # 1
|
||||
# 3 # line_tuna # ordered # 1
|
||||
# 4 # line_pizza_2 # new # 2
|
||||
# 5 # line_pizza_olive_2 # new # 1
|
||||
# 6 # line_tuna_2 # new # 2
|
||||
|
||||
assert all(line.state == 'ordered' for line in [line_1, line_2, line_3])
|
||||
(line_pizza_2 | line_pizza_olive_2 | line_tuna_2).action_order()
|
||||
|
||||
######################################################
|
||||
# id: # lines: # state: # quantity:
|
||||
#######################################################
|
||||
# 1 # line_pizza # sent # 1
|
||||
# 2 # line_pizza_olive # sent # 1
|
||||
# 3 # line_tuna # ordered # 3 (1 + 2 from line_tuna_2 id=6)
|
||||
# 4 # line_pizza_2 # ordered # 2
|
||||
# 5 # line_pizza_olive_2 # ordered # 1
|
||||
|
||||
assert all(line.state == 'ordered' for line in [line_pizza_2, line_pizza_olive_2])
|
||||
|
||||
self.assertEqual(line_tuna_2.active, False)
|
||||
self.assertEqual(line_tuna.quantity, 3)
|
||||
|
||||
self.supplier_pizza_inn._send_auto_email()
|
||||
|
||||
|
|
@ -151,7 +173,7 @@ env['lunch.supplier'].browse([{self.supplier_kothai.id}])._send_auto_email()""")
|
|||
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("#")],
|
||||
[line for line in cron_ny.sudo().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
|
||||
|
||||
|
|
@ -186,3 +208,54 @@ env['lunch.supplier'].browse([{self.supplier_kothai.id}])._send_auto_email()""")
|
|||
|
||||
self.supplier_kothai.automatic_email_time -= 1
|
||||
self.assertEqual(cron_ny.nextcall, old_nextcall + timedelta(days=1, hours=1))
|
||||
|
||||
def test_remove_toppings(self):
|
||||
partner = self.env['res.partner'].create({
|
||||
'name': 'Partner',
|
||||
})
|
||||
|
||||
supplier = self.env['lunch.supplier'].create({
|
||||
'partner_id': partner.id,
|
||||
'send_by': 'phone',
|
||||
'topping_ids_2': [
|
||||
(0, 0, {
|
||||
'name': 'salt',
|
||||
'price': 7,
|
||||
'company_id': self.env.company.id
|
||||
}),
|
||||
],
|
||||
'topping_ids_3': [
|
||||
(0, 0, {
|
||||
'name': 'sugar',
|
||||
'price': 10,
|
||||
'company_id': self.env.company.id
|
||||
}),
|
||||
],
|
||||
})
|
||||
|
||||
# simulating the delete as it's done on frontend
|
||||
supplier.write({
|
||||
'topping_ids_2': [(2, supplier.topping_ids_2.id)],
|
||||
})
|
||||
self.assertFalse(supplier.topping_ids_2)
|
||||
|
||||
# simulating the delete as it's done on frontend
|
||||
supplier.write({
|
||||
'topping_ids_3': [(2, supplier.topping_ids_3.id)],
|
||||
})
|
||||
self.assertFalse(supplier.topping_ids_3)
|
||||
|
||||
def test_lunch_order_with_minimum_threshold(self):
|
||||
""" Test that lunch order is allowed within the overdraft threshold. """
|
||||
|
||||
self.env.company.lunch_minimum_threshold = 200.0
|
||||
order = self.env['lunch.order'].create({
|
||||
'product_id': self.product_pizza.id,
|
||||
'date': self.monday_1pm.date(),
|
||||
'supplier_id': self.supplier_pizza_inn.id,
|
||||
'quantity': 11,
|
||||
})
|
||||
self.assertTrue(order.display_add_button)
|
||||
|
||||
order.action_order()
|
||||
self.assertEqual(order.state, "ordered")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue