1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
23 from tools.translate import _
25 from osv import osv, fields
27 class make_delivery(osv.osv_memory):
28 _name = "delivery.sale.order"
29 _description = 'Make Delievery'
32 'carrier_id': fields.many2one('delivery.carrier','Delivery Method', required=True),
36 def default_get(self, cr, uid, fields, context=None):
37 res = super(make_delivery, self).default_get(cr, uid, fields, context=context)
38 order_obj = self.pool.get('sale.order')
39 for order in order_obj.browse(cr, uid, context.get('active_ids', []), context=context):
40 carrier = order.carrier_id.id
42 carrier = order.partner_id.property_delivery_carrier.id
43 res.update({'carrier_id': carrier})
47 def view_init(self, cr , uid , fields, context=None):
50 order_obj = self.pool.get('sale.order')
51 for order in order_obj.browse(cr, uid, context.get('active_ids', []), context=context):
52 if not order.state in ('draft'):
53 raise osv.except_osv(_('Order not in draft state !'), _('The order state have to be draft to add delivery lines.'))
56 def delivery_set(self, cr, uid, ids, context=None):
59 rec_ids = context and context.get('active_ids',[])
60 order_obj = self.pool.get('sale.order')
61 line_obj = self.pool.get('sale.order.line')
62 grid_obj = self.pool.get('delivery.grid')
63 carrier_obj = self.pool.get('delivery.carrier')
64 acc_fp_obj = self.pool.get('account.fiscal.position')
65 order_objs = order_obj.browse(cr, uid, rec_ids, context=context)
66 for datas in self.browse(cr, uid, ids, context=context):
67 for order in order_objs:
68 grid_id = carrier_obj.grid_get(cr, uid, [datas.carrier_id.id],order.partner_shipping_id.id)
70 raise osv.except_osv(_('No grid available !'), _('No grid matching for this carrier !'))
72 if not order.state in ('draft'):
73 raise osv.except_osv(_('Order not in draft state !'), _('The order state have to be draft to add delivery lines.'))
75 grid = grid_obj.browse(cr, uid, grid_id, context=context)
77 taxes = grid.carrier_id.product_id.taxes_id
78 fpos = order.fiscal_position or False
79 taxes_ids = acc_fp_obj.map_tax(cr, uid, fpos, taxes)
80 line_obj.create(cr, uid, {
82 'name': grid.carrier_id.name,
84 'product_uom': grid.carrier_id.product_id.uom_id.id,
85 'product_id': grid.carrier_id.product_id.id,
86 'price_unit': grid_obj.get_price(cr, uid, grid.id, order, time.strftime('%Y-%m-%d'), context),
87 'tax_id': [(6,0,taxes_ids)],
88 'type': 'make_to_stock'
91 return {'type': 'ir.actions.act_window_close'}
95 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: