[IMP] website_sale: use product.template insead of product.product

bzr revid: chm@openerp.com-20130820141203-vkg93z9odh0rlf4d
This commit is contained in:
Christophe Matthieu 2013-08-20 16:12:03 +02:00
parent c48ceabbca
commit 05bb4f2dca
6 changed files with 71 additions and 64 deletions

View File

@ -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."),

View File

@ -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/<product_id>/'], 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)

View File

@ -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
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_product_product_public product.product.public product.model_product_product base.group_public 1 0 0 0
3 access_product_template_public product.template.public product.model_product_template base.group_public 1 0 0 0
4 access_point_of_sale_category_public point_of_sale.category.public point_of_sale.model_pos_category base.group_public 1 0 0 0

View File

@ -1,6 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="product_template_public" model="ir.rule">
<field name="name">product: Public product template</field>
<field name="model_id" ref="product.model_product_template"/>
<field name="domain_force">[('website_published', '=', True), ("sale_ok", "=", True)]</field>
<field name="groups" eval="[(4, ref('base.group_public'))]"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/>
<field name="perm_unlink" eval="False"/>
</record>
<record id="product_product_public" model="ir.rule">
<field name="name">product: Public product</field>
<field name="model_id" ref="product.model_product_product"/>

View File

@ -66,7 +66,7 @@
<xpath expr="//div[@id='shop_content']" position="before">
<div class="span4">
<ul class="nav nav-list">
<li t-att-class=" '' if current_category else 'active' " class='active'><a href="/shop/">All Products</a></li>
<li t-att-class=" '' if category_id else 'active' " class='active'><a href="/shop/">All Products</a></li>
<t t-foreach="categories" t-as="category">
<t t-call="website_sale.categories_recursive"/>
</t>
@ -81,7 +81,7 @@
<!-- List of categories -->
<template id="categories_recursive">
<li t-att-class="category.id == current_category and 'active' or ''">
<li t-att-class="category.id == category_id and 'active' or ''">
<a t-attf-href="/shop/category/#{ category.id }/" t-field="category.name"></a>
<ul t-if="category.child_id" class="nav nav-list">
<t t-foreach="category.child_id" t-as="category">
@ -102,17 +102,16 @@
<t t-call="website.pager" >
<t t-set="classname">pull-left</t>
</t>
<form action="/shop/" method="get" class="navbar-search pull-right pagination">
<form t-attf-action="/shop/#{ category_id and ('category/%s/' % category_id) or ''}" method="get" class="navbar-search pull-right pagination">
<input type="text" name="search" class="search-query span2" placeholder="Search" t-att-value="search or '' or ''"/>
</form>
</div>
</div>
<div class='row grid grid-align-top'>
<div t-foreach="products" t-as="product" class="span2 mb16 thumbnail text-center">
<a t-attf-href="/shop/product/#{ product.id }/ ">
<t t-foreach="products" t-as="product">
<div t-attf-class="span2 mb16 thumbnail text-center #{not product.website_published and 'alert' or ''}">
<a t-attf-href="/shop/product/#{ product.id }/?#{ search and ('search=%s' % search) or ''}#{ category_id and ('&amp;category_id=%s' % category_id) or ''}">
<h5 t-field="product.name"> </h5>
</a>
<a t-attf-href="/shop/product/#{ product.id }/">
<img class="img-rounded" t-att-src="product.img('image_small')"/>
</a>
<div>
@ -123,6 +122,7 @@
</div>
</div>
</div>
</t>
</div>
<div class="text-center">
<t t-call="website.pager" />
@ -137,16 +137,22 @@
<t t-call="website_sale.layout">
<t t-set="title">Product</t>
<t t-set="shop_content">
<div class='navbar navbar-inverse'>
<div class='navbar-inner'>
<form t-attf-action="/shop/#{ category_id and ('category/%s/' % category_id) or ''}" method="get" class="navbar-search pull-right pagination">
<input type="text" name="search" class="search-query span2" placeholder="Search" t-att-value="search or '' or ''"/>
</form>
</div>
</div>
<div id="product_detail">
<t t-call="website.publish"><t t-set="object" t-value="product"/></t>
<h2 t-field="product.name"></h2>
<a t-if="not product_variants" t-attf-href="/shop/add_cart/#{ product.id }/" class="btn btn-small btn-success pull-right">Add to cart</a>
<form t-if="product_variants" action="/shop/add_cart/" class="pull-right">
<select name="product_id">
<t t-foreach="product_variants" t-as="product">
<option t-att-value="product.id"><t t-esc="product.variants"/></option>
</t>
</select><br/>
<a t-if="not product.product_variant_ids" t-attf-href="/shop/add_cart/#{ product.id }/" class="btn btn-small btn-success pull-right">Add to cart</a>
<form t-if="len(product.product_variant_ids) > 1" action="/shop/add_cart/" class="pull-right">
<label class="radio" t-foreach="product.product_variant_ids" t-as="product">
<input type="radio" name="product_id" t-att-value="product.id" t-att-checked="product == product.product_variant_ids[0] or None"/>
<t t-esc="product.variants or ''">Standard</t>
</label><br/>
<button class="btn btn-small btn-success">Add to cart</button>
</form>
<img class="media-object" t-att-src="product.img('image')"/>

View File

@ -29,7 +29,7 @@ class product_pricelist(osv.osv):
}
class product_product(osv.osv):
_inherit = "product.product"
_inherit = "product.template"
_columns = {
'website_published': fields.boolean('Available in the website'),
'description_website': fields.html('Description for the website'),