Skip to content

Commit

Permalink
Merge pull request odoo#34 from ingadhoc/fix_produc_catalog
Browse files Browse the repository at this point in the history
IMP report by price_template and category Public
  • Loading branch information
jjscarafia committed Apr 7, 2015
2 parents 75d8fad + cb5e35a commit 43288df
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 29 deletions.
31 changes: 19 additions & 12 deletions product_catalog_aeroo_report/product_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,50 @@ class product_catalog_report(models.Model):
name = fields.Char(
'Name',
required=True
)
)
products_order = fields.Char(
'Products Order Sintax',
help='for eg. name desc', required=False
)
)
categories_order = fields.Char(
'Categories Order Sintax',
help='for eg. name desc',
)
)
include_sub_categories = fields.Boolean(
'Include Subcategories?',
)
)
only_with_stock = fields.Boolean(
'Only With Stock Products?',
)
)
product_type = fields.Selection(
[('product.template', 'Product Template'),
('product.product', 'Product')], 'Product Type',
required=True
)
report_xml_id = fields.Many2one(
'ir.actions.report.xml',
'Report XML',
domain=[('report_type','=','aeroo'),('model','=','product.product')],
context={'default_report_type': 'aeroo', 'default_model': 'product.product'},
domain=[('report_type', '=', 'aeroo'),
('model', '=', 'product.product')],
context={'default_report_type': 'aeroo',
'default_model': 'product.product'},
required=True
)
)
category_ids = fields.Many2many(
'product.category',
'product_catalog_report_categories',
'product_catalog_report_id',
'category_id',
'Product Categories',
required=True
)
)
pricelist_ids = fields.Many2many(
'product.pricelist',
'product_catalog_report_pricelists',
'product_catalog_report_id',
'pricelist_id',
'Pricelist',
)
)

@api.multi
def generate_report(self):
Expand All @@ -54,13 +61,13 @@ def generate_report(self):
self.ensure_one()

context = self._context.copy()

category_ids = self.category_ids.ids
if self.include_sub_categories:
category_ids = self.env['product.category'].search(
[('id', 'child_of', category_ids)]).ids
[('id', 'child_of', category_ids)]).ids

context['category_ids'] = category_ids
context['product_type'] = self.product_type
context['pricelist_ids'] = self.pricelist_ids.ids
context['products_order'] = self.products_order
context['categories_order'] = self.categories_order
Expand Down
1 change: 1 addition & 0 deletions product_catalog_aeroo_report/product_catalog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<field name="products_order"/>
<field name="only_with_stock"/>
<field name="include_sub_categories"/>
<field name="product_type"/>
</group>
<group col="1" colspan="4">
<field name="category_ids"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,nico,nico,07.04.2015 13:08,file:///home/nico/.config/libreoffice/4;
42 changes: 25 additions & 17 deletions product_catalog_aeroo_report/report/product_catalog_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@

class Parser(report_sxw.rml_parse):


def __init__(self, cr, uid, name, context):
super(Parser, self).__init__(cr, uid, name, context)

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

self.product_type = context.get('product_type', 'product.product')
pricelist_ids = context.get('pricelist_ids', [])
pricelists = self.pool['product.pricelist'].browse(
cr, uid, pricelist_ids, context=context)
cr, uid, pricelist_ids, context=context)

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

# Get categories ordered
categories = self.pool['product.category']
category_type = context.get('category_type', False)
if category_type == 'public_category':
categories = self.pool['product.public.category']
else:
categories = self.pool['product.category']
category_ids = context.get('category_ids', [])
category_ids = categories.search(
cr, uid, [('id', 'in', category_ids)],
Expand All @@ -30,14 +34,13 @@ def __init__(self, cr, uid, name, context):
cr, uid, category_ids, context=context)

products = self.get_products(category_ids, context=context)

company_id = self.pool['res.users'].browse(
cr, uid, [uid])[0].company_id

self.localcontext.update({
'lang': lang,
'categories': categories,
'products': products,
'product_type': self.product_type,
'company_logo': company_id.logo,
'pricelists': pricelists,
'today': time.localtime(),
Expand All @@ -48,11 +51,13 @@ def __init__(self, cr, uid, name, context):
})

def field_value_get(self, product, field, context=None):
# 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"
# 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"
if not context:
context = {}

product_obj = self.pool.get('product.product')
product_obj = self.pool.get(self.product_type)
field_value = product_obj.read(
self.cr, self.uid, [product.id], [field], context=context)
return field_value[0].get(field, '')
Expand All @@ -61,11 +66,10 @@ def get_price(self, product, pricelist, context=None):
if not context:
context = {}
context['pricelist'] = pricelist.id

product_obj = self.pool.get('product.product')
price = product_obj._product_price(
self.cr, self.uid, [product.id], False, False, context=context)
return price.get(product.id, 0.0)
product_obj = self.pool[self.product_type]
price = product_obj.browse(
self.cr, self.uid, [product.id], context=context).price
return price

def get_products(self, category_ids, context=None):
if not isinstance(category_ids, list):
Expand All @@ -75,13 +79,17 @@ def get_products(self, category_ids, context=None):
context = {}
order = context.get('products_order', '')
only_with_stock = context.get('only_with_stock', False)

domain = [('categ_id', 'in', category_ids)]
category_type = context.get('category_type', False)
if category_type == 'public_category':
domain = [('public_categ_ids', 'in', category_ids)]
else:
domain = [('categ_id', 'in', category_ids)]
if only_with_stock:
domain.append(('qty_available','>',0))
domain.append(('qty_available', '>', 0))

product_ids = self.pool.get('product.product').search(self.cr, self.uid, domain, order=order, context=context)
product_ids = self.pool[self.product_type].search(
self.cr, self.uid, domain, order=order, context=context)

products = self.pool.get('product.product').browse(
products = self.pool[self.product_type].browse(
self.cr, self.uid, product_ids, context=context)
return products
Binary file modified product_catalog_aeroo_report/report/product_catalog_simple.odt
Binary file not shown.
3 changes: 3 additions & 0 deletions report_category_public/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

import product_catalog
30 changes: 30 additions & 0 deletions report_category_public/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
{
'name': 'Report Category Public',
'version': '1.0',
'category': 'Aeroo Reporting',
'sequence': 14,
'summary': '',
'description': """
Report Category Public
============================
""",
'author': 'ADHOC',
'website': 'www.adhoc.com.ar',
'images': [
],
'depends': [
'website_sale',
'product_catalog_aeroo_report',
],
'data': ['product_catalog.xml'
],
'demo': [
],
'test': [
],
'installable': True,
'auto_install': True,
'application': False,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
49 changes: 49 additions & 0 deletions report_category_public/product_catalog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
from openerp import fields, models, api


class product_catalog_report(models.Model):
_inherit = 'product.product_catalog_report'

category_type = fields.Selection(
[('public_category', 'Public Category'),
('accounting_category', 'Accounting Category')], 'Category Type',
required=True
)
public_category_ids = fields.Many2many(
'product.public.category',
'product_catalog_report_categories_public',
'product_catalog_report_id',
'category_id',
'Product Categories Public',
required=True
)

@api.multi
def generate_report(self):
""" Print the catalog
"""
self.ensure_one()

context = self._context.copy()
if self.category_type == 'public_category':
category_ids = self.public_category_ids.ids
if self.include_sub_categories:
category_ids = self.env['product.public.category'].search(
[('id', 'child_of', category_ids)]).ids
else:
category_ids = self.category_ids.ids
if self.include_sub_categories:
category_ids = self.env['product.category'].search(
[('id', 'child_of', category_ids)]).ids

context['category_ids'] = category_ids
context['category_type'] = self.category_type
context['product_type'] = self.product_type
context['pricelist_ids'] = self.pricelist_ids.ids
context['products_order'] = self.products_order
context['categories_order'] = self.categories_order
context['only_with_stock'] = self.only_with_stock

return self.env['report'].with_context(context).get_action(
self, self.report_xml_id.report_name)
19 changes: 19 additions & 0 deletions report_category_public/product_catalog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<openerp>
<data>
<record id="view_product_catalog_public_report_form" model="ir.ui.view">
<field name="name">Product Catalog Public Reports</field>
<field name="model">product.product_catalog_report</field>
<field name="inherit_id" ref="product_catalog_aeroo_report.view_product_catalog_report_form"/>
<field name="arch" type="xml">
<field name="product_type" position="after">
<field name="category_type"/>
</field>
<field name="category_ids" position="replace">
<field name="category_ids" attrs="{'invisible':[('category_type','=','public_category')]}"/>
<field name="public_category_ids" attrs="{'invisible':[('category_type','=','accounting_category')]}"/>
</field>
</field>
</record>
</data>
</openerp>

0 comments on commit 43288df

Please sign in to comment.