8
8
9
9
class Parser (report_sxw .rml_parse ):
10
10
11
-
12
11
def __init__ (self , cr , uid , name , context ):
13
12
super (Parser , self ).__init__ (cr , uid , name , context )
14
13
15
14
lang = context .get ('lang' , 'es_ES' )
16
15
16
+ self .product_type = context .get ('product_type' , 'product.product' )
17
17
pricelist_ids = context .get ('pricelist_ids' , [])
18
18
pricelists = self .pool ['product.pricelist' ].browse (
19
- cr , uid , pricelist_ids , context = context )
19
+ cr , uid , pricelist_ids , context = context )
20
20
21
21
categories_order = context .get ('categories_order' , '' )
22
22
23
23
# Get categories ordered
24
- categories = self .pool ['product.category' ]
24
+ category_type = context .get ('category_type' , False )
25
+ if category_type == 'public_category' :
26
+ categories = self .pool ['product.public.category' ]
27
+ else :
28
+ categories = self .pool ['product.category' ]
25
29
category_ids = context .get ('category_ids' , [])
26
30
category_ids = categories .search (
27
31
cr , uid , [('id' , 'in' , category_ids )],
@@ -30,14 +34,13 @@ def __init__(self, cr, uid, name, context):
30
34
cr , uid , category_ids , context = context )
31
35
32
36
products = self .get_products (category_ids , context = context )
33
-
34
37
company_id = self .pool ['res.users' ].browse (
35
38
cr , uid , [uid ])[0 ].company_id
36
-
37
39
self .localcontext .update ({
38
40
'lang' : lang ,
39
41
'categories' : categories ,
40
42
'products' : products ,
43
+ 'product_type' : self .product_type ,
41
44
'company_logo' : company_id .logo ,
42
45
'pricelists' : pricelists ,
43
46
'today' : time .localtime (),
@@ -48,11 +51,13 @@ def __init__(self, cr, uid, name, context):
48
51
})
49
52
50
53
def field_value_get (self , product , field , context = None ):
51
- # TODO hacer funcioal esto en el reporte ods. El problema es que deberiamos usar export_data en vez de read para poder elegir que ver del padre, por ejemplo "categ_id/name"
54
+ # TODO hacer funcioal esto en el reporte ods. El problema es que
55
+ # deberiamos usar export_data en vez de read para poder elegir que ver
56
+ # del padre, por ejemplo "categ_id/name"
52
57
if not context :
53
58
context = {}
54
59
55
- product_obj = self .pool .get ('product.product' )
60
+ product_obj = self .pool .get (self . product_type )
56
61
field_value = product_obj .read (
57
62
self .cr , self .uid , [product .id ], [field ], context = context )
58
63
return field_value [0 ].get (field , '' )
@@ -61,11 +66,10 @@ def get_price(self, product, pricelist, context=None):
61
66
if not context :
62
67
context = {}
63
68
context ['pricelist' ] = pricelist .id
64
-
65
- product_obj = self .pool .get ('product.product' )
66
- price = product_obj ._product_price (
67
- self .cr , self .uid , [product .id ], False , False , context = context )
68
- return price .get (product .id , 0.0 )
69
+ product_obj = self .pool [self .product_type ]
70
+ price = product_obj .browse (
71
+ self .cr , self .uid , [product .id ], context = context ).price
72
+ return price
69
73
70
74
def get_products (self , category_ids , context = None ):
71
75
if not isinstance (category_ids , list ):
@@ -75,13 +79,17 @@ def get_products(self, category_ids, context=None):
75
79
context = {}
76
80
order = context .get ('products_order' , '' )
77
81
only_with_stock = context .get ('only_with_stock' , False )
78
-
79
- domain = [('categ_id' , 'in' , category_ids )]
82
+ category_type = context .get ('category_type' , False )
83
+ if category_type == 'public_category' :
84
+ domain = [('public_categ_ids' , 'in' , category_ids )]
85
+ else :
86
+ domain = [('categ_id' , 'in' , category_ids )]
80
87
if only_with_stock :
81
- domain .append (('qty_available' ,'>' ,0 ))
88
+ domain .append (('qty_available' , '>' , 0 ))
82
89
83
- product_ids = self .pool .get ('product.product' ).search (self .cr , self .uid , domain , order = order , context = context )
90
+ product_ids = self .pool [self .product_type ].search (
91
+ self .cr , self .uid , domain , order = order , context = context )
84
92
85
- products = self .pool . get ( 'product.product' ) .browse (
93
+ products = self .pool [ self . product_type ] .browse (
86
94
self .cr , self .uid , product_ids , context = context )
87
95
return products
0 commit comments