details: https://code.tryton.org/tryton/commit/bea535142d87
branch: default
user: Cédric Krier <[email protected]>
date: Mon Jul 13 15:33:35 2026 +0200
description:
Show companies field of cron only for methods that need them
Closes #14952
diffstat:
modules/account/ir.py
| 1 +
modules/account_fr_chorus/ir.py
| 4 +
modules/account_payment_braintree/ir.py
| 5 +
modules/account_payment_braintree/tests/scenario_account_payment_braintree.rst
| 4 -
modules/account_payment_clearing/ir.py
| 2 +
modules/account_payment_stripe/ir.py
| 4 +
modules/account_payment_stripe/tests/scenario_account_payment_stripe.rst
| 5 +-
modules/account_payment_stripe/tests/scenario_account_payment_stripe_dispute.rst
| 3 +-
modules/account_payment_stripe/tests/scenario_account_payment_stripe_identical.rst
| 9 +--
modules/account_payment_stripe/tests/scenario_account_payment_stripe_intent.rst
| 11 +--
modules/account_payment_stripe/tests/scenario_account_payment_stripe_refund_failure.rst
| 3 +-
modules/account_receivable_rule/ir.py
| 2 +
modules/company/ir.py
| 32 ++++++++-
modules/product_price_list_cache/ir.py
| 2 +
modules/sale/ir.py
| 2 +
modules/sale_payment/ir.py
| 1 +
modules/sale_subscription/ir.py
| 4 +
modules/stock/ir.py
| 4 +
modules/stock_quantity_issue/ir.py
| 2 +
modules/stock_supply/ir.py
| 1 +
20 files changed, 67 insertions(+), 34 deletions(-)
diffs (386 lines):
diff -r ed6d59c14b77 -r bea535142d87 modules/account/ir.py
--- a/modules/account/ir.py Wed Jul 08 14:59:40 2026 +0200
+++ b/modules/account/ir.py Mon Jul 13 15:33:35 2026 +0200
@@ -14,3 +14,4 @@
('account.move.line|reconcile_automatic',
"Reconcile Move Lines Automatically"),
])
+ cls.methods_company_needed.add('account.move.line|reconcile_automatic')
diff -r ed6d59c14b77 -r bea535142d87 modules/account_fr_chorus/ir.py
--- a/modules/account_fr_chorus/ir.py Wed Jul 08 14:59:40 2026 +0200
+++ b/modules/account_fr_chorus/ir.py Mon Jul 13 15:33:35 2026 +0200
@@ -14,3 +14,7 @@
('account.invoice.chorus|update',
"Update invoices from Chorus"),
])
+ cls.methods_company_needed.update({
+ 'account.invoice.chorus|send',
+ 'account.invoice.chorus|update',
+ })
diff -r ed6d59c14b77 -r bea535142d87 modules/account_payment_braintree/ir.py
--- a/modules/account_payment_braintree/ir.py Wed Jul 08 14:59:40 2026 +0200
+++ b/modules/account_payment_braintree/ir.py Mon Jul 13 15:33:35 2026 +0200
@@ -23,3 +23,8 @@
('account.payment.braintree.refund|braintree_pull',
"Pull Braintree Refund"),
])
+ cls.methods_company_needed.update({
+ 'account.payment|braintree_transact',
+ 'account.payment|braintree_pull',
+ 'account.payment.braintree.refund|braintree_pull',
+ })
diff -r ed6d59c14b77 -r bea535142d87
modules/account_payment_braintree/tests/scenario_account_payment_braintree.rst
---
a/modules/account_payment_braintree/tests/scenario_account_payment_braintree.rst
Wed Jul 08 14:59:40 2026 +0200
+++
b/modules/account_payment_braintree/tests/scenario_account_payment_braintree.rst
Mon Jul 13 15:33:35 2026 +0200
@@ -139,7 +139,6 @@
>>> cron_customer_create, = Cron.find([
... ('method', '=',
'account.payment.braintree.customer|braintree_create'),
... ])
- >>> cron_customer_create.companies.append(Company(company.id))
>>> cron_customer_create.click('run_once')
>>> braintree_customer.reload()
@@ -190,7 +189,6 @@
>>> cron_customer_delete, = Cron.find([
... ('method', '=',
'account.payment.braintree.customer|braintree_delete'),
... ])
- >>> cron_customer_delete.companies.append(Company(company.id))
>>> cron_customer_delete.click('run_once')
>>> braintree_customer.reload()
@@ -246,7 +244,6 @@
>>> cron_refund, = Cron.find([
... ('method', '=',
'account.payment.braintree.refund|braintree_refund'),
... ])
- >>> cron_refund.companies.append(Company(company.id))
>>> cron_refund.click('run_once')
>>> refund.reload()
@@ -259,7 +256,6 @@
>>> cron_refund_pull, = Cron.find([
... ('method', '=', 'account.payment.braintree.refund|braintree_pull'),
... ])
- >>> cron_refund_pull.companies.append(Company(company.id))
>>> cron_refund_pull.click('run_once')
>>> refund.reload()
>>> refund.state
diff -r ed6d59c14b77 -r bea535142d87 modules/account_payment_clearing/ir.py
--- a/modules/account_payment_clearing/ir.py Wed Jul 08 14:59:40 2026 +0200
+++ b/modules/account_payment_clearing/ir.py Mon Jul 13 15:33:35 2026 +0200
@@ -12,3 +12,5 @@
cls.method.selection.append(
('account.payment.journal|cron_post_clearing_moves',
"Post Clearing Moves"))
+ cls.methods_company_needed.add(
+ 'account.payment.journal|cron_post_clearing_moves')
diff -r ed6d59c14b77 -r bea535142d87 modules/account_payment_stripe/ir.py
--- a/modules/account_payment_stripe/ir.py Wed Jul 08 14:59:40 2026 +0200
+++ b/modules/account_payment_stripe/ir.py Mon Jul 13 15:33:35 2026 +0200
@@ -23,3 +23,7 @@
('account.payment.stripe.account|fetch_events',
"Fetch Stripe Events"),
])
+ cls.methods_company_needed.update({
+ 'account.payment|stripe_charge',
+ 'account.payment|stripe_capture_',
+ })
diff -r ed6d59c14b77 -r bea535142d87
modules/account_payment_stripe/tests/scenario_account_payment_stripe.rst
--- a/modules/account_payment_stripe/tests/scenario_account_payment_stripe.rst
Wed Jul 08 14:59:40 2026 +0200
+++ b/modules/account_payment_stripe/tests/scenario_account_payment_stripe.rst
Mon Jul 13 15:33:35 2026 +0200
@@ -13,7 +13,7 @@
>>> from proteus import Model
>>> from trytond.modules.account.tests.tools import create_chart,
create_fiscalyear
- >>> from trytond.modules.company.tests.tools import create_company,
get_company
+ >>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules
>>> today = dt.date.today()
@@ -56,7 +56,6 @@
>>> cron_fetch_events, = Cron.find([
... ('method', '=', 'account.payment.stripe.account|fetch_events'),
... ])
- >>> cron_fetch_events.companies.append(get_company())
Create payment journal::
@@ -183,7 +182,6 @@
>>> cron_customer_create, = Cron.find([
... ('method', '=', 'account.payment.stripe.customer|stripe_create'),
... ])
- >>> cron_customer_create.companies.append(get_company())
>>> cron_customer_create.click('run_once')
>>> stripe_customer.reload()
@@ -253,7 +251,6 @@
>>> cron_customer_delete, = Cron.find([
... ('method', '=', 'account.payment.stripe.customer|stripe_delete'),
... ])
- >>> cron_customer_delete.companies.append(get_company())
>>> cron_customer_delete.click('run_once')
>>> stripe_customer.reload()
diff -r ed6d59c14b77 -r bea535142d87
modules/account_payment_stripe/tests/scenario_account_payment_stripe_dispute.rst
---
a/modules/account_payment_stripe/tests/scenario_account_payment_stripe_dispute.rst
Wed Jul 08 14:59:40 2026 +0200
+++
b/modules/account_payment_stripe/tests/scenario_account_payment_stripe_dispute.rst
Mon Jul 13 15:33:35 2026 +0200
@@ -13,7 +13,7 @@
>>> from proteus import Model
>>> from trytond.modules.account.tests.tools import create_chart,
create_fiscalyear
- >>> from trytond.modules.company.tests.tools import create_company,
get_company
+ >>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules
>>> today = dt.date.today()
@@ -45,7 +45,6 @@
>>> cron_fetch_events, = Cron.find([
... ('method', '=', 'account.payment.stripe.account|fetch_events'),
... ])
- >>> cron_fetch_events.companies.append(get_company())
Create payment journal::
diff -r ed6d59c14b77 -r bea535142d87
modules/account_payment_stripe/tests/scenario_account_payment_stripe_identical.rst
---
a/modules/account_payment_stripe/tests/scenario_account_payment_stripe_identical.rst
Wed Jul 08 14:59:40 2026 +0200
+++
b/modules/account_payment_stripe/tests/scenario_account_payment_stripe_identical.rst
Mon Jul 13 15:33:35 2026 +0200
@@ -10,7 +10,7 @@
>>> import stripe
>>> from proteus import Model
- >>> from trytond.modules.company.tests.tools import create_company,
get_company
+ >>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules, assertEqual
>>> today = dt.date.today()
@@ -19,15 +19,10 @@
>>> config = activate_modules('account_payment_stripe', create_company)
- >>> Company = Model.get('company.company')
>>> Cron = Model.get('ir.cron')
>>> StripeAccount = Model.get('account.payment.stripe.account')
>>> StripeCustomer = Model.get('account.payment.stripe.customer')
-Get company::
-
- >>> company = get_company()
-
Create Stripe account::
>>> stripe_account = StripeAccount(name="Stripe")
@@ -41,8 +36,6 @@
>>> cron_customer_create, = Cron.find([
... ('method', '=', 'account.payment.stripe.customer|stripe_create'),
... ])
- >>> cron_customer_create.companies.append(Company(company.id))
- >>> cron_customer_create.save()
Create parties::
diff -r ed6d59c14b77 -r bea535142d87
modules/account_payment_stripe/tests/scenario_account_payment_stripe_intent.rst
---
a/modules/account_payment_stripe/tests/scenario_account_payment_stripe_intent.rst
Wed Jul 08 14:59:40 2026 +0200
+++
b/modules/account_payment_stripe/tests/scenario_account_payment_stripe_intent.rst
Mon Jul 13 15:33:35 2026 +0200
@@ -13,7 +13,7 @@
>>> from proteus import Model
>>> from trytond.modules.account.tests.tools import create_chart,
create_fiscalyear
- >>> from trytond.modules.company.tests.tools import create_company,
get_company
+ >>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules
>>> today = dt.date.today()
@@ -25,10 +25,7 @@
>>> config = activate_modules(
... 'account_payment_stripe', create_company, create_chart)
-Get company::
-
- >>> Company = Model.get('company.company')
- >>> company = get_company()
+ >>> Cron = Model.get('ir.cron')
Create fiscal year::
@@ -46,11 +43,9 @@
Setup fetch events cron::
- >>> Cron = Model.get('ir.cron')
>>> cron_fetch_events, = Cron.find([
... ('method', '=', 'account.payment.stripe.account|fetch_events'),
... ])
- >>> cron_fetch_events.companies.append(Company(company.id))
Create payment journal::
@@ -67,7 +62,6 @@
Register card::
- >>> Cron = Model.get('ir.cron')
>>> Customer = Model.get('account.payment.stripe.customer')
>>> customer = Customer()
>>> customer.party = party
@@ -82,7 +76,6 @@
>>> cron_update_intent, = Cron.find([
... ('method', '=',
'account.payment.stripe.customer|stripe_intent_update'),
... ])
- >>> cron_update_intent.companies.append(Company(company.id))
>>> cron_update_intent.click('run_once')
>>> customer.reload()
>>> bool(customer.stripe_customer_id)
diff -r ed6d59c14b77 -r bea535142d87
modules/account_payment_stripe/tests/scenario_account_payment_stripe_refund_failure.rst
---
a/modules/account_payment_stripe/tests/scenario_account_payment_stripe_refund_failure.rst
Wed Jul 08 14:59:40 2026 +0200
+++
b/modules/account_payment_stripe/tests/scenario_account_payment_stripe_refund_failure.rst
Mon Jul 13 15:33:35 2026 +0200
@@ -13,7 +13,7 @@
>>> from proteus import Model
>>> from trytond.modules.account.tests.tools import create_chart,
create_fiscalyear
- >>> from trytond.modules.company.tests.tools import create_company,
get_company
+ >>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules
>>> today = dt.date.today()
@@ -47,7 +47,6 @@
>>> cron_fetch_events, = Cron.find([
... ('method', '=', 'account.payment.stripe.account|fetch_events'),
... ])
- >>> cron_fetch_events.companies.append(get_company())
Create payment journal::
diff -r ed6d59c14b77 -r bea535142d87 modules/account_receivable_rule/ir.py
--- a/modules/account_receivable_rule/ir.py Wed Jul 08 14:59:40 2026 +0200
+++ b/modules/account_receivable_rule/ir.py Mon Jul 13 15:33:35 2026 +0200
@@ -13,3 +13,5 @@
('account.account.receivable.rule|apply',
"Apply Account Receivable Rules"),
])
+ cls.methods_company_needed.add(
+ 'account.account.receivable.rule|apply')
diff -r ed6d59c14b77 -r bea535142d87 modules/company/ir.py
--- a/modules/company/ir.py Wed Jul 08 14:59:40 2026 +0200
+++ b/modules/company/ir.py Mon Jul 13 15:33:35 2026 +0200
@@ -4,7 +4,7 @@
from trytond import backend
from trytond.model import ModelSQL, ModelView, dualmethod, fields
from trytond.pool import Pool, PoolMeta
-from trytond.pyson import Eval
+from trytond.pyson import Eval, If
from trytond.tools import timezone as tz
from trytond.transaction import Transaction
@@ -75,8 +75,22 @@
'ir.cron-company.company', 'cron', 'company', "Companies",
states={
'readonly': Eval('running', False),
+ 'invisible': ~Eval('company_needed', False),
},
+ domain=[
+ If(~Eval('company_needed'),
+ ('id', '=', None),
+ ()),
+ ],
help='Companies registered for this cron.')
+ company_needed = fields.Function(fields.Boolean(
+ "Company Needed"),
+ 'on_change_with_company_needed')
+
+ @classmethod
+ def __setup__(cls):
+ super().__setup__()
+ cls.methods_company_needed = set()
@dualmethod
@ModelView.button
@@ -89,10 +103,18 @@
with Transaction().set_context(company=company.id):
super().run_once([cron])
- @staticmethod
- def default_companies():
- Company = Pool().get('company.company')
- return list(map(int, Company.search([])))
+ @fields.depends('method')
+ def on_change_with_company_needed(self, name=None):
+ return self.method in self.__class__.methods_company_needed
+
+ @fields.depends('companies', methods=['on_change_with_company_needed'])
+ def on_change_method(self):
+ pool = Pool()
+ Company = pool.get('company.company')
+ if self.on_change_with_company_needed():
+ self.companies = Company.search([])
+ else:
+ self.companies = []
class CronCompany(ModelSQL):
diff -r ed6d59c14b77 -r bea535142d87 modules/product_price_list_cache/ir.py
--- a/modules/product_price_list_cache/ir.py Wed Jul 08 14:59:40 2026 +0200
+++ b/modules/product_price_list_cache/ir.py Mon Jul 13 15:33:35 2026 +0200
@@ -12,3 +12,5 @@
super().__setup__()
cls.method.selection.append(
('product.price_list|fill_cache', "Fill Product Price List Cache"))
+ cls.methods_company_needed.add(
+ 'product.price_list|fill_cache')
diff -r ed6d59c14b77 -r bea535142d87 modules/sale/ir.py
--- a/modules/sale/ir.py Wed Jul 08 14:59:40 2026 +0200
+++ b/modules/sale/ir.py Mon Jul 13 15:33:35 2026 +0200
@@ -14,3 +14,5 @@
('sale.sale|cancel_expired_quotation',
"Cancel Expired Sale Quotation"),
])
+ cls.methods_company_needed.add(
+ 'sale.sale|cancel_expired_quotation')
diff -r ed6d59c14b77 -r bea535142d87 modules/sale_payment/ir.py
--- a/modules/sale_payment/ir.py Wed Jul 08 14:59:40 2026 +0200
+++ b/modules/sale_payment/ir.py Mon Jul 13 15:33:35 2026 +0200
@@ -12,3 +12,4 @@
super().__setup__()
cls.method.selection.append(
('sale.sale|payment_confirm', "Confirm sales based on payment"))
+ cls.methods_company_needed.add('sale.sale|payment_confirm')
diff -r ed6d59c14b77 -r bea535142d87 modules/sale_subscription/ir.py
--- a/modules/sale_subscription/ir.py Wed Jul 08 14:59:40 2026 +0200
+++ b/modules/sale_subscription/ir.py Mon Jul 13 15:33:35 2026 +0200
@@ -15,3 +15,7 @@
('sale.subscription|generate_invoice',
"Generate Subscription Invoices"),
])
+ cls.methods_company_needed.update({
+ 'sale.subscription.line|generate_consumption',
+ 'sale.subscription|generate_invoice',
+ })
diff -r ed6d59c14b77 -r bea535142d87 modules/stock/ir.py
--- a/modules/stock/ir.py Wed Jul 08 14:59:40 2026 +0200
+++ b/modules/stock/ir.py Mon Jul 13 15:33:35 2026 +0200
@@ -27,6 +27,10 @@
"Reschedule Internal Shipments"),
('ir.cron|stock_shipment_assign_try', "Assign Shipments"),
])
+ cls.methods_company_needed.update({
+ 'product.product|recompute_cost_price_from_moves',
+ 'ir.cron|stock_shipment_assign_try',
+ })
@classmethod
def __register__(cls, module):
diff -r ed6d59c14b77 -r bea535142d87 modules/stock_quantity_issue/ir.py
--- a/modules/stock_quantity_issue/ir.py Wed Jul 08 14:59:40 2026 +0200
+++ b/modules/stock_quantity_issue/ir.py Mon Jul 13 15:33:35 2026 +0200
@@ -13,3 +13,5 @@
('stock.quantity.issue|generate_issues',
"Generate Stock Quantity Issues"),
])
+ cls.methods_company_needed.add(
+ 'stock.quantity.issue|generate_issues')
diff -r ed6d59c14b77 -r bea535142d87 modules/stock_supply/ir.py
--- a/modules/stock_supply/ir.py Wed Jul 08 14:59:40 2026 +0200
+++ b/modules/stock_supply/ir.py Mon Jul 13 15:33:35 2026 +0200
@@ -12,3 +12,4 @@
cls.method.selection.extend([
('stock.order_point|supply_stock', "Supply Stock"),
])
+ cls.methods_company_needed.add('stock.order_point|supply_stock')