changeset 29c487454fe9 in modules/sale:default
details: https://hg.tryton.org/modules/sale?cmd=changeset&node=29c487454fe9
description:
Enforce positive timedelta
issue11869
review421921004
diffstat:
configuration.py | 9 +++++++--
product.py | 32 +++++++++++++++++++++++---------
2 files changed, 30 insertions(+), 11 deletions(-)
diffs (95 lines):
diff -r 81549ea0f42f -r 29c487454fe9 configuration.py
--- a/configuration.py Mon Oct 31 17:07:31 2022 +0100
+++ b/configuration.py Thu Nov 24 19:16:51 2022 +0100
@@ -6,7 +6,7 @@
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 @@
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 -r 81549ea0f42f -r 29c487454fe9 product.py
--- a/product.py Mon Oct 31 17:07:31 2022 +0100
+++ b/product.py Thu Nov 24 19:16:51 2022 +0100
@@ -8,19 +8,24 @@
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 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 @@
])
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 @@
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):