diff --git a/configuration.py b/configuration.py index 6eda5a3eb0..3a1f68445d 100644 --- a/configuration.py +++ b/configuration.py @@ -6,7 +6,7 @@ from trytond.model import ( from trytond.modules.company.model import ( CompanyMultiValueMixin, CompanyValueMixin) from trytond.pool import Pool -from trytond.pyson import Eval, Id +from trytond.pyson import Eval, Id, TimeDelta from trytond.tools.multivalue import migrate_property sale_invoice_method = fields.Selection( @@ -48,7 +48,12 @@ class Configuration( get_sale_invoice_methods = get_sale_methods('invoice_method') sale_shipment_method = fields.MultiValue(sale_shipment_method) get_sale_shipment_methods = get_sale_methods('shipment_method') - sale_process_after = fields.TimeDelta("Process Sale after", + sale_process_after = fields.TimeDelta( + "Process Sale after", + domain=['OR', + ('sale_process_after', '=', None), + ('sale_process_after', '>=', TimeDelta()), + ], help="The grace period during which confirmed sale " "can still be reset to draft.\n" "Applied if a worker queue is activated.") diff --git a/product.py b/product.py index abe4952278..d37b436d67 100644 --- a/product.py +++ b/product.py @@ -8,19 +8,24 @@ from trytond.model import ModelSQL, ModelView, ValueMixin, fields from trytond.modules.currency.fields import Monetary from trytond.modules.product import price_digits from trytond.pool import Pool, PoolMeta -from trytond.pyson import Eval +from trytond.pyson import Eval, TimeDelta from trytond.transaction import Transaction +default_lead_time = fields.TimeDelta( + "Default Lead Time", + domain=['OR', + ('default_lead_time', '=', None), + ('default_lead_time', '>=', TimeDelta()), + ], + help="The time from confirming the sales order to sending the " + "products.\n" + "Used for products without a lead time.") + class Configuration(metaclass=PoolMeta): __name__ = 'product.configuration' - default_lead_time = fields.MultiValue( - fields.TimeDelta( - "Default Lead Time", - help="The time from confirming the sales order to sending the " - "products.\n" - "Used for products without a lead time.")) + default_lead_time = fields.MultiValue(default_lead_time) @classmethod def default_default_lead_time(cls, **pattern): @@ -30,7 +35,7 @@ class Configuration(metaclass=PoolMeta): class DefaultLeadTime(ModelSQL, ValueMixin): "Product Default Lead Time" __name__ = 'product.configuration.default_lead_time' - default_lead_time = fields.TimeDelta("Default Lead Time") + default_lead_time = default_lead_time class Template(metaclass=PoolMeta): @@ -47,6 +52,10 @@ class Template(metaclass=PoolMeta): ]) lead_time = fields.MultiValue(fields.TimeDelta( "Lead Time", + domain=['OR', + ('lead_time', '=', None), + ('lead_time', '>=', TimeDelta()), + ], states={ 'invisible': ~Eval('salable', False), }, @@ -112,7 +121,12 @@ class ProductLeadTime(ModelSQL, ValueMixin): template = fields.Many2One( 'product.template', "Template", ondelete='CASCADE') - lead_time = fields.TimeDelta("Lead Time") + lead_time = fields.TimeDelta( + "Lead Time", + domain=['OR', + ('lead_time', '=', None), + ('lead_time', '>=', TimeDelta()), + ]) @classmethod def __register__(cls, module_name):