~vauxoo/addons-vauxoo/8.0-import_tax_tariff-dev-yani-rev-2

« back to all changes in this revision

Viewing changes to price_structure/model/product_product.py

  • Committer: Nhomar Hernandez
  • Date: 2013-04-19 20:33:12 UTC
  • mfrom: (542.1.314 addons-vauxoo)
  • Revision ID: nhomar@gmail.com-20130419203312-o35v7dn79l6vur0t
[MERGE - PEP8 AND V7-MIG] All migrated to V7 Just
improved osv.osv => osv.Model, osv.osv_memory => osv.TransientModel
import inside openerp.* enviroment
Erased class instansiation no necesarry anymore in V7
AUTOPEP8 run, Left PEP8 long lines manually.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#    Module Writen to OpenERP, Open Source Management Solution
5
5
#    Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
6
6
#    All Rights Reserved
7
 
###############Credits######################################################
8
 
#    Coded by: Vauxoo C.A.           
 
7
# Credits######################################################
 
8
#    Coded by: Vauxoo C.A.
9
9
#    Planified by: Nhomar Hernandez
10
10
#    Audited by: Vauxoo C.A.
11
11
#############################################################################
21
21
#
22
22
#    You should have received a copy of the GNU Affero General Public License
23
23
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 
################################################################################
25
 
 
26
 
from osv import fields, osv
27
 
import tools
28
 
from tools.translate import _
 
24
##########################################################################
 
25
 
 
26
from openerp.osv import osv, fields
 
27
import openerp.tools as tools
 
28
from openerp.tools.translate import _
 
29
 
29
30
from tools import config
30
 
import netsvc
 
31
import openerp.netsvc as netsvc
31
32
import decimal_precision as dp
32
 
from tools.sql import drop_view_if_exists
33
 
 
34
 
class product_product(osv.osv):
35
 
    
 
33
from openerp.tools.sql import drop_view_if_exists
 
34
 
 
35
 
 
36
 
 
37
class product_product(osv.Model):
 
38
 
36
39
    _inherit = 'product.product'
37
 
    
38
40
 
39
41
    def _search_price_list_item_c(self, cr, uid, ids, field_name, arg, context={}):
40
42
        item_obj = self.pool.get('product.pricelist.item')
41
43
        res = {}
42
 
        for product in self.browse(cr,uid,ids,context=context):
43
 
            item_ids = item_obj.search(cr,uid,[('categ_id','=',product.categ_id.id)],context=context)
44
 
            if context.get('query',True):
 
44
        for product in self.browse(cr, uid, ids, context=context):
 
45
            item_ids = item_obj.search(cr, uid, [(
 
46
                'categ_id', '=', product.categ_id.id)], context=context)
 
47
            if context.get('query', True):
45
48
                sql_str = item_ids and len(ids) == 1 and '''UPDATE product_pricelist_item set
46
49
                                product_active_id=%d
47
 
                                WHERE id %s %s '''%(product.id,len(item_ids) > 1 and 'in' or '=',len(item_ids) > 1 and tuple(item_ids) or item_ids[0])
 
50
                                WHERE id %s %s ''' % (product.id, len(item_ids) > 1 and 'in' or '=', len(item_ids) > 1 and tuple(item_ids) or item_ids[0])
48
51
                sql_str and cr.execute(sql_str)
49
52
                item_ids and len(ids) == 1 and cr.commit()
50
53
            res[product.id] = item_ids
51
54
 
52
55
        return res
53
56
 
54
 
 
55
57
    def _search_price_list_item_p(self, cr, uid, ids, field_name, arg, context={}):
56
 
        
 
58
 
57
59
        item_obj = self.pool.get('product.pricelist.item')
58
60
        res = {}
59
 
        for product in self.browse(cr,uid,ids,context=context):
60
 
            item_ids = item_obj.search(cr,uid,[('product_id','=',product.id)],context=context)
61
 
            if context.get('query',True):
 
61
        for product in self.browse(cr, uid, ids, context=context):
 
62
            item_ids = item_obj.search(cr, uid, [(
 
63
                'product_id', '=', product.id)], context=context)
 
64
            if context.get('query', True):
62
65
                sql_str = item_ids and len(ids) == 1 and '''UPDATE product_pricelist_item set
63
66
                                product_active_id=%d
64
 
                                WHERE id %s %s '''%(product.id,len(item_ids) > 1 and 'in' or '=',len(item_ids) > 1 and tuple(item_ids) or item_ids[0])
 
67
                                WHERE id %s %s ''' % (product.id, len(item_ids) > 1 and 'in' or '=', len(item_ids) > 1 and tuple(item_ids) or item_ids[0])
65
68
                sql_str and cr.execute(sql_str)
66
69
                item_ids and len(ids) == 1 and cr.commit()
67
70
            res[product.id] = item_ids
68
71
        return res
69
 
    
 
72
 
70
73
    def _write_price_list_item_p(obj, cr, uid, id, name, value, fnct_inv_arg, context={}):
71
74
        for val in value:
72
 
            if val[0] == 1 :
73
 
                sql_str = val[2].get('price_discount',False) and """UPDATE product_pricelist_item set
 
75
            if val[0] == 1:
 
76
                sql_str = val[2].get('price_discount', False) and """UPDATE product_pricelist_item set
74
77
                            price_discount='%s'
75
 
                            WHERE id=%d """ % (val[2].get('price_discount'), val[1]) 
76
 
                val[2].get('price_discount',False) and cr.execute(sql_str)
 
78
                            WHERE id=%d """ % (val[2].get('price_discount'), val[1])
 
79
                val[2].get('price_discount', False) and cr.execute(sql_str)
77
80
        return True
78
81
 
79
 
 
80
 
 
81
 
 
82
82
    _columns = {
83
 
    #'price_list_item_ids':fields.one2many('product.pricelit.item','product_id','Price List Item',help='Percent to compute cost from Price list item'),
84
 
    'price_list_item_ids': fields.function(_search_price_list_item_p, relation='product.pricelist.item',fnct_inv=_write_price_list_item_p,method=True, string="Price item by product", type='one2many'),
85
 
    'category_item_ids': fields.function(_search_price_list_item_c, relation='product.pricelist.item', method=True, string="Price item by category", type='one2many'),
 
83
        #'price_list_item_ids':fields.one2many('product.pricelit.item','product_id','Price List Item',help='Percent to compute cost from Price list item'),
 
84
        'price_list_item_ids': fields.function(_search_price_list_item_p, relation='product.pricelist.item', fnct_inv=_write_price_list_item_p, method=True, string="Price item by product", type='one2many'),
 
85
        'category_item_ids': fields.function(_search_price_list_item_c, relation='product.pricelist.item', method=True, string="Price item by category", type='one2many'),
86
86
 
87
87
    }
88
 
    
89
 
product_product()
90
 
 
91
 
 
92
 
class inherit_product_category(osv.osv):
 
88
 
 
89
 
 
90
 
 
91
class inherit_product_category(osv.Model):
93
92
    """ """
94
 
    
95
 
    _inherit='product.category'
96
93
 
 
94
    _inherit = 'product.category'
97
95
 
98
96
    def _search_price_list_item(self, cr, uid, ids, field_name, arg, context={}):
99
 
        
 
97
 
100
98
        item_obj = self.pool.get('product.pricelist.item')
101
99
        res = {}
102
 
        for category in self.browse(cr,uid,ids,context=context):
103
 
            res[category.id] = item_obj.search(cr,uid,[('categ_id','=',category.id)],context=context)
 
100
        for category in self.browse(cr, uid, ids, context=context):
 
101
            res[category.id] = item_obj.search(cr, uid, [(
 
102
                'categ_id', '=', category.id)], context=context)
104
103
        return res
105
104
 
106
 
 
107
105
    def _write_price_list_item(obj, cr, uid, id, name, value, fnct_inv_arg, context={}):
108
106
        for val in value:
109
 
            if val[0] == 1 :
110
 
                sql_str = val[2].get('price_discount',False) and """UPDATE product_pricelist_item set
 
107
            if val[0] == 1:
 
108
                sql_str = val[2].get('price_discount', False) and """UPDATE product_pricelist_item set
111
109
                            price_discount='%s'
112
 
                            WHERE id=%d """ % (val[2].get('price_discount'), val[1]) 
113
 
                val[2].get('price_discount',False) and cr.execute(sql_str)
 
110
                            WHERE id=%d """ % (val[2].get('price_discount'), val[1])
 
111
                val[2].get('price_discount', False) and cr.execute(sql_str)
114
112
                cr.commit()
115
113
        return True
116
114
 
117
 
    _columns={
118
 
    'price_list_item_ids': fields.function(_search_price_list_item, relation='product.pricelist.item',fnct_inv=_write_price_list_item,method=True, string="Price item by category", type='one2many'),
119
 
    
 
115
    _columns = {
 
116
        'price_list_item_ids': fields.function(_search_price_list_item, relation='product.pricelist.item', fnct_inv=_write_price_list_item, method=True, string="Price item by category", type='one2many'),
 
117
 
120
118
    }
121
119
 
122
 
inherit_product_category()
123