From 05bb4f2dcaa1127c00a776a7e684aff75b806f45 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 20 Aug 2013 16:12:03 +0200 Subject: [PATCH] [IMP] website_sale: use product.template insead of product.product bzr revid: chm@openerp.com-20130820141203-vkg93z9odh0rlf4d --- addons/product/product.py | 58 +++++++++---------- addons/website_sale/controllers/main.py | 30 ++++------ .../website_sale/security/ir.model.access.csv | 1 + addons/website_sale/security/website_sale.xml | 10 ++++ addons/website_sale/views/website_sale.xml | 34 ++++++----- addons/website_sale/website_sale.py | 2 +- 6 files changed, 71 insertions(+), 64 deletions(-) diff --git a/addons/product/product.py b/addons/product/product.py index c0a007789fd..8c74217efac 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -289,6 +289,15 @@ class product_template(osv.osv): _name = "product.template" _description = "Product Template" + def _get_image(self, cr, uid, ids, name, args, context=None): + result = dict.fromkeys(ids, False) + for obj in self.browse(cr, uid, ids, context=context): + result[obj.id] = tools.image_get_resized_images(obj.image, avoid_resize_medium=True) + return result + + def _set_image(self, cr, uid, id, name, value, args, context=None): + return self.write(cr, uid, [id], {'image': tools.image_resize_image_big(value)}, context=context) + _columns = { 'name': fields.char('Name', size=128, required=True, translate=True, select=True), 'product_manager': fields.many2one('res.users','Product Manager'), @@ -328,7 +337,26 @@ class product_template(osv.osv): 'mes_type': fields.selection((('fixed', 'Fixed'), ('variable', 'Variable')), 'Measure Type'), 'seller_ids': fields.one2many('product.supplierinfo', 'product_id', 'Supplier'), 'company_id': fields.many2one('res.company', 'Company', select=1), - 'product_ids': fields.one2many('product.product', 'product_tmpl_id', 'Product Variants'), + # image: all image fields are base64 encoded and PIL-supported + 'image': fields.binary("Image", + help="This field holds the image used as image for the product, limited to 1024x1024px."), + 'image_medium': fields.function(_get_image, fnct_inv=_set_image, + string="Medium-sized image", type="binary", multi="_get_image", + store={ + 'product.product': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), + }, + help="Medium-sized image of the product. It is automatically "\ + "resized as a 128x128px image, with aspect ratio preserved, "\ + "only when the image exceeds one of those sizes. Use this field in form views or some kanban views."), + 'image_small': fields.function(_get_image, fnct_inv=_set_image, + string="Small-sized image", type="binary", multi="_get_image", + store={ + 'product.product': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), + }, + help="Small-sized image of the product. It is automatically "\ + "resized as a 64x64px image, with aspect ratio preserved. "\ + "Use this field anywhere a small image is required."), + 'product_variant_ids': fields.one2many('product.product', 'product_tmpl_id', 'Product Variants'), } def _get_uom_id(self, cr, uid, *args): @@ -515,15 +543,6 @@ class product_product(osv.osv): return result - def _get_image(self, cr, uid, ids, name, args, context=None): - result = dict.fromkeys(ids, False) - for obj in self.browse(cr, uid, ids, context=context): - result[obj.id] = tools.image_get_resized_images(obj.image, avoid_resize_medium=True) - return result - - def _set_image(self, cr, uid, id, name, value, args, context=None): - return self.write(cr, uid, [id], {'image': tools.image_resize_image_big(value)}, context=context) - def _get_name_template_ids(self, cr, uid, ids, context=None): result = set() template_ids = self.pool.get('product.product').search(cr, uid, [('product_tmpl_id', 'in', ids)]) @@ -568,25 +587,6 @@ class product_product(osv.osv): }, select=True), 'color': fields.integer('Color Index'), - # image: all image fields are base64 encoded and PIL-supported - 'image': fields.binary("Image", - help="This field holds the image used as image for the product, limited to 1024x1024px."), - 'image_medium': fields.function(_get_image, fnct_inv=_set_image, - string="Medium-sized image", type="binary", multi="_get_image", - store={ - 'product.product': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), - }, - help="Medium-sized image of the product. It is automatically "\ - "resized as a 128x128px image, with aspect ratio preserved, "\ - "only when the image exceeds one of those sizes. Use this field in form views or some kanban views."), - 'image_small': fields.function(_get_image, fnct_inv=_set_image, - string="Small-sized image", type="binary", multi="_get_image", - store={ - 'product.product': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10), - }, - help="Small-sized image of the product. It is automatically "\ - "resized as a 64x64px image, with aspect ratio preserved. "\ - "Use this field anywhere a small image is required."), 'seller_info_id': fields.function(_calc_seller, type='many2one', relation="product.supplierinfo", string="Supplier Info", multi="seller_info"), 'seller_delay': fields.function(_calc_seller, type='integer', string='Supplier Lead Time', multi="seller_info", help="This is the average delay in days between the purchase order confirmation and the reception of goods for this product and for the default supplier. It is used by the scheduler to order requests based on reordering delays."), 'seller_qty': fields.function(_calc_seller, type='float', string='Supplier Quantity', multi="seller_info", help="This is minimum quantity to purchase from Main Supplier."), diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 4854da64aa5..0aae53a80fa 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -55,7 +55,7 @@ class Ecommerce(http.Controller): def category(self, cat_id=0, page=0, **post): website = request.registry['website'] - product_obj = request.registry.get('product.product') + product_obj = request.registry.get('product.template') domain = [("sale_ok", "=", True)] if SUPERUSER_ID != request.uid: @@ -66,49 +66,39 @@ class Ecommerce(http.Controller): ('name', 'ilike', "%%%s%%" % post.get("search")), ('description', 'ilike', "%%%s%%" % post.get("search")), ('description_website', 'ilike', "%%%s%%" % post.get("search")), - ('pos_categ_id.name', 'ilike', "%%%s%%" % post.get("search"))] + ('product_variant_ids.pos_categ_id.name', 'ilike', "%%%s%%" % post.get("search"))] if cat_id: cat_id = int(cat_id) - domain += [('pos_categ_id.id', 'child_of', cat_id)] + domain + domain += [('product_variant_ids.pos_categ_id.id', 'child_of', cat_id)] + domain step = 20 product_count = len(product_obj.search(request.cr, request.uid, domain)) pager = website.pager(url="/shop/category/%s/" % cat_id, total=product_count, page=page, step=step, scope=7, url_args=post) - product_ids = product_obj.search(request.cr, request.uid, domain, limit=step, offset=pager['offset']) - - products = product_obj.browse(request.cr, request.uid, product_ids) - tmpl_ids = [] - product_tmpl_ids = [] - for product in products: - if product.product_tmpl_id.id not in tmpl_ids: - tmpl_ids.append(product.product_tmpl_id.id) - product_tmpl_ids.append(product) + product_ids = product_obj.search(request.cr, request.uid, domain, limit=step, offset=pager['offset'], order="website_published,name") values = website.get_rendering_context({ 'categories': self.get_categories(), - 'current_category': cat_id, - 'products': product_tmpl_ids, + 'category_id': cat_id, + 'products': product_obj.browse(request.cr, request.uid, product_ids), 'search': post.get("search"), 'pager': pager, }) return website.render("website_sale.products", values) @http.route(['/shop/product//'], type='http', auth="public") - def product(self, cat_id=0, product_id=0): + def product(self, cat_id=0, product_id=0, **post): website = request.registry['website'] - order = get_current_order() product_id = product_id and int(product_id) or 0 - product_obj = request.registry.get('product.product') - - line = [line for line in order.order_line if line.product_id.id == product_id] + product_obj = request.registry.get('product.template') product = product_obj.browse(request.cr, request.uid, product_id) values = website.get_rendering_context({ + 'category_id': post.get('category_id') and int(post.get('category_id')) or None, + 'search': post.get("search"), 'categories': self.get_categories(), 'product': product, - 'product_variants': product.product_tmpl_id.product_ids, }) return website.render("website_sale.product", values) diff --git a/addons/website_sale/security/ir.model.access.csv b/addons/website_sale/security/ir.model.access.csv index 8d41ba779d4..1edc0bd5c8f 100644 --- a/addons/website_sale/security/ir.model.access.csv +++ b/addons/website_sale/security/ir.model.access.csv @@ -1,3 +1,4 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_product_product_public,product.product.public,product.model_product_product,base.group_public,1,0,0,0 +access_product_template_public,product.template.public,product.model_product_template,base.group_public,1,0,0,0 access_point_of_sale_category_public,point_of_sale.category.public,point_of_sale.model_pos_category,base.group_public,1,0,0,0 \ No newline at end of file diff --git a/addons/website_sale/security/website_sale.xml b/addons/website_sale/security/website_sale.xml index b37578d41e0..3b3489ac77c 100644 --- a/addons/website_sale/security/website_sale.xml +++ b/addons/website_sale/security/website_sale.xml @@ -1,6 +1,16 @@ + + product: Public product template + + [('website_published', '=', True), ("sale_ok", "=", True)] + + + + + + product: Public product diff --git a/addons/website_sale/views/website_sale.xml b/addons/website_sale/views/website_sale.xml index b03c425c22c..cf71349a75c 100644 --- a/addons/website_sale/views/website_sale.xml +++ b/addons/website_sale/views/website_sale.xml @@ -66,7 +66,7 @@