openerp-community-reviewer team mailing list archive
-
openerp-community-reviewer team
-
Mailing list archive
-
Message #01758
lp:~camptocamp/sale-wkfl/7.0-add-sale_stock_global_delivery_lead_time-afe into lp:sale-wkfl
Alexandre Fayolle - camptocamp has proposed merging lp:~camptocamp/sale-wkfl/7.0-add-sale_stock_global_delivery_lead_time-afe into lp:sale-wkfl.
Requested reviews:
Sale Core Editors (sale-core-editors)
For more details, see:
https://code.launchpad.net/~camptocamp/sale-wkfl/7.0-add-sale_stock_global_delivery_lead_time-afe/+merge/197205
[ADD] sale_stock_global_delivery_lead_time
This module adds a global delivery lead time on sale.orders. The resulting pickings are scheduled taking the global lead time in addition to the individual lead times on each sale.order.line.
--
https://code.launchpad.net/~camptocamp/sale-wkfl/7.0-add-sale_stock_global_delivery_lead_time-afe/+merge/197205
Your team Sale Core Editors is requested to review the proposed merge of lp:~camptocamp/sale-wkfl/7.0-add-sale_stock_global_delivery_lead_time-afe into lp:sale-wkfl.
=== added directory 'sale_stock_global_delivery_lead_time'
=== added file 'sale_stock_global_delivery_lead_time/__init__.py'
--- sale_stock_global_delivery_lead_time/__init__.py 1970-01-01 00:00:00 +0000
+++ sale_stock_global_delivery_lead_time/__init__.py 2013-11-29 14:15:27 +0000
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Author: Alexandre Fayolle
+# Copyright 2013 Camptocamp SA
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from . import sale_stock
=== added file 'sale_stock_global_delivery_lead_time/__openerp__.py'
--- sale_stock_global_delivery_lead_time/__openerp__.py 1970-01-01 00:00:00 +0000
+++ sale_stock_global_delivery_lead_time/__openerp__.py 2013-11-29 14:15:27 +0000
@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Author: Alexandre Fayolle
+# Copyright 2013 Camptocamp SA
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+{
+ 'name' : 'Sale global delivery lead time',
+ 'version' : '0.1',
+ 'category' : 'Sales Management',
+ 'description': '''
+ Provides a way of setting a delivery lead time for all lines of a sale order
+ ''',
+ 'author' : 'Camptocamp',
+ 'website' : 'http://www.camptocamp.com',
+ 'depends' : ['sale_stock'],
+ 'data' : ['sale_stock_view.xml'],
+ 'demo' : [],
+ 'test' : [],
+ 'installable': True,
+ 'auto_install' : False,
+ 'application' : False,
+}
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== added file 'sale_stock_global_delivery_lead_time/sale_stock.py'
--- sale_stock_global_delivery_lead_time/sale_stock.py 1970-01-01 00:00:00 +0000
+++ sale_stock_global_delivery_lead_time/sale_stock.py 2013-11-29 14:15:27 +0000
@@ -0,0 +1,84 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Author: Alexandre Fayolle
+# Copyright 2013 Camptocamp SA
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+from datetime import datetime, timedelta
+from dateutil.relativedelta import relativedelta
+
+from openerp.osv import orm, fields
+from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT, DATETIME_FORMATS_MAP, float_compare
+
+
+class sale_order(orm.Model):
+ _inherit = 'sale.order'
+
+ def _min_max_date_planned(self, cr, uid, ids, field_names, arg, context=None):
+ res = {}
+ if not ids:
+ return res
+ order_line_obj = self.pool.get('sale.order.line')
+ sale_infos = self.read(cr, uid, ids, ['delay', 'date_order'], context=context, load='_classic_write')
+ line_ids = order_line_obj.search(cr, uid, [('order_id', 'in', ids)], context=context)
+ line_delays = order_line_obj.read(cr, uid, line_ids, ['order_id', 'delay'], context=context, load='_classic_write')
+ order_line_delays = {} # dict order_id: [line delays]
+ for line_info in line_delays:
+ order_line_delays.setdefault(line_info['order_id'], []).append(line_info['delay'])
+ for sale_info in sale_infos:
+ sale_id = sale_info['id']
+ res[sale_id] = {}
+ start_date = datetime.strptime(self.date_to_datetime(cr, uid, sale_info['date_order'], context),
+ DEFAULT_SERVER_DATETIME_FORMAT)
+ print start_date, sale_info['delay'], order_line_delays.get(sale_id, [0])
+ min_delay = sale_info['delay'] + min(order_line_delays.get(sale_id, [0]))
+ max_delay = sale_info['delay'] + max(order_line_delays.get(sale_id, [0]))
+ min_date = start_date + relativedelta(days=min_delay)
+ max_date = start_date + relativedelta(days=max_delay)
+ print min_date, max_date
+ for name in field_names:
+ if name.startswith('min'):
+ date = min_date
+ elif name.startswith('max'):
+ date = max_date
+ else:
+ continue
+ res[sale_id][name] = date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
+ print res
+ return res
+
+ _columns = {'delay': fields.float('Delivery Lead Time',
+ required=True,
+ help="Number of days between the order confirmation and the shipping of the products to the customer. This lead time is added to the lead time of each line.",
+ readonly=True,
+ states={'draft': [('readonly', False)]}),
+ 'min_date_planned': fields.function(_min_max_date_planned,
+ type='date',
+ string='Earliest date planned',
+ method=True, multi='date_planned'),
+ 'max_date_planned': fields.function(_min_max_date_planned,
+ type='date',
+ string='Latest date planned',
+ method=True, multi='date_planned'),
+ }
+ _defaults = {'delay': 0,
+ }
+
+ def _get_date_planned(self, cr, uid, order, line, start_date, context=None):
+ date_planned = super(sale_order, self)._get_date_planned(cr, uid, order, line, start_date, context)
+ date_planned = datetime.strptime(date_planned, DEFAULT_SERVER_DATETIME_FORMAT) + relativedelta(days=order.delay or 0.0)
+ return date_planned.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
=== added file 'sale_stock_global_delivery_lead_time/sale_stock_view.xml'
--- sale_stock_global_delivery_lead_time/sale_stock_view.xml 1970-01-01 00:00:00 +0000
+++ sale_stock_global_delivery_lead_time/sale_stock_view.xml 2013-11-29 14:15:27 +0000
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+ <data>
+
+ <record id="view_order_form" model="ir.ui.view">
+ <field name="name">sale.order.form</field>
+ <field name="model">sale.order</field>
+ <field name="inherit_id" ref="sale_stock.view_order_form_inherit" />
+ <field name="arch" type="xml">
+ <field name='date_order' position="after">
+ <field name="delay"/>
+ <field name="min_date_planned"/>
+ <field name="max_date_planned"/>
+ </field>
+ </field>
+ </record>
+
+
+ </data>
+</openerp>
Follow ups