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

Revert "TA#60956 [CHG] Run Cron As Queue Job" #381

Open
wants to merge 2 commits into
base: 14.0
Choose a base branch
from
Open
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
6 changes: 0 additions & 6 deletions gitoo.yml
Original file line number Diff line number Diff line change
@@ -116,12 +116,6 @@
includes:
- date_range

- url: https://github.com/OCA/queue
branch: "14.0"
includes:
- queue_job
- queue_job_cron

- url: https://github.com/OCA/web
branch: "14.0"
includes:
23 changes: 13 additions & 10 deletions sale_dynamic_price/__manifest__.py
Original file line number Diff line number Diff line change
@@ -3,19 +3,22 @@

{
"name": "Sale Dynamic Price",
"version": "14.0.1.0.1",
"author": "Numigi",
"maintainer": "Numigi",
"website": "https://bit.ly/numigi-com",
"license": "LGPL-3",
'version': '14.0.1.0.0',
'author': 'Numigi',
'maintainer': 'Numigi',
'website': 'https://bit.ly/numigi-com',
'license': 'LGPL-3',
"category": "Sales",
"summary": "Compute sale prices based on product cost",
"depends": ["base_view_inheritance_extension", "product", "queue_job_cron"],
"depends": [
'base_view_inheritance_extension',
'product',
],
"data": [
"views/product_template.xml",
"views/product_product.xml",
"views/product_template_attribute_value.xml",
"data/ir_cron.xml",
'views/product_template.xml',
'views/product_product.xml',
'views/product_template_attribute_value.xml',
'data/ir_cron.xml',
],
"installable": True,
}
8 changes: 0 additions & 8 deletions sale_dynamic_price/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo noupdate="1">

<record model="queue.job.channel" id="channel_product_product_ir_cron">
<field name="name">product_product.ir_cron</field>
<field name="parent_id" ref="queue_job.channel_root" />
</record>

<record id="sale_price_update_cron" model="ir.cron">
<field name="name">Update dynamic sale prices on products</field>
<field name="model_id" ref="product.model_product_product"/>
@@ -14,9 +9,6 @@
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">weeks</field>
<field name="run_as_queue_job" eval="True"/>
<field name="no_parallel_queue_job_run" eval="True"/>
<field name="channel_id" ref="channel_product_product_ir_cron"/>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
</record>
11 changes: 1 addition & 10 deletions sale_dynamic_price/tests/test_dynamic_price.py
Original file line number Diff line number Diff line change
@@ -11,15 +11,6 @@ class TestDynamicPrice(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()

# Set queue job to no delay for testing
cls.env = cls.env(
context=dict(
cls.env.context,
test_queue_job_no_delay=True,
)
)

vals_list = {
"name": "Product A",
"type": "product",
@@ -82,7 +73,7 @@ def test_compute_margin_amount(self, data_):
)
@unpack
def test_update_sale_price_from_cost(
self, cost, margin, rounding, surcharge, expected_price
self, cost, margin, rounding, surcharge, expected_price
):
self.product.write(
{
8 changes: 0 additions & 8 deletions sale_rental/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo noupdate="1">

<record model="queue.job.channel" id="channel_sale_order_line_ir_cron">
<field name="name">sale_order_line.ir_cron</field>
<field name="parent_id" ref="queue_job.channel_root" />
</record>

<record id="rental_service_qty_delivered_update_cron" model="ir.cron">
<field name="name">Update the delivered quantity on sale order lines of type rental service</field>
<field name="model_id" ref="model_sale_order_line"/>
<field name="state">code</field>
<field name="code">model.update_rental_service_qty_delivered_cron()</field>
<field name="user_id" ref="base.user_root"/>
<field name="run_as_queue_job" eval="True"/>
<field name="no_parallel_queue_job_run" eval="True"/>
<field name="channel_id" ref="channel_sale_order_line_ir_cron"/>
<field name="interval_number">12</field>
<field name="interval_type">hours</field>
<field name="numbercall">-1</field>
9 changes: 0 additions & 9 deletions sale_rental/tests/common.py
Original file line number Diff line number Diff line change
@@ -8,15 +8,6 @@ class RentalCase(KitCase):
@classmethod
def setUpClass(cls):
super().setUpClass()

# Set queue job to no delay for testing
cls.env = cls.env(
context=dict(
cls.env.context,
test_queue_job_no_delay=True,
)
)

cls.stock_user = cls.env.ref("base.user_demo")
cls.stock_user.groups_id = cls.env.ref("stock.group_stock_user")

34 changes: 17 additions & 17 deletions sale_warranty/__manifest__.py
Original file line number Diff line number Diff line change
@@ -3,27 +3,27 @@

{
"name": "Sales Warranty",
"version": "14.0.1.1.2",
"author": "Numigi",
"maintainer": "Numigi",
"website": "https://bit.ly/numigi-com",
"license": "LGPL-3",
'version': '14.0.1.1.1',
'author': 'Numigi',
'maintainer': 'Numigi',
'website': 'https://bit.ly/numigi-com',
'license': 'LGPL-3',
"category": "Sales",
"summary": "Manage warranties on sales",
"depends": ["sale_stock", "queue_job_cron"],
"depends": ['sale_stock'],
"data": [
"security/groups.xml",
"security/rules.xml",
"security/ir.model.access.csv",
"views/menu.xml",
"views/config_settings.xml",
"views/warranty_type.xml",
"views/warranty.xml",
"views/product.xml",
"views/sale_order.xml",
'security/groups.xml',
'security/rules.xml',
'security/ir.model.access.csv',
'views/menu.xml',
'views/config_settings.xml',
'views/warranty_type.xml',
'views/warranty.xml',
'views/product.xml',
'views/sale_order.xml',
"views/stock_production_lot.xml",
"data/ir_cron.xml",
"data/ir_sequence.xml",
'data/ir_cron.xml',
'data/ir_sequence.xml',
],
"installable": True,
"application": True,
8 changes: 0 additions & 8 deletions sale_warranty/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo noupdate="1">

<record model="queue.job.channel" id="channel_sale_warranty_ir_cron">
<field name="name">sale_warranty.ir_cron</field>
<field name="parent_id" ref="queue_job.channel_root" />
</record>

<record id="expired_warranties_cron" model="ir.cron">
<field name="name">Sale Warranties: update status of expired warranties</field>
<field name="model_id" ref="model_sale_warranty"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="run_as_queue_job" eval="True"/>
<field name="no_parallel_queue_job_run" eval="True"/>
<field name="channel_id" ref="channel_sale_warranty_ir_cron"/>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="state">code</field>
71 changes: 27 additions & 44 deletions sale_warranty/tests/test_expired_warranties_cron.py
Original file line number Diff line number Diff line change
@@ -10,67 +10,50 @@ class ExpiredWarrantiesCronCase(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()

# Set queue job to no delay for testing
cls.env = cls.env(
context=dict(
cls.env.context,
test_queue_job_no_delay=True,
)
)

cls.customer = cls.env["res.partner"].create(
{
"name": "My Customer",
}
)

cls.warranty_6_months = cls.env["sale.warranty.type"].create(
{
"name": "6 Months Parts",
"duration_in_months": 6,
"description": "Warranted 6 months on parts",
}
)

cls.product_a = cls.env["product.product"].create(
{
"name": "My Product",
"tracking": "serial",
"type": "product",
"warranty_type_ids": [(4, cls.warranty_6_months.id)],
}
)
cls.customer = cls.env['res.partner'].create({
'name': 'My Customer',
})

cls.warranty_6_months = cls.env['sale.warranty.type'].create({
'name': '6 Months Parts',
'duration_in_months': 6,
'description': 'Warranted 6 months on parts'
})

cls.product_a = cls.env['product.product'].create({
'name': 'My Product',
'tracking': 'serial',
'type': 'product',
'warranty_type_ids': [(4, cls.warranty_6_months.id)]
})

cls.today = datetime.now().date()

cls.warranty = cls.env["sale.warranty"].create(
{
"partner_id": cls.customer.id,
"product_id": cls.product_a.id,
"type_id": cls.warranty_6_months.id,
"state": "active",
"activation_date": cls.today - timedelta(90),
}
)
cls.warranty = cls.env['sale.warranty'].create({
'partner_id': cls.customer.id,
'product_id': cls.product_a.id,
'type_id': cls.warranty_6_months.id,
'state': 'active',
'activation_date': cls.today - timedelta(90),
})

def run_cron(self):
self.env.ref("sale_warranty.expired_warranties_cron").method_direct_trigger()
self.env.ref('sale_warranty.expired_warranties_cron').method_direct_trigger()


class TestExpiredWarrantiesCron(ExpiredWarrantiesCronCase):

def test_if_expiration_date_after_today_then_warranty_active(self):
self.warranty.expiry_date = self.today + timedelta(1)
self.run_cron()
assert self.warranty.state == "active"
assert self.warranty.state == 'active'

def test_if_expiration_date_is_today_then_warranty_active(self):
self.warranty.expiry_date = self.today
self.run_cron()
assert self.warranty.state == "active"
assert self.warranty.state == 'active'

def test_if_expiration_date_before_today_then_warranty_expired(self):
self.warranty.expiry_date = self.today - timedelta(1)
self.run_cron()
assert self.warranty.state == "expired"
assert self.warranty.state == 'expired'
20 changes: 10 additions & 10 deletions sale_warranty_lead_on_expiry/__manifest__.py
Original file line number Diff line number Diff line change
@@ -3,19 +3,19 @@

{
"name": "Sales Warranty Lead On Expiry",
"version": "14.0.1.0.1",
"author": "Numigi",
"maintainer": "Numigi",
"website": "https://bit.ly/numigi-com",
"license": "LGPL-3",
'version': '14.0.1.0.0',
'author': 'Numigi',
'maintainer': 'Numigi',
'website': 'https://bit.ly/numigi-com',
'license': 'LGPL-3',
"category": "Sales",
"summary": "Generate a lead when a sale warranty expires",
"depends": ["sale_warranty", "crm", "queue_job_cron"],
"depends": ['sale_warranty', 'crm'],
"data": [
"data/ir_cron.xml",
"views/config_settings.xml",
"views/warranty_to_lead_link_message.xml",
"views/warranty_type.xml",
'data/ir_cron.xml',
'views/config_settings.xml',
'views/warranty_to_lead_link_message.xml',
'views/warranty_type.xml',
],
"installable": True,
}
3 changes: 0 additions & 3 deletions sale_warranty_lead_on_expiry/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -6,9 +6,6 @@
<field name="model_id" ref="model_sale_warranty"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="run_as_queue_job" eval="True"/>
<field name="no_parallel_queue_job_run" eval="True"/>
<field name="channel_id" ref="sale_warranty.channel_sale_warranty_ir_cron"/>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="state">code</field>
89 changes: 36 additions & 53 deletions sale_warranty_lead_on_expiry/tests/test_lead_on_expiry_cron.py
Original file line number Diff line number Diff line change
@@ -12,65 +12,50 @@ class LeadOnExpiryCronCase(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env.user.company_id.warranty_delay_between_leads = LEAD_DELAY

# Set queue job to no delay for testing
cls.env = cls.env(
context=dict(
cls.env.context,
test_queue_job_no_delay=True,
)
)
cls.customer = cls.env['res.partner'].create({
'name': 'My Customer'
})

cls.env.user.company_id.warranty_delay_between_leads = LEAD_DELAY
cls.team = cls.env['crm.team'].create({'name': 'Team A'})

cls.warranty_6_months = cls.env['sale.warranty.type'].create({
'name': '6 Months Parts',
'duration_in_months': 6,
'description': 'Warranted 6 months on parts',
'automated_action': True,
'sales_team_id': cls.team.id,
'automated_action_delay': 0,
})

cls.customer = cls.env["res.partner"].create({"name": "My Customer"})

cls.team = cls.env["crm.team"].create({"name": "Team A"})

cls.warranty_6_months = cls.env["sale.warranty.type"].create(
{
"name": "6 Months Parts",
"duration_in_months": 6,
"description": "Warranted 6 months on parts",
"automated_action": True,
"sales_team_id": cls.team.id,
"automated_action_delay": 0,
}
)

cls.product_a = cls.env["product.product"].create(
{
"name": "My Product",
"tracking": "serial",
"type": "product",
}
)
cls.product_a = cls.env['product.product'].create({
'name': 'My Product',
'tracking': 'serial',
'type': 'product',
})

cls.warranty = cls._create_warranty()

@classmethod
def _find_lead(cls):
return cls.env["crm.lead"].search([("partner_id", "=", cls.customer.id)])
return cls.env['crm.lead'].search([('partner_id', '=', cls.customer.id)])

@classmethod
def _run_cron(cls):
cls.env.ref(
"sale_warranty_lead_on_expiry.lead_on_expiry_cron"
).method_direct_trigger()
cls.env.ref('sale_warranty_lead_on_expiry.lead_on_expiry_cron').method_direct_trigger()

@classmethod
def _create_warranty(cls):
today = datetime.now().date()
return cls.env["sale.warranty"].create(
{
"partner_id": cls.customer.id,
"product_id": cls.product_a.id,
"type_id": cls.warranty_6_months.id,
"state": "active",
"activation_date": today - timedelta(90),
"expiry_date": today - timedelta(30),
}
)
return cls.env['sale.warranty'].create({
'partner_id': cls.customer.id,
'product_id': cls.product_a.id,
'type_id': cls.warranty_6_months.id,
'state': 'active',
'activation_date': today - timedelta(90),
'expiry_date': today - timedelta(30),
})


class TestLeadOnExpiryCron(LeadOnExpiryCronCase):
@@ -114,7 +99,7 @@ def test_if_days_to_trigger_reached__new_lead_created(self):
def test_generated_lead_type_is_opportunity(self):
self._run_cron()
lead = self._find_lead()
assert lead.type == "opportunity"
assert lead.type == 'opportunity'


class TestWarrantiesWithExtension(LeadOnExpiryCronCase):
@@ -128,14 +113,12 @@ class TestWarrantiesWithExtension(LeadOnExpiryCronCase):
def setUpClass(cls):
super().setUpClass()
today = datetime.now().date()
cls.warranty.write(
{
"activation_date": today - timedelta(150),
"expiry_date": today - timedelta(120),
"extension_start_date": today + timedelta(60),
"extension_expiry_date": today + timedelta(90),
}
)
cls.warranty.write({
'activation_date': today - timedelta(150),
'expiry_date': today - timedelta(120),
'extension_start_date': today + timedelta(60),
'extension_expiry_date': today + timedelta(90),
})

def test_if_days_to_trigger_not_reached__no_lead_created(self):
self.warranty_6_months.automated_action_delay = 89