2018-01-16 06:58:15 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-01-16 11:34:37 +01:00
|
|
|
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
|
2018-01-16 06:58:15 +01:00
|
|
|
|
2018-01-16 11:34:37 +01:00
|
|
|
from flectra import fields, models
|
|
|
|
from flectra.http import request
|
2018-01-16 06:58:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ProductProduct(models.Model):
|
|
|
|
_inherit = 'product.product'
|
|
|
|
|
|
|
|
cart_qty = fields.Integer(compute='_compute_cart_qty')
|
|
|
|
|
|
|
|
def _compute_cart_qty(self):
|
|
|
|
website = getattr(request, 'website', None)
|
|
|
|
if not website:
|
|
|
|
return
|
|
|
|
cart = website.sale_get_order()
|
|
|
|
for product in self:
|
|
|
|
product.cart_qty = sum(cart.order_line.filtered(lambda p: p.product_id.id == product.id).mapped('product_uom_qty')) if cart else 0
|