~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to cost_structure/wizard/default_cost_to_report.py

  • Committer: Gabriela (Vauxoo)
  • Date: 2012-01-02 16:24:49 UTC
  • Revision ID: gabrielaquilarque97@gmail.com-20120102162449-lhxnrtif2ud36du2

[ADD] Added new module invoice_so.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
# -*- encoding: utf-8 -*-
3
 
###########################################################################
4
 
#    Module Writen to OpenERP, Open Source Management Solution
5
 
#    Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
6
 
#    All Rights Reserved
7
 
# Credits######################################################
8
 
#    Coded by: Vauxoo C.A.
9
 
#    Planified by: Nhomar Hernandez
10
 
#    Audited by: Vauxoo C.A.
11
 
#############################################################################
12
 
#    This program is free software: you can redistribute it and/or modify
13
 
#    it under the terms of the GNU Affero General Public License as published by
14
 
#    the Free Software Foundation, either version 3 of the License, or
15
 
#    (at your option) any later version.
16
 
#
17
 
#    This program is distributed in the hope that it will be useful,
18
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 
#    GNU Affero General Public License for more details.
21
 
#
22
 
#    You should have received a copy of the GNU Affero General Public License
23
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 
##########################################################################
25
 
 
26
 
from openerp.osv import osv, fields
27
 
import openerp.tools as tools
28
 
from openerp.tools.translate import _
29
 
 
30
 
from tools import config
31
 
import openerp.netsvc as netsvc
32
 
import decimal_precision as dp
33
 
import time
34
 
import datetime
35
 
import re
36
 
 
37
 
 
38
 
class default_price_to_report(osv.TransientModel):
39
 
 
40
 
    _name = 'default.price.to.report'
41
 
 
42
 
    _columns = {
43
 
        'list_price': fields.many2one('product.pricelist', 'List Price'),
44
 
        'sure': fields.boolean('Sure?', help="Are sure this operation"),
45
 
    }
46
 
 
47
 
    def default_price(self, cr, uid, ids, context=None):
48
 
        if context is None:
49
 
            context = {}
50
 
 
51
 
        method_obj = self.pool.get('method.price')
52
 
        product_obj = self.pool.get('product.product')
53
 
        wzr_brw = self.browse(cr, uid, ids, context=context)[0]
54
 
        if wzr_brw.sure:
55
 
            if context.get('active_ids'):
56
 
                name = wzr_brw.list_price and wzr_brw.list_price.name or False
57
 
                name = name.split(' ')
58
 
                name = name and name[0] == 'Precio' and name[
59
 
                    1].isdigit() and name[1]
60
 
                print name
61
 
                if name:
62
 
                    cost_id = [i.property_cost_structure and
63
 
                        i.property_cost_structure.id\
64
 
                        for i in product_obj.browse(
65
 
                        cr, uid, context.get('active_ids'), context=context)]
66
 
                    methods_ids = method_obj.search(cr, uid,
67
 
                    [('cost_structure_id', 'in', cost_id), (
68
 
                        'default_cost', '=', True)], context=context)
69
 
                    if methods_ids:
70
 
                        raise osv.except_osv(_('Error'), _(
71
 
                            'The product already has a default_cost'))
72
 
                    methods_ids = method_obj.search(cr, uid,
73
 
                        [('cost_structure_id', 'in', cost_id), (
74
 
                        'sequence', '=', int(name))], context=context)
75
 
                    method_obj.write(cr, uid, methods_ids, {
76
 
                                     'default_cost': True}, context=context)
77
 
        else:
78
 
            raise osv.except_osv(_('Error'), _('Please select sure option'))
79
 
        return {'type': 'ir.actions.act_window_close'}