Replace Delivery Time by Lead Time on Product Template

and rename Delivery Date of Sale Line into Shipping Date.

issue5275
review22741002
This commit is contained in:
Cédric Krier committed 2016-02-02 21:16:12 +01:00
1 parent 28c560d8e2
commit f75f52fb0d
5 files changed
+41 -17

No files matched your search

+3
View File
@@ -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
+29 -8
View File
@@ -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
+5 -5
View File
@@ -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
+2 -2
View File
@@ -24,8 +24,8 @@ this repository contains the full copyright notices and license terms. -->
<field name="unit_price"/>
<label name="amount"/>
<field name="amount"/>
<label name="delivery_date"/>
<field name="delivery_date"/>
<label name="shipping_date"/>
<field name="shipping_date"/>
</page>
<page string="Taxes" id="taxes">
<field name="taxes" colspan="4"/>
+2 -2
View File
@@ -13,8 +13,8 @@ this repository contains the full copyright notices and license terms. -->
<field name="salable"/>
<label name="sale_uom"/>
<field name="sale_uom"/>
<label name="delivery_time"/>
<field name="delivery_time"/>
<label name="lead_time"/>
<field name="lead_time"/>
</page>
</xpath>
</data>