[ADD]:Recommendation of related product

[IMP]: demo data

bzr revid: aja@tinyerp.com-20131210104442-1yqigjiwszjowogp
This commit is contained in:
ajay javiya (OpenERP) 2013-12-10 16:14:42 +05:30
parent 8f4617c335
commit 060fe3329c
6 changed files with 163 additions and 174 deletions

View File

@ -346,7 +346,7 @@
<t t-foreach="product.recommended_products()" t-as="product">
<div class='col-md-2 thumbnail' style='width: 170px; margin-right: 16px;'>
<div class='mt16 text-center'>
<span t-field="product.image_small"/>
<span t-field="product.image_small" t-field-options='{"widget": "image", "class": "img-rounded"}'/>
<h5>
<a t-href="/shop/product/#{ slug(product) }/"
style="display: block">

View File

@ -55,15 +55,18 @@ class sale_quote(http.Controller):
return request.redirect("/quote/%s" % token)
@website.route(['/quote/update_line'], type='json', auth="public")
def update(self, line_id=None, qty=None, remove=False,unlink=False,**post):
def update(self, line_id=None, remove=False, unlink=False, order_id=None, **post):
if unlink:
request.registry.get('sale.order.line').unlink(request.cr, SUPERUSER_ID,[int(line_id)], context=request.context)
return
else:
val = self._update_order_line(line_id=int(line_id), number=(remove and -1 or 1), qty=int(qty))
# order = request.registry['website'].get_current_order(request.cr, request.uid, context=request.context)
return {}
val = self._update_order_line(line_id=int(line_id), number=(remove and -1 or 1))
order = request.registry.get('sale.order').browse(request.cr, SUPERUSER_ID, order_id)
return [val , order.amount_total]
def _update_order_line(self,line_id, number,qty):
qty += number
request.registry.get('sale.order.line').write(request.cr, SUPERUSER_ID, [int(line_id)], {'product_uom_qty':(qty)}, context=request.context)
return qty
def _update_order_line(self,line_id, number):
order_line_obj = request.registry.get('sale.order.line')
order_line_val = order_line_obj.read(request.cr, SUPERUSER_ID, [int(line_id)], [], context=request.context)[0]
quantity = order_line_val['product_uom_qty'] + number
order_line_obj.write(request.cr, SUPERUSER_ID, [int(line_id)], {'product_uom_qty':(quantity)}, context=request.context)
return quantity

View File

@ -85,3 +85,25 @@ class sale_order(osv.osv):
def onchange_template_id(self, cr, uid,ids, template_id, context=None):
data = self._get_sale_order_line(cr, uid, template_id, context)
return {'value':data}
def recommended_products(self, cr, uid, ids,context=None):
order_line = self.browse(cr, uid, ids[0], context=context).order_line
product_pool = self.pool.get('product.product')
product_ids = []
for line in order_line:
query = """
SELECT sol.product_id
FROM sale_order_line as my
LEFT JOIN sale_order_line as sol
ON sol.order_id = my.order_id
WHERE my.product_id in (%s)
AND sol.product_id not in (%s)
GROUP BY sol.product_id
ORDER BY COUNT(sol.order_id) DESC
LIMIT 10
"""
cr.execute(query, (line.product_id.id, line.product_id.id))
for p in cr.fetchall():
product_ids.append(p[0])
product_ids = product_pool.search(cr, uid, [("id", "in", product_ids)], limit=3)
return product_pool.browse(cr, uid, product_ids)

View File

@ -1,7 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="product_template_quote_1" model="product.template">
<field name="name">Functional Training</field>
<field name="categ_id" ref="product.product_category_5"/>
<field name="public_categ_id" ref="product.Computer_all_in_one"/>
<field name="standard_price">50000.0</field>
<field name="list_price">750000.0</field>
<field name="type">service</field>
<field name="uom_id" ref="product.product_uom_unit"/>
<field name="uom_po_id" ref="product.product_uom_unit"/>
<field name="description_sale">Learn directly from our team and network of OpenERP experts. Choose from the available training sessions for a better functional understanding of OpenERP</field>
</record>
<record id="product_product_quote_1" model="product.product">
<field name="product_tmpl_id" ref="product_template_quote_1"/>
<field name="default_code">QF11</field>
</record>
<record id="product_template_quote_2" model="product.template">
<field name="name">Technical Training</field>
<field name="categ_id" ref="product.product_category_5"/>
<field name="public_categ_id" ref="product.Computer_all_in_one"/>
<field name="standard_price">50000.0</field>
<field name="list_price">0.0</field>
<field name="type">service</field>
<field name="uom_id" ref="product.product_uom_unit"/>
<field name="uom_po_id" ref="product.product_uom_unit"/>
<field name="description_sale">Learn directly from our team and network of OpenERP experts. Choose from the available training sessions for a better technical understanding of OpenERP</field>
</record>
<record id="product_product_quote_2" model="product.product">
<field name="product_tmpl_id" ref="product_template_quote_2"/>
<field name="default_code">QF12</field>
</record>
<record id="website_sale_order_1" model="sale.order">
<field name="partner_id" ref="base.res_partner_2"/>
<field name="partner_invoice_id" ref="base.res_partner_2"/>
@ -37,7 +67,18 @@
<div class="panel-body">
<h4><small>Have strong value added services as you can rely on 3000 existing modules to deliver what the customer needs in a short period of time. Grow with your existing customer base by continuously proposing new modules.</small></h4>
</div>
</div>
</div><record model="ir.ui.view" id="view_model_name_form">
<field name="name">model.name.form</field>
<field name="model">model.name</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Untitled">
<group col="6" colspan="4">
</group>
</form>
</field>
</record>
</div>
<div class="col-md-4">
<div class="panel panel-success">
@ -251,49 +292,42 @@
<record id="website_sale_order_line_1" model="sale.order.line">
<field name="order_id" ref="website_sale_order_1"/>
<field name="name">Gold Partner</field>
<field name="product_id" ref="product.product_product_4"/>
<field name="product_id" ref="product_product_quote_1"/>
<field name="product_uom_qty">1</field>
<field name="product_uos_qty">1</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">12950.00</field>
<field name="website_description" type="html">
<section data-snippet-id="text-image" class="mt16 mb16 oe_dark">
<div class="container">
<div class="row">
<div class="col-md-5 col-md-offset-1 mt64">
<h3>Why you'll love an iPad.</h3>
<p>
Right from the start, theres a lot to love about
iPad. Its simple yet powerful. Thin and light yet
full-featured. It can do just about everything and
be just about anything.
</p><p>
And because its so easy to use, its easy to love.
</p>
<section data-snippet-id="text-image" class="tab-pane oe_section jumbotron">
<div class="container panel panel-default tab-pane active oe_section">
<div class="row panel-body">
<div class="text-center">
<h2><strong>Online Training + Certification</strong></h2>
<p><small>These courses feature the same high quality course content found in our traditional classroom trainings, supplemented with modular sessions and cloud-based labs. Many of our online learning courses also include dozens of recorded webinars and live sessions by our senior instructors. At the end of the training, you can pass the OpenERP Certification exam in one of the 5000+ Pearson VUE test centers worldwide.</small></p>
</div>
<div class="col-md-5 mt16 mb16">
<img class="img img-responsive" src="/website_sale/static/src/img/ipad_why.png"/>
<div class="col-md-offset-1">
<p><strong>Your advantages</strong></p>
<ul>
<li>Modular approach applied to the learning method</li>
<li>New interactive learning experience</li>
<li>Lower training budget for the same quality courses</li>
<li>Better comfort to facilitate your learning process</li>
</ul>
</div>
</div>
</div>
</section>
<section data-snippet-id="image-text" class="mt16">
<div class="container">
<div class="row">
<div class="col-md-5 col-md-offset-1">
<img class="img img-responsive" src="/website_sale/static/src/img/ipad_experience.png"/>
</div>
<div class="col-md-6 mt64">
<h3>The full iPad experience.</h3>
<h4 class="small">There is less of it, but no less to it.</h4>
<p>
Everything you love about iPad — the beautiful
screen, fast and fluid performance, FaceTime and
iSight cameras, thousands of amazing apps, 10-hour
battery life* — is everything youll love about
iPad mini, too. And you can hold it in one hand.
</p>
</div>
<div class="col-xs-12 col-md-12 text-center">
<h2><strong>Structure of the Training</strong></h2>
</div>
<div class="col-md-5 col-md-offset-1 mt32 mb16">
<img class="img img-responsive" src="https://www.openerp.com/saas_master/static/site_new/img/layout/online_training.png"/>
</div>
<div class="col-md-5">
<p><strong>There are three components to the training</strong></p>
<ul>
<li>Videos with detailed demos</li>
<li>Hands-on exercises and their solutions</li>
<li>Live Q&amp;A sessions with a trainer</li>
</ul>
</div>
</div>
</section>
@ -303,107 +337,38 @@
<record id="website_sale_order_line_2" model="sale.order.line">
<field name="order_id" ref="website_sale_order_1"/>
<field name="name">Functional Training</field>
<field name="product_id" ref="product.product_product_5"/>
<field name="product_id" ref="product_product_quote_2"/>
<field name="product_uom_qty">1</field>
<field name="product_uos_qty">1</field>
<field name="product_uom" ref="product.product_uom_unit"/>
<field name="price_unit">00.00</field>
<field name="website_description" type="html">
<section data-snippet-id="text-image" class="mt16 mb16">
<div class="container">
<div class="row">
<div class="col-md-5 col-md-offset-1 mt32">
<h3>Bose Mini Bluetooth Speaker.</h3>
<p>
The Bose® SoundLink® mini is Bose's smallest portable Bluetooth speaker. Its ultra-compact size fits in the
palm of your hand, yet gives you full, natural sound wirelessly from your iPhone, iPad, or iPod. Grab it and go
full-featured. It can do just about everything and
experience music just about anywhere.
</p>
<div class="panel panel-default mt48" data-snippet-id="panel">
<div class="panel-heading">
<h3 class="panel-title">Characteristics</h3>
</div>
<div class="panel-body">
<ul>
<li>Sleek, compact design</li>
<li>Efficient, high-quality audio</li>
<li>Remote control for power, volume, track seek</li>
<li>Auxiliary input for portable devices</li>
<li>Universal iPod docking station fits most iPod/iPhone models</li>
<li>Charges iPod/iPhone</li>
<li>Volume control on main system</li>
</ul>
</div>
</div>
</div>
<div class="col-md-4 mt16 mb16 col-md-offset1">
<img class="img img-responsive" src="/website_sale/static/src/img/play_where_you_play.jpg"/>
</div>
<section id="whatsuit" class="tab-pane active oe_section jumbotron">
<div class="container panel panel-default tab-pane active oe_section">
<div class="row panel-body">
<div class="text-center">
<h2><strong>Technical Training</strong></h2>
<p><small>This course is dedicated to partners, integrators and developers who need to have a grasp of the OpenERP development process. This course is for new developers or for IT professionals eager to learn more about the OpenERP's technical aspects.
This 5-day training takes place in the Headquarters of OpenERP, in Grand-Rosière (Belgium).</small></p>
</div>
</div>
</section>
<section data-snippet-id="text-image" class="mt16 mb16 oe_dark">
<div class="container">
<div class="row">
<div class="col-md-5 col-md-offset-1 mt16">
<h2>Plays where you play</h2>
<p>
The SoundLink® Mini speaker is small and light enough
to tuck into your bag. It weighs in at just 1.5 pounds.
Its low profile lets you place it almost anywhere and
provides a low center of gravity that makes it nearly
impossible to tip over.
</p>
<p>
The rechargeable lithium-ion battery delivers up to seven hours of playtime.
And at home, you can listen even longer—the charging cradle lets
you listen while it charges.
</p>
</div>
<div class="col-md-5 col-md-offset-1 mt32">
<img class="img img-responsive" src="/website_sale/static/src/img/more_features.png"/>
</div>
<div class="col-md-5 col-md-offset-4 text-center mb16 mt16">
<h3>Bluetooth connectivity</h3>
<p>
The speaker has a range of about 30 feet, so you can enjoy
the sound you want without wires. It pairs easily with your
smartphone, iPad® or other Bluetooth device.
And it remembers the most recent six devices you've used,
so reconnecting is even simpler.
</p>
</div>
</div>
<div class="col-xs-12 col-md-12 text-center">
<h2><strong>Objectives</strong></h2>
</div>
</section>
<section data-snippet-id="text-image" class="mt16 mb16">
<div class="container">
<div class="row">
<div class="col-md-5 col-md-offset-1 mt32 mb16">
<img class="img img-responsive" src="/website_sale/static/src/img/bluetooth.jpg"/>
</div>
<div class="col-md-5 mt16">
<h2>More features.</h2>
<p>
Charging cradle recharges the battery and serves as a convenient
home base for your speaker, and it lets you play while it charges.
</p>
<p>
Wall charger can be plugged into the cradle or directly into the speaker
</p>
<p>
Auxiliary port lets you connect other audio sources, like an MP3 player
</p>
<p>
USB port allows for software update to ensure ongoing Bluetooth device compatibility
</p>
<p>
Soft covers are available separately in blue, green or orange. Pick a color to match your style.
</p>
</div>
<div class="">
<p><strong>Having attended this course, participants should be able to</strong></p>
<ul>
<li>Videos with detailed demos</li>
<li>Hands-on exercises and their solutions</li>
<li>Live Q&amp;A sessions with a trainer</li>
</ul>
<p><strong>Structure of the Training</strong></p>
<h3><small>There are three components to the training:</small></h3>
<ul>
<li>Demo in class with the trainer</li>
<li>Hands-on exercises and their corresponding solutions</li>
<li>Q&amp;A sessions</li>
</ul>
</div>
</div>
</section>

View File

@ -3,19 +3,21 @@ $(document).ready(function () {
ev.preventDefault();
var $link = $(ev.currentTarget);
var href = $link.attr("href");
var qty = $link.attr("href").match(/qty=([0-9]+)/);
var order_id = $link.attr("href").match(/order_id=([0-9]+)/);
var line_id = href.match(/update_line\/([0-9]+)/);
console.log(line_id);
openerp.jsonRpc("/quote/update_line/", 'call', {
'line_id': line_id[1],
'qty': qty[1],
'order_id':parseInt(order_id[1]),
'remove': $link.is('[href*="remove"]'),
'unlink': $link.is('[href*="unlink"]'),
})
.then(function (data) {
location.reload();
// $link.parent('.input-group:first').find('.js_line_qty').val(data[0]);
// $('[data-oe-model="sale.order"][data-oe-field="amount_total"]').replaceWith(data[1]);
if(!data){
location.reload();
}
$link.parents('.input-group:first').find('.js_quantity').val(data[0]);
$('[data-id="total_amount"]>span').html(data[1]);
});
return false;
});

View File

@ -117,13 +117,13 @@
<td class="col-sm-1 col-md-1" style="text-align: center">
<div class="input-group">
<span class="input-group-addon">
<a t-href="./update_line/#{ line.id }/?qty=#{line.product_uom_qty}&amp;remove=True" class="mb8 js_update_line_json">
<a t-href="./update_line/#{ line.id }/?order_id=#{ quotation.id }&amp;remove=True" class="mb8 js_update_line_json">
<span class="fa fa-minus"/>
</a>
</span>
<input type="text" class="form-control js_line_qty" t-att-data-id="line.id" t-att-value="line.product_uom_qty"/>
<input type="text" class="js_quantity form-control" t-att-data-id="line.id" t-att-value="line.product_uom_qty"/>
<span class="input-group-addon">
<a t-href="./update_line/#{ line.id }/?qty=#{line.product_uom_qty}" class="mb8 js_update_line_json">
<a t-href="./update_line/#{ line.id }/?order_id=#{ quotation.id }" class="mb8 js_update_line_json">
<span class="fa fa-plus"/>
</a>
</span>
@ -133,45 +133,20 @@
<strong t-field="line.price_unit" t-field-options='{"widget": "monetary","display_currency": "website.pricelist_id.currency_id"}'></strong>
</td>
<td class="col-sm-1 col-md-1">
<a t-href="./update_line/#{ line.id }/??qty=#{line.product_uom_qty}&amp;unlink=True" class="mb8 js_update_line_json pull-right">
<a t-href="./update_line/#{ line.id }/?order_id=#{ quotation.id }&amp;unlink=True" class="mb8 js_update_line_json pull-right">
<span class="fa fa-trash-o"></span>
</a>
</td>
</tr>
</t>
<tr>
<td>   </td>
<td><h5>Subtotal</h5></td>
<td class="text-right">
<h5>
<strong t-field="quotation.amount_untaxed" t-field-options='{"widget": "monetary","display_currency": "website.pricelist_id.currency_id"}'></strong>
</h5>
</td>
<td>   </td>
</tr>
<tr>
<td>   </td>
<td><h5>Tax</h5></td>
<td class="text-right">
<h5>
<!-- <strong t-field="quotation.amount_taxed"-->
<!-- t-field-options='{-->
<!-- "widget": "monetary",-->
<!-- "display_currency": "website.pricelist_id.currency_id"}'>-->
<!-- </strong>-->
</h5>
</td>
<td>   </td>
</tr>
<tr>
<td>   </td>
<td><h3>Total</h3></td>
<td class="text-right">
<td class="text-left" colspan="2">
<h3>
<strong t-field="quotation.amount_total" t-field-options='{"widget": "monetary","display_currency": "website.pricelist_id.currency_id"}'></strong>
<strong data-id="total_amount" t-field="quotation.amount_total" t-field-options='{"widget": "monetary","display_currency": "website.pricelist_id.currency_id"}'></strong>
</h3>
</td>
<td>   </td>
</tr>
</tbody>
</table>
@ -259,6 +234,7 @@
</section>
</t>
<t t-call="website_sale_quote.pricing"/>
<t t-call="website_sale_quote.product_recommendation"/>
<t t-call="website_sale_quote.chatter"/>
</div>
<div class="col-xs-6 col-md-4 sidebar oe_section" id="sidebar">
@ -272,5 +248,26 @@
</div>
</t>
</template>
<template id="product_recommendation">
<!-- <div class="container mt32" t-if="product.recommended_products()">-->
<h3>Customers who have bought this product also bought:</h3>
<div class='row mt16' style="margin-left: 15px !important;">
<t t-foreach="quotation.recommended_products()" t-as="product">
<div class='col-md-2 thumbnail' style='width: 170px; margin-right: 16px;'>
<div class='mt16 text-center'>
<span t-field="product.image_small" t-field-options='{"widget": "image", "class": "img-rounded"}'/>
<!-- <h5>-->
<!-- <a t-href="/shop/product/#{ slug(product) }/"-->
<!-- style="display: block">-->
<!-- <span t-field='product.name'-->
<!-- style="display: block"/>-->
<!-- </a>-->
<!-- </h5>-->
</div>
</div>
</t>
</div>
<!-- </div>-->
</template>
</data>
</openerp>