The Lunch module can automatically send an email to a supplier with the daily orders at a configured time. It can also remind the users via chat so they don't forget to order their sanddwish. Before, two high frequency cron jobs were responsible to check every 20 and 5 minutes if we reached the moment when to send the email to the suppliers or the notification to the users. Together the two crons were executed 360 times a day. The new model uses a dedicated daily cron per supplier record and per alert record, the dedicated cron is created on the fly and its moment of execution automatically updated to reflect the supplier/alert record. See also #41858 for prior work. closes odoo/odoo#63749 Task: 2416741 Related: odoo/upgrade#2044 Signed-off-by: Julien Castiaux <Julien00859@users.noreply.github.com>
113 lines
3.4 KiB
Python
113 lines
3.4 KiB
Python
# 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
|
|
|
|
|
|
fakenow = datetime(2021, 1, 29, 12, 20, 0)
|
|
|
|
@freeze_time(fakenow)
|
|
class TestsCommon(common.TransactionCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super().setUpClass()
|
|
cls.fakenow = fakenow
|
|
|
|
def setUp(self):
|
|
super(TestsCommon, self).setUp()
|
|
|
|
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,
|
|
'category_id': self.category_pizza.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')
|