diff --git a/CHANGELOG b/CHANGELOG index 2bd628f5f6..9c0c1ef05c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +* Replace Delivery Time by Lead Time on Product Template +* Rename Delivery Date of Sale Line into Shipping Date + Version 3.8.0 - 2015-11-02 * Bug fixes (see mercurial logs for details) * Delivery Date of Line shows effective date if possible diff --git a/product.py b/product.py index 6452c2e073..c9695aa3f5 100644 --- a/product.py +++ b/product.py @@ -6,6 +6,7 @@ from trytond.model import fields from trytond.pyson import Eval from trytond.pool import Pool, PoolMeta from trytond.transaction import Transaction +from trytond import backend __all__ = ['Template', 'Product'] __metaclass__ = PoolMeta @@ -25,13 +26,12 @@ class Template: ('category', '=', Eval('default_uom_category')), ], depends=['active', 'salable', 'default_uom_category']) - delivery_time = fields.Integer('Delivery Time', states={ + lead_time = fields.TimeDelta('Lead Time', states={ 'readonly': ~Eval('active', True), 'invisible': ~Eval('salable', False), 'required': Eval('salable', False), }, - depends=['active', 'salable'], - help='In number of days') + depends=['active', 'salable']) @classmethod def __setup__(cls): @@ -47,9 +47,30 @@ class Template: if 'salable' not in cls.account_revenue.depends: cls.account_revenue.depends.append('salable') + @classmethod + def __register__(cls, module_name): + TableHandler = backend.get('TableHandler') + cursor = Transaction().cursor + table = TableHandler(cursor, cls, module_name) + sql_table = cls.__table__() + + super(Template, cls).__register__(module_name) + + # Migration from 3.8: change delivery_time into timedelta lead_time + if table.column_exist('delivery_time'): + cursor.execute(*sql_table.select( + sql_table.id, sql_table.delivery_time)) + for id_, delivery_time in cursor.fetchall(): + lead_time = datetime.timedelta(days=delivery_time) + cursor.execute(*sql_table.update( + [sql_table.lead_time], + [lead_time], + where=sql_table.id == id_)) + table.drop_column('delivery_time') + @staticmethod - def default_delivery_time(): - return 0 + def default_lead_time(): + return datetime.timedelta(0) @fields.depends('default_uom', 'sale_uom', 'salable') def on_change_default_uom(self): @@ -116,12 +137,12 @@ class Product: currency, round=False) return prices - def compute_delivery_date(self, date=None): + def compute_shipping_date(self, date=None): ''' - Compute the delivery date a the given date + Compute the shipping date at the given date ''' Date = Pool().get('ir.date') if not date: date = Date.today() - return date + datetime.timedelta(self.delivery_time) + return date + self.lead_time diff --git a/sale.py b/sale.py index 77ca6b05b2..559ae2c605 100644 --- a/sale.py +++ b/sale.py @@ -1045,12 +1045,12 @@ class SaleLine(ModelSQL, ModelView): 'From Location'), 'get_from_location') to_location = fields.Function(fields.Many2One('stock.location', 'To Location'), 'get_to_location') - delivery_date = fields.Function(fields.Date('Delivery Date', + shipping_date = fields.Function(fields.Date('Shipping Date', states={ 'invisible': Eval('type') != 'line', }, depends=['type']), - 'on_change_with_delivery_date') + 'on_change_with_shipping_date') @classmethod def __setup__(cls): @@ -1282,13 +1282,13 @@ class SaleLine(ModelSQL, ModelView): return self.warehouse.input_location.id @fields.depends('product', 'quantity', 'moves', '_parent_sale.sale_date') - def on_change_with_delivery_date(self, name=None): + def on_change_with_shipping_date(self, name=None): if self.moves: return min(m.effective_date if m.effective_date else m.planned_date for m in self.moves) if self.product and self.quantity > 0: date = self.sale.sale_date if self.sale else None - return self.product.compute_delivery_date(date=date) + return self.product.compute_shipping_date(date=date) def get_invoice_line(self, invoice_type): ''' @@ -1447,7 +1447,7 @@ class SaleLine(ModelSQL, ModelView): move.company = self.sale.company move.unit_price = self.unit_price move.currency = self.sale.currency - move.planned_date = self.delivery_date + move.planned_date = self.shipping_date move.invoice_lines = self._get_move_invoice_lines(shipment_type) move.origin = self return move diff --git a/view/sale_line_form.xml b/view/sale_line_form.xml index 949b1dce4a..300cac2f0e 100644 --- a/view/sale_line_form.xml +++ b/view/sale_line_form.xml @@ -24,8 +24,8 @@ this repository contains the full copyright notices and license terms. -->