Skip to content

Commit 43288df

Browse files
committed
Merge pull request odoo#34 from ingadhoc/fix_produc_catalog
IMP report by price_template and category Public
2 parents 75d8fad + cb5e35a commit 43288df

9 files changed

+147
-29
lines changed

product_catalog_aeroo_report/product_catalog.py

+19-12
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,50 @@ class product_catalog_report(models.Model):
99
name = fields.Char(
1010
'Name',
1111
required=True
12-
)
12+
)
1313
products_order = fields.Char(
1414
'Products Order Sintax',
1515
help='for eg. name desc', required=False
16-
)
16+
)
1717
categories_order = fields.Char(
1818
'Categories Order Sintax',
1919
help='for eg. name desc',
20-
)
20+
)
2121
include_sub_categories = fields.Boolean(
2222
'Include Subcategories?',
23-
)
23+
)
2424
only_with_stock = fields.Boolean(
2525
'Only With Stock Products?',
26-
)
26+
)
27+
product_type = fields.Selection(
28+
[('product.template', 'Product Template'),
29+
('product.product', 'Product')], 'Product Type',
30+
required=True
31+
)
2732
report_xml_id = fields.Many2one(
2833
'ir.actions.report.xml',
2934
'Report XML',
30-
domain=[('report_type','=','aeroo'),('model','=','product.product')],
31-
context={'default_report_type': 'aeroo', 'default_model': 'product.product'},
35+
domain=[('report_type', '=', 'aeroo'),
36+
('model', '=', 'product.product')],
37+
context={'default_report_type': 'aeroo',
38+
'default_model': 'product.product'},
3239
required=True
33-
)
40+
)
3441
category_ids = fields.Many2many(
3542
'product.category',
3643
'product_catalog_report_categories',
3744
'product_catalog_report_id',
3845
'category_id',
3946
'Product Categories',
4047
required=True
41-
)
48+
)
4249
pricelist_ids = fields.Many2many(
4350
'product.pricelist',
4451
'product_catalog_report_pricelists',
4552
'product_catalog_report_id',
4653
'pricelist_id',
4754
'Pricelist',
48-
)
55+
)
4956

5057
@api.multi
5158
def generate_report(self):
@@ -54,13 +61,13 @@ def generate_report(self):
5461
self.ensure_one()
5562

5663
context = self._context.copy()
57-
5864
category_ids = self.category_ids.ids
5965
if self.include_sub_categories:
6066
category_ids = self.env['product.category'].search(
61-
[('id', 'child_of', category_ids)]).ids
67+
[('id', 'child_of', category_ids)]).ids
6268

6369
context['category_ids'] = category_ids
70+
context['product_type'] = self.product_type
6471
context['pricelist_ids'] = self.pricelist_ids.ids
6572
context['products_order'] = self.products_order
6673
context['categories_order'] = self.categories_order

product_catalog_aeroo_report/product_catalog.xml

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<field name="products_order"/>
3737
<field name="only_with_stock"/>
3838
<field name="include_sub_categories"/>
39+
<field name="product_type"/>
3940
</group>
4041
<group col="1" colspan="4">
4142
<field name="category_ids"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
,nico,nico,07.04.2015 13:08,file:///home/nico/.config/libreoffice/4;

product_catalog_aeroo_report/report/product_catalog_parser.py

+25-17
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,24 @@
88

99
class Parser(report_sxw.rml_parse):
1010

11-
1211
def __init__(self, cr, uid, name, context):
1312
super(Parser, self).__init__(cr, uid, name, context)
1413

1514
lang = context.get('lang', 'es_ES')
1615

16+
self.product_type = context.get('product_type', 'product.product')
1717
pricelist_ids = context.get('pricelist_ids', [])
1818
pricelists = self.pool['product.pricelist'].browse(
19-
cr, uid, pricelist_ids, context=context)
19+
cr, uid, pricelist_ids, context=context)
2020

2121
categories_order = context.get('categories_order', '')
2222

2323
# 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']
2529
category_ids = context.get('category_ids', [])
2630
category_ids = categories.search(
2731
cr, uid, [('id', 'in', category_ids)],
@@ -30,14 +34,13 @@ def __init__(self, cr, uid, name, context):
3034
cr, uid, category_ids, context=context)
3135

3236
products = self.get_products(category_ids, context=context)
33-
3437
company_id = self.pool['res.users'].browse(
3538
cr, uid, [uid])[0].company_id
36-
3739
self.localcontext.update({
3840
'lang': lang,
3941
'categories': categories,
4042
'products': products,
43+
'product_type': self.product_type,
4144
'company_logo': company_id.logo,
4245
'pricelists': pricelists,
4346
'today': time.localtime(),
@@ -48,11 +51,13 @@ def __init__(self, cr, uid, name, context):
4851
})
4952

5053
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"
5257
if not context:
5358
context = {}
5459

55-
product_obj = self.pool.get('product.product')
60+
product_obj = self.pool.get(self.product_type)
5661
field_value = product_obj.read(
5762
self.cr, self.uid, [product.id], [field], context=context)
5863
return field_value[0].get(field, '')
@@ -61,11 +66,10 @@ def get_price(self, product, pricelist, context=None):
6166
if not context:
6267
context = {}
6368
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
6973

7074
def get_products(self, category_ids, context=None):
7175
if not isinstance(category_ids, list):
@@ -75,13 +79,17 @@ def get_products(self, category_ids, context=None):
7579
context = {}
7680
order = context.get('products_order', '')
7781
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)]
8087
if only_with_stock:
81-
domain.append(('qty_available','>',0))
88+
domain.append(('qty_available', '>', 0))
8289

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)
8492

85-
products = self.pool.get('product.product').browse(
93+
products = self.pool[self.product_type].browse(
8694
self.cr, self.uid, product_ids, context=context)
8795
return products
Binary file not shown.

report_category_public/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import product_catalog

report_category_public/__openerp__.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -*- coding: utf-8 -*-
2+
{
3+
'name': 'Report Category Public',
4+
'version': '1.0',
5+
'category': 'Aeroo Reporting',
6+
'sequence': 14,
7+
'summary': '',
8+
'description': """
9+
Report Category Public
10+
============================
11+
""",
12+
'author': 'ADHOC',
13+
'website': 'www.adhoc.com.ar',
14+
'images': [
15+
],
16+
'depends': [
17+
'website_sale',
18+
'product_catalog_aeroo_report',
19+
],
20+
'data': ['product_catalog.xml'
21+
],
22+
'demo': [
23+
],
24+
'test': [
25+
],
26+
'installable': True,
27+
'auto_install': True,
28+
'application': False,
29+
}
30+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# -*- coding: utf-8 -*-
2+
from openerp import fields, models, api
3+
4+
5+
class product_catalog_report(models.Model):
6+
_inherit = 'product.product_catalog_report'
7+
8+
category_type = fields.Selection(
9+
[('public_category', 'Public Category'),
10+
('accounting_category', 'Accounting Category')], 'Category Type',
11+
required=True
12+
)
13+
public_category_ids = fields.Many2many(
14+
'product.public.category',
15+
'product_catalog_report_categories_public',
16+
'product_catalog_report_id',
17+
'category_id',
18+
'Product Categories Public',
19+
required=True
20+
)
21+
22+
@api.multi
23+
def generate_report(self):
24+
""" Print the catalog
25+
"""
26+
self.ensure_one()
27+
28+
context = self._context.copy()
29+
if self.category_type == 'public_category':
30+
category_ids = self.public_category_ids.ids
31+
if self.include_sub_categories:
32+
category_ids = self.env['product.public.category'].search(
33+
[('id', 'child_of', category_ids)]).ids
34+
else:
35+
category_ids = self.category_ids.ids
36+
if self.include_sub_categories:
37+
category_ids = self.env['product.category'].search(
38+
[('id', 'child_of', category_ids)]).ids
39+
40+
context['category_ids'] = category_ids
41+
context['category_type'] = self.category_type
42+
context['product_type'] = self.product_type
43+
context['pricelist_ids'] = self.pricelist_ids.ids
44+
context['products_order'] = self.products_order
45+
context['categories_order'] = self.categories_order
46+
context['only_with_stock'] = self.only_with_stock
47+
48+
return self.env['report'].with_context(context).get_action(
49+
self, self.report_xml_id.report_name)
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0"?>
2+
<openerp>
3+
<data>
4+
<record id="view_product_catalog_public_report_form" model="ir.ui.view">
5+
<field name="name">Product Catalog Public Reports</field>
6+
<field name="model">product.product_catalog_report</field>
7+
<field name="inherit_id" ref="product_catalog_aeroo_report.view_product_catalog_report_form"/>
8+
<field name="arch" type="xml">
9+
<field name="product_type" position="after">
10+
<field name="category_type"/>
11+
</field>
12+
<field name="category_ids" position="replace">
13+
<field name="category_ids" attrs="{'invisible':[('category_type','=','public_category')]}"/>
14+
<field name="public_category_ids" attrs="{'invisible':[('category_type','=','accounting_category')]}"/>
15+
</field>
16+
</field>
17+
</record>
18+
</data>
19+
</openerp>

0 commit comments

Comments
 (0)