1 ##############################################################################
3 # OpenERP, Open Source Management Solution
4 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as
8 # published by the Free Software Foundation, either version 3 of the
9 # License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 ##############################################################################
21 from osv import fields,osv
23 from tools import config
25 class sale_order_line(osv.osv):
26 _name = "sale.order.line"
27 _inherit = "sale.order.line"
29 def _product_margin(self, cr, uid, ids, field_name, arg, context=None):
31 for line in self.browse(cr, uid, ids):
34 if line.purchase_price:
35 res[line.id] = round((line.price_unit*line.product_uos_qty*(100.0-line.discount)/100.0) -(line.purchase_price*line.product_uos_qty),2)
37 res[line.id] = round((line.price_unit*line.product_uos_qty*(100.0-line.discount)/100.0) -(line.product_id.standard_price*line.product_uos_qty),2)
41 'margin': fields.function(_product_margin, method=True, string='Margin', store=True),
42 'purchase_price': fields.float('Cost Price', digits=(16,2))
47 class sale_order(osv.osv):
48 _inherit = "sale.order"
50 def _product_margin(self, cr, uid, ids, field_name, arg, context=None):
52 for sale in self.browse(cr, uid, ids, context=context):
54 for line in sale.order_line:
55 result[sale.id] += line.margin or 0.0
59 'margin': fields.function(_product_margin, method=True, string='Margin', store=True),
64 class stock_picking(osv.osv):
65 _inherit = 'stock.picking'
68 'invoice_ids': fields.many2many('account.invoice', 'picking_invoice_rel', 'picking_id', 'invoice_id', 'Invoices', domain=[('type','=','in_invoice')]),
71 def create_invoice(self, cr, uid, ids, *args):
72 # need to carify with new requirement
75 picking_obj = self.pool.get('stock.picking')
76 picking_obj.write(cr, uid, ids, {'invoice_state' : '2binvoiced'})
77 res = picking_obj.action_invoice_create(cr, uid, ids, type='out_invoice', context={})
78 invoice_ids = res.values()
79 picking_obj.write(cr, uid, ids,{'invoice_ids': [[6,0,invoice_ids]]})
83 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: