flectra/addons/website_sale_stock/models/product_product.py
flectra-admin 769eafb483 [INIT] Inception of Flectra from Odoo
Flectra is Forked from Odoo v11 commit : (6135e82d73)
2018-01-16 11:45:59 +05:30

20 lines
634 B
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
from odoo.http import request
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