Show companies field of cron only for methods that need them

Closes #14952
This commit is contained in:
Cédric Krier
2026-07-13 15:33:35 +02:00
parent b167bd1e77
commit 24405399a0
20 changed files with 67 additions and 34 deletions
+1
View File
@@ -14,3 +14,4 @@ class Cron(metaclass=PoolMeta):
('account.move.line|reconcile_automatic',
"Reconcile Move Lines Automatically"),
])
cls.methods_company_needed.add('account.move.line|reconcile_automatic')
+4
View File
@@ -14,3 +14,7 @@ class Cron(metaclass=PoolMeta):
('account.invoice.chorus|update',
"Update invoices from Chorus"),
])
cls.methods_company_needed.update({
'account.invoice.chorus|send',
'account.invoice.chorus|update',
})
+5
View File
@@ -23,3 +23,8 @@ class Cron(metaclass=PoolMeta):
('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',
})
@@ -139,7 +139,6 @@ Run cron::
>>> 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 @@ Run cron::
>>> 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 @@ Refund some amount::
>>> 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 @@ Refund some amount::
>>> 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
+2
View File
@@ -12,3 +12,5 @@ class Cron(metaclass=PoolMeta):
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')
+4
View File
@@ -23,3 +23,7 @@ class Cron(metaclass=PoolMeta):
('account.payment.stripe.account|fetch_events',
"Fetch Stripe Events"),
])
cls.methods_company_needed.update({
'account.payment|stripe_charge',
'account.payment|stripe_capture_',
})
@@ -13,7 +13,7 @@ Imports::
>>> 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 @@ Setup fetch events cron::
>>> 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 @@ Run cron::
>>> 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 @@ Run cron::
>>> 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()
@@ -13,7 +13,7 @@ Imports::
>>> 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 @@ Setup fetch events cron::
>>> cron_fetch_events, = Cron.find([
... ('method', '=', 'account.payment.stripe.account|fetch_events'),
... ])
>>> cron_fetch_events.companies.append(get_company())
Create payment journal::
@@ -10,7 +10,7 @@ Imports::
>>> 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 @@ Activate modules::
>>> 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 @@ Setup cron::
>>> 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::
@@ -13,7 +13,7 @@ Imports::
>>> 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 @@ Activate modules::
>>> 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 @@ Create Stripe account::
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 @@ Create party::
Register card::
>>> Cron = Model.get('ir.cron')
>>> Customer = Model.get('account.payment.stripe.customer')
>>> customer = Customer()
>>> customer.party = party
@@ -82,7 +76,6 @@ Register card::
>>> 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)
@@ -13,7 +13,7 @@ Imports::
>>> 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 @@ Setup fetch events cron::
>>> cron_fetch_events, = Cron.find([
... ('method', '=', 'account.payment.stripe.account|fetch_events'),
... ])
>>> cron_fetch_events.companies.append(get_company())
Create payment journal::
+2
View File
@@ -13,3 +13,5 @@ class Cron(metaclass=PoolMeta):
('account.account.receivable.rule|apply',
"Apply Account Receivable Rules"),
])
cls.methods_company_needed.add(
'account.account.receivable.rule|apply')
+27 -5
View File
@@ -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 @@ class Cron(metaclass=PoolMeta):
'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 @@ class Cron(metaclass=PoolMeta):
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):
+2
View File
@@ -12,3 +12,5 @@ class Cron(metaclass=PoolMeta):
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')
+2
View File
@@ -14,3 +14,5 @@ class Cron(metaclass=PoolMeta):
('sale.sale|cancel_expired_quotation',
"Cancel Expired Sale Quotation"),
])
cls.methods_company_needed.add(
'sale.sale|cancel_expired_quotation')
+1
View File
@@ -12,3 +12,4 @@ class Cron(metaclass=PoolMeta):
super().__setup__()
cls.method.selection.append(
('sale.sale|payment_confirm', "Confirm sales based on payment"))
cls.methods_company_needed.add('sale.sale|payment_confirm')
+4
View File
@@ -15,3 +15,7 @@ class Cron(metaclass=PoolMeta):
('sale.subscription|generate_invoice',
"Generate Subscription Invoices"),
])
cls.methods_company_needed.update({
'sale.subscription.line|generate_consumption',
'sale.subscription|generate_invoice',
})
+4
View File
@@ -27,6 +27,10 @@ class Cron(metaclass=PoolMeta):
"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):
+2
View File
@@ -13,3 +13,5 @@ class Cron(metaclass=PoolMeta):
('stock.quantity.issue|generate_issues',
"Generate Stock Quantity Issues"),
])
cls.methods_company_needed.add(
'stock.quantity.issue|generate_issues')
+1
View File
@@ -12,3 +12,4 @@ class Cron(metaclass=PoolMeta):
cls.method.selection.extend([
('stock.order_point|supply_stock', "Supply Stock"),
])
cls.methods_company_needed.add('stock.order_point|supply_stock')