2013-07-16 09:36:24 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
2013-08-12 16:31:23 +00:00
|
|
|
# Copyright (C)-2010 Tiny SPRL (<http://tiny.be>).
|
2013-07-16 09:36:24 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
2013-08-12 16:31:23 +00:00
|
|
|
# published by the Free Software Foundation, either version of the
|
2013-07-16 09:36:24 +00:00
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2013-09-02 10:46:46 +00:00
|
|
|
from openerp import SUPERUSER_ID
|
2013-07-16 09:36:24 +00:00
|
|
|
from openerp.osv import osv, fields
|
|
|
|
|
|
|
|
|
|
|
|
class product_pricelist(osv.osv):
|
|
|
|
_inherit = "product.pricelist"
|
|
|
|
_columns = {
|
2013-08-22 09:09:41 +00:00
|
|
|
'code': fields.char('Promotionnal Code', size=64, translate=True),
|
2013-07-16 09:36:24 +00:00
|
|
|
}
|
2013-08-12 09:12:49 +00:00
|
|
|
|
2013-08-22 14:27:35 +00:00
|
|
|
class product_template(osv.osv):
|
2013-08-20 14:12:03 +00:00
|
|
|
_inherit = "product.template"
|
2013-09-24 10:28:34 +00:00
|
|
|
_order = 'website_published,name'
|
2013-08-12 09:12:49 +00:00
|
|
|
_columns = {
|
|
|
|
'website_published': fields.boolean('Available in the website'),
|
2013-08-23 13:36:04 +00:00
|
|
|
'website_description': fields.html('Description for the website'),
|
2013-09-03 08:36:39 +00:00
|
|
|
'suggested_product_id': fields.many2one('product.template', 'Suggested For Product'),
|
|
|
|
'suggested_product_ids': fields.one2many('product.template', 'suggested_product_id', 'Suggested Products'),
|
2013-09-22 17:27:27 +00:00
|
|
|
'website_sizex': fields.selection(map(lambda x: (str(x+1),str(x+1)), range(12)), 'Size X'),
|
|
|
|
'website_sizey': fields.selection(map(lambda x: (str(x+1),str(x+1)), range(6)), 'Size Y'),
|
|
|
|
'website_product_class': fields.selection([('','Default'), ('oe_image_full','Image Full')], 'Size Y'),
|
2013-09-19 05:54:25 +00:00
|
|
|
}
|
|
|
|
_defaults = {
|
2013-09-23 12:03:28 +00:00
|
|
|
'website_sizex': '3',
|
|
|
|
'website_sizey': '2',
|
2013-09-22 17:27:27 +00:00
|
|
|
'website_product_class': '',
|
2013-08-12 16:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def recommended_products(self, cr, uid, ids, context=None):
|
|
|
|
id = ids[0]
|
|
|
|
product_ids = []
|
|
|
|
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
|
2013-08-19 13:19:29 +00:00
|
|
|
LIMIT 10
|
2013-08-13 11:52:47 +00:00
|
|
|
"""
|
|
|
|
cr.execute(query, (id, id))
|
2013-08-12 16:31:23 +00:00
|
|
|
for p in cr.fetchall():
|
|
|
|
product_ids.append(p[0])
|
|
|
|
|
|
|
|
# search to apply access rules
|
2013-08-19 13:19:29 +00:00
|
|
|
product_ids = self.search(cr, uid, [("id", "in", product_ids)], limit=3)
|
2013-08-12 16:31:23 +00:00
|
|
|
return self.browse(cr, uid, product_ids)
|
|
|
|
|
2013-08-14 13:57:41 +00:00
|
|
|
def img(self, cr, uid, ids, field='image_small', context=None):
|
|
|
|
return "/website/image?model=%s&field=%s&id=%s" % (self._name, field, ids[0])
|
2013-08-12 16:31:23 +00:00
|
|
|
|
2013-08-22 14:27:35 +00:00
|
|
|
class product_product(osv.osv):
|
|
|
|
_inherit = "product.product"
|
2013-09-04 09:54:05 +00:00
|
|
|
|
|
|
|
def _website_url(self, cr, uid, ids, field_name, arg, context=None):
|
|
|
|
res = {}
|
|
|
|
base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url')
|
|
|
|
for id in ids:
|
|
|
|
res[id] = "%s/shop/product/%s/" % (base_url, id)
|
|
|
|
return res
|
2013-08-22 14:27:35 +00:00
|
|
|
|
2013-09-04 09:54:05 +00:00
|
|
|
_columns = {
|
|
|
|
'website_url': fields.function(_website_url, string="Website url"),
|
|
|
|
}
|
|
|
|
|
2013-08-22 14:27:35 +00:00
|
|
|
def img(self, cr, uid, ids, field='image_small', context=None):
|
|
|
|
return "/website/image?model=%s&field=%s&id=%s" % (self._name, field, ids[0])
|
|
|
|
|
2013-08-12 16:31:23 +00:00
|
|
|
class sale_order(osv.osv):
|
|
|
|
_inherit = "sale.order"
|
|
|
|
|
|
|
|
def get_total_quantity(self, cr, uid, ids, context=None):
|
|
|
|
order = self.browse(cr, uid, ids[0], context=context)
|
2013-08-13 09:12:18 +00:00
|
|
|
|
|
|
|
return sum(l.product_uom_qty for l in (order.order_line or []))
|
2013-09-02 10:46:46 +00:00
|
|
|
|
|
|
|
class sale_order_line(osv.osv):
|
|
|
|
_inherit = "sale.order.line"
|
|
|
|
|
|
|
|
def _recalculate_product_values(self, cr, uid, ids, product_id=None, context=None):
|
|
|
|
user_obj = self.pool.get('res.users')
|
|
|
|
product_id = product_id or ids and self.browse(cr, uid, ids[0], context=context).product_id.id
|
2013-09-05 08:04:07 +00:00
|
|
|
return self.product_id_change(cr, SUPERUSER_ID, [],
|
2013-09-02 10:46:46 +00:00
|
|
|
pricelist=context.pop('pricelist'),
|
|
|
|
product=product_id,
|
|
|
|
partner_id=user_obj.browse(cr, SUPERUSER_ID, uid).partner_id.id,
|
|
|
|
context=context)['value']
|