changeset 8850aa25cd14 in modules/sale:default
details: https://hg.tryton.org/modules/sale?cmd=changeset;node=8850aa25cd14
description:
        Add default lead time for products

        issue9420
        review3117710
diffstat:

 CHANGELOG                           |   1 +
 __init__.py                         |   2 +
 product.py                          |  45 ++++++++++++++++++++++++++++++------
 product.xml                         |   6 ++++
 view/product_configuration_form.xml |   9 +++++++
 5 files changed, 55 insertions(+), 8 deletions(-)

diffs (138 lines):

diff -r a88e6cd681a7 -r 8850aa25cd14 CHANGELOG
--- a/CHANGELOG Sun Jan 17 00:58:44 2021 +0100
+++ b/CHANGELOG Tue Jan 19 15:00:08 2021 +0100
@@ -1,3 +1,4 @@
+* Add default lead time for products
 * Add summary to sale line list
 * Add TaxableMixin to sale line
 
diff -r a88e6cd681a7 -r 8850aa25cd14 __init__.py
--- a/__init__.py       Sun Jan 17 00:58:44 2021 +0100
+++ b/__init__.py       Tue Jan 19 15:00:08 2021 +0100
@@ -21,6 +21,8 @@
         sale.SaleLineTax,
         sale.SaleLineIgnoredMove,
         sale.SaleLineRecreatedMove,
+        product.Configuration,
+        product.DefaultLeadTime,
         product.Template,
         product.Product,
         product.SaleContext,
diff -r a88e6cd681a7 -r 8850aa25cd14 product.py
--- a/product.py        Sun Jan 17 00:58:44 2021 +0100
+++ b/product.py        Tue Jan 19 15:00:08 2021 +0100
@@ -2,13 +2,31 @@
 # this repository contains the full copyright notices and license terms.
 import datetime
 
-from trytond.model import ModelView, fields
+from trytond.model import ModelSQL, ModelView, fields
 from trytond.pyson import Eval
 from trytond.pool import Pool, PoolMeta
 from trytond.transaction import Transaction
+from trytond.modules.company.model import CompanyValueMixin
 from trytond.modules.product import price_digits
 
 
+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."))
+
+
+class DefaultLeadTime(ModelSQL, CompanyValueMixin):
+    "Product Default Lead Time"
+    __name__ = 'product.configuration.default_lead_time'
+    default_lead_time = fields.TimeDelta("Default Lead Time")
+
+
 class Template(metaclass=PoolMeta):
     __name__ = 'product.template'
     salable = fields.Boolean("Salable")
@@ -27,7 +45,10 @@
         states={
             'invisible': ~Eval('salable', False),
             },
-        depends=['salable'])
+        depends=['salable'],
+        help="The time from confirming the sales order to sending the "
+        "products.\n"
+        "If empty the default lead time from the configuration is used.")
 
     @classmethod
     def __register__(cls, module_name):
@@ -51,10 +72,6 @@
                         where=sql_table.id == id_))
             table.drop_column('delivery_time')
 
-    @staticmethod
-    def default_lead_time():
-        return datetime.timedelta(0)
-
     @fields.depends('default_uom', 'sale_uom', 'salable')
     def on_change_default_uom(self):
         try:
@@ -137,6 +154,16 @@
                             currency, round=False)
         return prices
 
+    @property
+    def lead_time_used(self):
+        pool = Pool()
+        Configuration = pool.get('product.configuration')
+        if self.lead_time is None:
+            config = Configuration(1)
+            return config.get_multivalue('default_lead_time')
+        else:
+            return self.lead_time
+
     def compute_shipping_date(self, date=None):
         '''
         Compute the shipping date at the given date
@@ -145,9 +172,11 @@
 
         if not date:
             date = Date.today()
-        if self.lead_time is None:
+
+        lead_time = self.lead_time_used
+        if lead_time is None:
             return datetime.date.max
-        return date + self.lead_time
+        return date + lead_time
 
 
 class SaleContext(ModelView):
diff -r a88e6cd681a7 -r 8850aa25cd14 product.xml
--- a/product.xml       Sun Jan 17 00:58:44 2021 +0100
+++ b/product.xml       Tue Jan 19 15:00:08 2021 +0100
@@ -38,5 +38,11 @@
             <field name="type">form</field>
             <field name="name">product_sale_context_form</field>
         </record>
+
+        <record model="ir.ui.view" id="product_configuration_view_form">
+            <field name="model">product.configuration</field>
+            <field name="inherit" 
ref="product.product_configuration_view_form"/>
+            <field name="name">product_configuration_form</field>
+        </record>
     </data>
 </tryton>
diff -r a88e6cd681a7 -r 8850aa25cd14 view/product_configuration_form.xml
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/view/product_configuration_form.xml       Tue Jan 19 15:00:08 2021 +0100
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<!-- This file is part of Tryton.  The COPYRIGHT file at the top level of
+this repository contains the full copyright notices and license terms. -->
+<data>
+    <xpath expr="/form" position="inside">
+        <label name="default_lead_time"/>
+        <field name="default_lead_time"/>
+    </xpath>
+</data>

Reply via email to