2009-10-13 05:58:37 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2006-12-07 13:41:40 +00:00
|
|
|
##############################################################################
|
2009-10-14 11:15:34 +00:00
|
|
|
#
|
2009-01-20 08:48:19 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
2009-10-14 11:15:34 +00:00
|
|
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
2008-06-16 11:00:21 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 11:15:34 +00:00
|
|
|
# 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.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# 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
|
2009-10-14 11:15:34 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# 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/>.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
import time
|
|
|
|
import wizard
|
|
|
|
import ir
|
2007-08-14 14:13:20 +00:00
|
|
|
import pooler
|
2008-07-08 08:13:12 +00:00
|
|
|
from tools.translate import _
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2008-10-27 23:58:25 +00:00
|
|
|
from tools.misc import UpdateableStr
|
|
|
|
|
|
|
|
delivery_form = UpdateableStr()
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
delivery_fields = {
|
2008-07-22 15:11:28 +00:00
|
|
|
'carrier_id' : {'string':'Delivery Method', 'type':'many2one', 'relation': 'delivery.carrier','required':True}
|
2006-12-07 13:41:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def _delivery_default(self, cr, uid, data, context):
|
2008-07-22 15:11:28 +00:00
|
|
|
order_obj = pooler.get_pool(cr.dbname).get('sale.order')
|
|
|
|
order = order_obj.browse(cr, uid, data['ids'])[0]
|
2008-10-27 23:58:25 +00:00
|
|
|
delivery_form.string="""<?xml version="1.0"?>
|
|
|
|
<form string="Create deliveries">
|
|
|
|
<separator colspan="4" string="Delivery Method" />
|
|
|
|
<field name="carrier_id" context="{'order_id': %d}"/>
|
|
|
|
</form>
|
|
|
|
""" % (data['id'],)
|
|
|
|
|
2009-01-20 08:48:19 +00:00
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
if not order.state in ('draft'):
|
|
|
|
raise wizard.except_wizard(_('Order not in draft state !'), _('The order state have to be draft to add delivery lines.'))
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2009-01-20 08:48:19 +00:00
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
carrier_id = order.partner_id.property_delivery_carrier.id
|
|
|
|
return {'carrier_id': carrier_id}
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
def _delivery_set(self, cr, uid, data, context):
|
2008-07-22 15:11:28 +00:00
|
|
|
order_obj = pooler.get_pool(cr.dbname).get('sale.order')
|
|
|
|
line_obj = pooler.get_pool(cr.dbname).get('sale.order.line')
|
|
|
|
order_objs = order_obj.browse(cr, uid, data['ids'], context)
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
for order in order_objs:
|
|
|
|
grid_id = pooler.get_pool(cr.dbname).get('delivery.carrier').grid_get(cr, uid, [data['form']['carrier_id']],order.partner_shipping_id.id)
|
|
|
|
if not grid_id:
|
|
|
|
raise wizard.except_wizard(_('No grid avaible !'), _('No grid matching for this carrier !'))
|
2008-09-26 10:25:10 +00:00
|
|
|
grid_obj=pooler.get_pool(cr.dbname).get('delivery.grid')
|
|
|
|
grid = grid_obj.browse(cr, uid, [grid_id])[0]
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2008-10-21 16:28:19 +00:00
|
|
|
taxes = grid.carrier_id.product_id.taxes_id
|
2009-01-20 08:48:19 +00:00
|
|
|
fpos = order.fiscal_position or False
|
|
|
|
taxes_ids = pooler.get_pool(cr.dbname).get('account.fiscal.position').map_tax(cr, uid, fpos, taxes)
|
2008-07-22 15:11:28 +00:00
|
|
|
line_obj.create(cr, uid, {
|
|
|
|
'order_id': order.id,
|
|
|
|
'name': grid.carrier_id.name,
|
|
|
|
'product_uom_qty': 1,
|
|
|
|
'product_uom': grid.carrier_id.product_id.uom_id.id,
|
|
|
|
'product_id': grid.carrier_id.product_id.id,
|
2009-01-20 08:48:19 +00:00
|
|
|
'price_unit': grid_obj.get_price(cr, uid, grid.id, order, time.strftime('%Y-%m-%d'), context),
|
2008-09-26 10:25:10 +00:00
|
|
|
'tax_id': [(6,0,taxes_ids)],
|
2008-07-22 15:11:28 +00:00
|
|
|
'type': 'make_to_stock'
|
2008-10-27 23:58:25 +00:00
|
|
|
})
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
return {}
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
class make_delivery(wizard.interface):
|
2008-07-22 15:11:28 +00:00
|
|
|
states = {
|
|
|
|
'init' : {
|
|
|
|
'actions' : [_delivery_default],
|
2008-11-06 22:54:51 +00:00
|
|
|
'result' : {'type' : 'form', 'arch' : delivery_form, 'fields' : delivery_fields, 'state' : [('end', 'Cancel', 'gtk-cancel'),('delivery', 'Add Delivery Costs', 'gtk-ok') ]}
|
2008-07-22 15:11:28 +00:00
|
|
|
},
|
|
|
|
'delivery' : {
|
|
|
|
'actions' : [_delivery_set],
|
|
|
|
'result' : {'type' : 'state', 'state' : 'end'}
|
|
|
|
},
|
|
|
|
}
|
2006-12-07 13:41:40 +00:00
|
|
|
make_delivery("delivery.sale.order")
|
2008-07-23 14:41:47 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|