1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # Copyright (c) 2004-2008 Tiny SPRL (http://tiny.be) All Rights Reserved.
8 # WARNING: This program as such is intended to be used by professional
9 # programmers who take the whole responsability of assessing all potential
10 # consequences resulting from its eventual inadequacies and bugs
11 # End users who are looking for a ready-to-use solution with commercial
12 # garantees and support are strongly adviced to contract a Free Software
15 # This program is Free Software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation; either version 2
18 # of the License, or (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 ###############################################################################
31 from osv import fields,osv
32 from tools.translate import _
34 # Overloaded stock_picking to manage carriers :
35 class stock_picking(osv.osv):
36 _name = "stock.picking"
37 _description = "Picking list"
38 _inherit = 'stock.picking'
40 'carrier_id':fields.many2one("delivery.carrier","Carrier"),
41 'volume': fields.float('Volume'),
42 'weight': fields.float('Weight'),
45 def action_invoice_create(self, cursor, user, ids, journal_id=False,
46 group=False, type='out_invoice', context=None):
47 invoice_obj = self.pool.get('account.invoice')
48 picking_obj = self.pool.get('stock.picking')
49 carrier_obj = self.pool.get('delivery.carrier')
50 grid_obj = self.pool.get('delivery.grid')
51 invoice_line_obj = self.pool.get('account.invoice.line')
53 result = super(stock_picking, self).action_invoice_create(cursor, user,
54 ids, journal_id=journal_id, group=group, type=type,
57 picking_ids = result.keys()
58 invoice_ids = result.values()
61 for invoice in invoice_obj.browse(cursor, user, invoice_ids,
63 invoices[invoice.id] = invoice
65 for picking in picking_obj.browse(cursor, user, picking_ids,
67 if not picking.carrier_id:
69 grid_id = carrier_obj.grid_get(cursor, user, [picking.carrier_id.id],
70 picking.address_id.id, context=context)
72 raise osv.except_osv(_('Warning'),
73 _('The carrier %s (id: %d) has no delivery grid!') \
74 % (picking.carrier_id.name,
75 picking.carrier_id.id))
76 invoice = invoices[result[picking.id]]
77 price = grid_obj.get_price_from_picking(cursor, user, grid_id,
78 invoice.amount_untaxed, picking.weight, picking.volume,
80 account_id = picking.carrier_id.product_id.product_tmpl_id\
81 .property_account_income.id
83 account_id = picking.carrier_id.product_id.categ_id\
84 .property_account_income_categ.id
86 taxes = picking.carrier_id.product_id.taxes_id
88 partner_id=picking.address_id.partner_id and picking.address_id.partner_id.id or False
89 taxes_ids = [x.id for x in picking.carrier_id.product_id.taxes_id]
91 partner = picking.address_id.partner_id
92 account_id = self.pool.get('account.fiscal.position').map_account(cursor, user, partner, account_id)
93 taxes_ids = self.pool.get('account.fiscal.position').map_tax(cursor, user, partner, taxes)
95 invoice_line_obj.create(cursor, user, {
96 'name': picking.carrier_id.name,
97 'invoice_id': invoice.id,
98 'uos_id': picking.carrier_id.product_id.uos_id.id,
99 'product_id': picking.carrier_id.product_id.id,
100 'account_id': account_id,
103 'invoice_line_tax_id': [(6, 0,taxes_ids)],
109 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: