From 6097405ffb8c13013efea6bcb2e4f35c96157b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 24 Nov 2022 19:16:51 +0100 Subject: [PATCH] Enforce positive timedelta issue11869 review421921004 --- configuration.py | 9 +++++++-- party.py | 18 ++++++++++++------ product.py | 9 +++++++-- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/configuration.py b/configuration.py index 10cdf296ae..8edf3f596d 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 purchase_invoice_method = fields.Selection( @@ -36,7 +36,12 @@ class Configuration( ])) purchase_invoice_method = fields.MultiValue(purchase_invoice_method) get_purchase_invoice_method = get_purchase_methods('invoice_method') - purchase_process_after = fields.TimeDelta("Process Purchase after", + purchase_process_after = fields.TimeDelta( + "Process Purchase after", + domain=['OR', + ('purchase_process_after', '=', None), + ('purchase_process_after', '>=', TimeDelta()), + ], help="The grace period during which confirmed purchase " "can still be reset to draft.\n" "Applied only if a worker queue is activated.") diff --git a/party.py b/party.py index 96859e3d1d..e106e34d12 100644 --- a/party.py +++ b/party.py @@ -6,11 +6,20 @@ from trytond.modules.company.model import ( CompanyMultiValueMixin, CompanyValueMixin) from trytond.modules.party.exceptions import EraseError from trytond.pool import Pool, PoolMeta -from trytond.pyson import Eval +from trytond.pyson import Eval, TimeDelta supplier_currency = fields.Many2One( 'currency.currency', "Supplier Currency", help="Default currency for purchases from this party.") +supplier_lead_time = fields.TimeDelta( + "Lead Time", + domain=['OR', + ('supplier_lead_time', '=', None), + ('supplier_lead_time', '>=', TimeDelta()), + ], + help="The time from confirming the purchase order to receiving " + "the goods from the party when used as a supplier.\n" + "Used if no lead time is set on the product supplier.") class Party(CompanyMultiValueMixin, metaclass=PoolMeta): @@ -20,10 +29,7 @@ class Party(CompanyMultiValueMixin, metaclass=PoolMeta): " as customer.")) customer_codes = fields.One2Many( 'party.party.customer_code', 'party', "Customer Codes") - supplier_lead_time = fields.MultiValue(fields.TimeDelta("Lead Time", - help="The time from confirming the purchase order to receiving " - "the goods from the party when used as a supplier.\n" - "Used if no lead time is set on the product supplier.")) + supplier_lead_time = fields.MultiValue(supplier_lead_time) supplier_lead_times = fields.One2Many( 'party.party.supplier_lead_time', 'party', "Lead Times") supplier_currency = fields.MultiValue(supplier_currency) @@ -52,7 +58,7 @@ class SupplierLeadTime(ModelSQL, CompanyValueMixin): 'company': Eval('company', -1), }, depends={'company'}) - supplier_lead_time = fields.TimeDelta("Lead Time") + supplier_lead_time = supplier_lead_time class PartySupplierCurrency(ModelSQL, ValueMixin): diff --git a/product.py b/product.py index a549bca13d..951ff2d7f1 100644 --- a/product.py +++ b/product.py @@ -12,7 +12,7 @@ from trytond.model import ( from trytond.modules.currency.fields import Monetary from trytond.modules.product import price_digits from trytond.pool import Pool, PoolMeta -from trytond.pyson import Bool, Eval, If +from trytond.pyson import Bool, Eval, If, TimeDelta from trytond.tools import is_full_text, lstrip_wildcard from trytond.transaction import Transaction @@ -285,7 +285,12 @@ class ProductSupplier( company = fields.Many2One( 'company.company', "Company", required=True, ondelete='CASCADE') - lead_time = fields.TimeDelta('Lead Time', + lead_time = fields.TimeDelta( + "Lead Time", + domain=['OR', + ('lead_time', '=', None), + ('lead_time', '>=', TimeDelta()), + ], help="The time from confirming the purchase order to receiving the " "products.\n" "If empty the lead time of the supplier is used.")