Launchpad automatic translations update.
[odoo/odoo.git] / addons / product_margin / wizard / product_margin.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21
22 import time
23
24 from osv import fields, osv
25 from tools.translate import _
26
27 class product_margin(osv.osv_memory):
28     _name = 'product.margin'
29     _description = 'Product Margin'
30     _columns = {
31         'from_date': fields.date('From'),
32         'to_date': fields.date('To'),
33         'invoice_state':fields.selection([
34            ('paid','Paid'),
35            ('open_paid','Open and Paid'),
36            ('draft_open_paid','Draft, Open and Paid'),
37         ],'Invoice State', select=True, required=True),
38     }
39     _defaults = {
40         'from_date': time.strftime('%Y-01-01'),
41         'to_date': time.strftime('%Y-12-31'),
42         'invoice_state': "open_paid",
43     }
44     def action_open_window(self, cr, uid, ids, context=None):
45         """
46             @param cr: the current row, from the database cursor,
47             @param uid: the current user’s ID for security checks,
48             @param ids: the ID or list of IDs if we want more than one
49
50             @return:
51         """
52         if context is None:
53             context = {}
54         mod_obj = self.pool.get('ir.model.data')
55         result = mod_obj._get_id(cr, uid, 'product', 'product_search_form_view')
56         id = mod_obj.read(cr, uid, result, ['res_id'], context=context)
57         cr.execute('select id,name from ir_ui_view where name=%s and type=%s', ('product.margin.graph', 'graph'))
58         view_res3 = cr.fetchone()[0]
59         cr.execute('select id,name from ir_ui_view where name=%s and type=%s', ('product.margin.form.inherit', 'form'))
60         view_res2 = cr.fetchone()[0]
61         cr.execute('select id,name from ir_ui_view where name=%s and type=%s', ('product.margin.tree', 'tree'))
62         view_res = cr.fetchone()[0]
63
64         #get the current product.margin object to obtain the values from it
65         product_margin_obj = self.browse(cr, uid, ids, context=context)[0]
66
67         context = {'invoice_state' : product_margin_obj.invoice_state}
68         if product_margin_obj.from_date:
69             context.update({'date_from': product_margin_obj.from_date})
70         if product_margin_obj.to_date:
71             context.update({'date_to': product_margin_obj.to_date})
72         return {
73             'name': _('Product Margins'),
74             'context': context,
75             'view_type': 'form',
76             "view_mode": 'tree,form,graph',
77             'res_model':'product.product',
78             'type': 'ir.actions.act_window',
79             'views': [(view_res,'tree'), (view_res2,'form'), (view_res3,'graph')],
80             'view_id': False,
81             'search_view_id': id['res_id']
82         }
83
84 product_margin()
85
86 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: