Beispiel #1
0
 def _get_partner_pricelist_multi_search_domain_hook(self, company_id):
     domain = super()._get_partner_pricelist_multi_search_domain_hook(
         company_id)
     website = ir_http.get_request_website()
     if website:
         domain += self._get_website_pricelists_domain(website)
     return domain
Beispiel #2
0
 def _get_partner_pricelist_multi_search_domain_hook(self):
     domain = super(ProductPricelist,
                    self)._get_partner_pricelist_multi_search_domain_hook()
     website = ir_http.get_request_website()
     if website:
         domain += self._get_website_pricelists_domain(website.id)
     return domain
Beispiel #3
0
 def get_available(self):
     """ Return the available languages as a list of (code, name) sorted by name. """
     website = ir_http.get_request_website()
     if website:
         return sorted([(lang.code, lang.url_code, lang.name)
                        for lang in request.website.language_ids])
     return super(Lang, self).get_available()
Beispiel #4
0
    def _post_processing_att(self, tagName, atts, options):
        if atts.get('data-no-post-process'):
            return atts

        atts = super(QWeb, self)._post_processing_att(tagName, atts, options)

        if options.get('inherit_branding') or options.get('rendering_bundle') or \
           options.get('edit_translations') or options.get('debug') or (request and request.session.debug):
            return atts

        website = ir_http.get_request_website()
        if not website and options.get('website_id'):
            website = self.env['website'].browse(options['website_id'])

        if not website:
            return atts

        name = self.URL_ATTRS.get(tagName)
        if request and name and name in atts:
            atts[name] = url_for(atts[name])

        if not website.cdn_activated:
            return atts

        if name and name in atts:
            atts = OrderedDict(atts)
            atts[name] = website.get_cdn_url(atts[name])
        if isinstance(atts.get('style'), str) and 'background-image' in atts['style']:
            atts = OrderedDict(atts)
            atts['style'] = re_background_image.sub(lambda m: '%s%s' % (m.group(1), website.get_cdn_url(m.group(2))), atts['style'])

        return atts
Beispiel #5
0
 def _get_pricelist_available(self, req, show_visible=False):
     """ Return the list of pricelists that can be used on website for the current user.
     Country restrictions will be detected with GeoIP (if installed).
     :param bool show_visible: if True, we don't display pricelist where selectable is False (Eg: Code promo)
     :returns: pricelist recordset
     """
     website = ir_http.get_request_website()
     if not website:
         if self.env.context.get('website_id'):
             website = self.browse(self.env.context['website_id'])
         else:
             # In the weird case we are coming from the backend (https://github.com/odoo/odoo/issues/20245)
             website = len(self) == 1 and self or self.search([], limit=1)
     isocountry = req and req.session.geoip and req.session.geoip.get(
         'country_code') or False
     partner = self.env.user.partner_id
     last_order_pl = partner.last_website_so_id.pricelist_id
     partner_pl = partner.property_product_pricelist
     pricelists = website._get_pl_partner_order(
         isocountry,
         show_visible,
         website.user_id.sudo().partner_id.property_product_pricelist.id,
         req and req.session.get('website_sale_current_pl') or None,
         website.pricelist_ids,
         partner_pl=partner_pl and partner_pl.id or None,
         order_pl=last_order_pl and last_order_pl.id or None)
     return self.env['product.pricelist'].browse(pricelists)
Beispiel #6
0
 def _get_partner_pricelist_multi_filter_hook(self):
     res = super(ProductPricelist,
                 self)._get_partner_pricelist_multi_filter_hook()
     website = ir_http.get_request_website()
     if website:
         res = res.filtered(
             lambda pl: pl._is_available_on_website(website.id))
     return res
Beispiel #7
0
 def _compute_cart_qty(self):
     website = ir_http.get_request_website()
     if not website:
         self.cart_qty = 0
         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
Beispiel #8
0
 def _get_contextual_pricelist(self):
     """ Override to fallback on website current pricelist
     """
     pricelist = super()._get_contextual_pricelist()
     if pricelist:
         return pricelist
     website = ir_http.get_request_website()
     if website:
         return website.get_current_pricelist()
     return pricelist
Beispiel #9
0
 def _get_partner_pricelist_multi(self, partner_ids, company_id=None):
     ''' If `property_product_pricelist` is read from website, we should use
         the website's company and not the user's one.
         Passing a `company_id` to super will avoid using the current user's
         company.
     '''
     website = ir_http.get_request_website()
     if not company_id and website:
         company_id = website.company_id.id
     return super(ProductPricelist, self)._get_partner_pricelist_multi(partner_ids, company_id)
Beispiel #10
0
 def _get_partner_pricelist_multi(self, partner_ids, company_id=None):
     ''' If `property_product_pricelist` is read from website, we should use
         the website's company and not the user's one.
         Passing a `company_id` to super will avoid using the current user's
         company.
     '''
     website = ir_http.get_request_website()
     if not company_id and website:
         company_id = website.company_id.id
     return super(ProductPricelist, self)._get_partner_pricelist_multi(partner_ids, company_id)
Beispiel #11
0
    def _eval_context(self):
        res = super(IrRule, self)._eval_context()

        # We need is_frontend to avoid showing website's company items in backend
        # (that could be different than current company). We can't use
        # `get_current_website(falback=False)` as it could also return a website
        # in backend (if domain set & match)..
        is_frontend = ir_http.get_request_website()
        Website = self.env['website']
        res['website'] = is_frontend and Website.get_current_website() or Website
        return res
Beispiel #12
0
    def _compute_cart_qty(self):
        """Get cart quantity in order to set custom availability messages.

        """
        website = ir_http.get_request_website()
        if not website:
            self.cart_qty = 0
            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
Beispiel #13
0
 def _compute_cart_qty(self):
     website = ir_http.get_request_website()
     if not website:
         self.cart_qty = 0
         return
     cart = website.sale_get_order()
     for product in self:
         qty = 0
         for line in cart.order_line.filtered(
                 lambda p: p.product_id.id == product.id):
             qty += line.product_uom_qty * line.product_uom.factor_inv
         product.cart_qty = qty
Beispiel #14
0
	def _compute_last_website_quote_id(self):
		QuoteOrder = self.env['quote.order']
		for partner in self:
			is_public = any([u._is_public()
							 for u in partner.with_context(active_test=False).user_ids])
			website = ir_http.get_request_website()
			if website and not is_public:
				partner.last_website_quote_id = QuoteOrder.search([
					('partner_id', '=', partner.id),
				],order='id desc',  limit=1)
			else:
				partner.last_website_quote_id = QuoteOrder
Beispiel #15
0
 def _compute_last_website_so_id(self):
     SaleOrder = self.env['sale.order']
     for partner in self:
         is_public = partner.is_public
         website = ir_http.get_request_website()
         if website and not is_public:
             partner.last_website_so_id = SaleOrder.search([
                 ('partner_id', '=', partner.id),
                 ('website_id', '=', website.id),
                 ('state', '=', 'draft'),
             ], order='write_date desc', limit=1)
         else:
             partner.last_website_so_id = SaleOrder  # Not in a website context or public User
Beispiel #16
0
 def _compute_last_website_so_id(self):
     SaleOrder = self.env['sale.order']
     for partner in self:
         is_public = any([u._is_public()
                          for u in partner.with_context(active_test=False).user_ids])
         website = ir_http.get_request_website()
         if website and not is_public:
             partner.last_website_so_id = SaleOrder.search([
                 ('partner_id', '=', partner.id),
                 ('website_id', '=', website.id),
                 ('state', '=', 'draft'),
             ], order='write_date desc', limit=1)
         else:
             partner.last_website_so_id = SaleOrder  # Not in a website context or public User
Beispiel #17
0
    def _post_processing_att(self, tagName, atts):
        if atts.get('data-no-post-process'):
            return atts

        atts = super()._post_processing_att(tagName, atts)

        website = ir_http.get_request_website()
        if not website and self.env.context.get('website_id'):
            website = self.env['website'].browse(
                self.env.context['website_id'])
        if website and tagName == 'img' and 'loading' not in atts:
            atts['loading'] = 'lazy'  # default is auto

        if self.env.context.get('inherit_branding') or self.env.context.get('rendering_bundle') or \
           self.env.context.get('edit_translations') or self.env.context.get('debug') or (request and request.session.debug):
            return atts

        if not website:
            return atts

        name = self.URL_ATTRS.get(tagName)
        if request and name and name in atts:
            atts[name] = url_for(atts[name])

        if not website.cdn_activated:
            return atts

        data_name = f'data-{name}'
        if name and (name in atts or data_name in atts):
            atts = OrderedDict(atts)
            if name in atts:
                atts[name] = website.get_cdn_url(atts[name])
            if data_name in atts:
                atts[data_name] = website.get_cdn_url(atts[data_name])
        if isinstance(atts.get('style'),
                      str) and 'background-image' in atts['style']:
            atts = OrderedDict(atts)
            atts['style'] = re_background_image.sub(
                lambda m: '%s%s' %
                (m.group(1), website.get_cdn_url(m.group(2))), atts['style'])

        return atts
 def _domain_website_attachment_ids(self):
     """Get domain for website attachments."""
     domain = [
         # Only use public attachments
         ("public", "=", True),
         # Exclude Odoo asset files to avoid confusing the user
         "!",
         ("name", "=ilike", "/web/content/%.assets%.js"),
         "!",
         ("name", "=ilike", "/web/content/%.assets%.css"),
         "!",
         ("name", "=ilike", r"/web/content/%/web\_editor.summernote%.js"),
         "!",
         ("name", "=ilike", r"/web/content/%/web\_editor.summernote%.css"),
     ]
     # Filter by website domain in frontend
     if ir_http.get_request_website():
         website = self.env["website"].get_current_website()
         domain += website.website_domain()
     return domain
Beispiel #19
0
 def _get_pricelist_available(self, req, show_visible=False):
     """ Return the list of pricelists that can be used on website for the current user.
     Country restrictions will be detected with GeoIP (if installed).
     :param bool show_visible: if True, we don't display pricelist where selectable is False (Eg: Code promo)
     :returns: pricelist recordset
     """
     website = ir_http.get_request_website()
     if not website:
         if self.env.context.get('website_id'):
             website = self.browse(self.env.context['website_id'])
         else:
             # In the weird case we are coming from the backend (https://github.com/odoo/odoo/issues/20245)
             website = len(self) == 1 and self or self.search([], limit=1)
     isocountry = req and req.session.geoip and req.session.geoip.get('country_code') or False
     partner = self.env.user.partner_id
     last_order_pl = partner.last_website_so_id.pricelist_id
     partner_pl = partner.sudo(user=self.env.user).property_product_pricelist
     pricelists = website._get_pl_partner_order(isocountry, show_visible,
                                                website.user_id.sudo().partner_id.property_product_pricelist.id,
                                                req and req.session.get('website_sale_current_pl') or None,
                                                website.pricelist_ids,
                                                partner_pl=partner_pl and partner_pl.id or None,
                                                order_pl=last_order_pl and last_order_pl.id or None)
     return self.env['product.pricelist'].browse(pricelists)
Beispiel #20
0
    def _get_price_and_discount(self, qty, partner_id, date):
        res = {
            "price": 0,
            "discount": 0,
            "explanation": "",
            "decimals": 2,
            "customer_price": False,
            "promotion": False,
        }
        # if self._context.get('only_pricelist', False):
        #     res['price'] = self.price
        #     return res
        website = ir_http.get_request_website()
        if isinstance(partner_id, pycompat.integer_types):
            partner = self.env["res.partner"].browse(partner_id)[0]
        else:
            partner = partner_id
        # print ("CÁLCULO  DE PRECIOS PERSONALIZADO . Partner %s " % partner.name )
        if partner.portfolio:
            decimals = max([partner.decimals, partner.commercial_partner_id.decimals])
        else:
            decimals = 2
        # print("DECIMALS: %d" % decimals)
        discount = 0
        promotion = False
        # Precio de tarifa
        if self._context.get('pricelist', False):
            pricelist = self.env["product.pricelist"].browse(self._context['pricelist'])[0]
        else:
            pricelist = partner.commercial_partner_id.property_product_pricelist

        pricelist_prices = pricelist.get_products_price(
            self, [qty], [partner.id], date
        )
        if self.id:
            pricelist_price = pricelist_prices[self.id]
        else:
            pricelist_price = 0
        pricelist_price_discount = pricelist_price_web = pricelist_price
        pricelist_explanation = "Precio de tarifa "
        if website and website._uid:
            uid = self.env["res.users"].sudo().browse(website._uid)[0]
            web_request = uid.share
            portfolio = uid.portfolio
        else:
            web_request = False
            portfolio = False
        if web_request:
            # es usuario web
            web_default_pricelist = website.get_pricelist_available()[0]
            web_prices = web_default_pricelist.get_products_price(
                self, [qty], [partner.id], date
            )
            pricelist_price_web = web_prices[self.id]
            # pricelist_price_web  = self.with_context({'pricelist':web_default_pricelist.id, 'only_pricelist':True}).price
            # print ("Usuario WEB. Precio WEB %f" % pricelist_price_web)

        # SE cpopia toda esta parte par mostrar el descuetno de forma explícita
        # PEro se necesita en esta parte para poder comprar precios incluido el descuento
        # Aplica descuento de categoría
        categ_dis = self.env["category.discount"].get_customer_discount(
            partner.commercial_partner_id, self.categ_id.id
        )

        if categ_dis:

            pricelist_price_discount = pricelist_price * (
                1 - categ_dis[0].discount / 100
            )
            pricelist_explanation += " . Encontrado descuento de " "categoría  " + str(
                categ_dis[0].discount
            )
            discount = categ_dis[0].discount

            # get customet price
        customer_price = (
            self.env["customer.price"].get_customer_price(
                partner.sudo().commercial_partner_id, self, qty
            )
            or 0
        )
        if customer_price:
            res["customer_price"] = True

        # search promotion
        rule = self.env["product.pricelist"].search_promotion(self.id, qty, date)
        if rule:
            promotion_price = rule.fixed_price
        else:
            promotion_price = 0

        # Selecciona precio mínimo

        if partner.fixed_prices or partner.commercial_partner_id.fixed_prices:

            if customer_price:
                price = customer_price
                discount = 0
                explanation = "Cliente con precios fijos: Precio " "pactado "
            else:
                if (
                    pricelist_price_discount
                    and pricelist_price_discount < pricelist_price
                ):
                    price = pricelist_price
                    explanation = (
                        "Cliente con precios fijos: Precio "
                        "pactado no encontrado. Aplicado "
                        "precio de tarifa con descuento por categoría: \n"
                        + pricelist_explanation
                    )
                else:
                    discount = 0
                    price = pricelist_price
                    explanation = (
                        "Cliente con precios fijos: Precio "
                        "pactado no encontrado. Aplicado "
                        "precio de tarifa: \n" + pricelist_explanation
                    )
        else:
            price = pricelist_price
            explanation = pricelist_explanation
            if (
                customer_price
                and customer_price < pricelist_price_discount
                and pricelist_price_discount != 0
            ):
                price = customer_price
                explanation = "Encontrado precio pactado por debajo " "de tarifa "
                discount = 0
            if (
                promotion_price
                and promotion_price < pricelist_price_discount
                and promotion_price < price
                and price != 0
            ):
                price = promotion_price
                explanation = "Aplicada promoción "
                discount = 0
                promotion = True
            if (
                web_request
                and pricelist_price_web < pricelist_price_discount
                and pricelist_price_web < price
                and pricelist_price_web != 0
            ):
                price = pricelist_price_web
                explanation = "Aplicada precio web"
                discount = 0
                # print("PRECIO WEB APLICADO!!!!!  %d" % price)

        if web_request and not portfolio:
            # print("REDONDEA PRECIOS sies web y no cartera")
            decimals = 2
            # Si es web y no es cliete de  cartera redondeo a dos decimales
            if discount:
                price = float(round(Decimal(str(pricelist_price_discount)), 2))
            else:
                price = float(round(Decimal(str(price)), 2))
            discount = 0

        print("Producto %d , Precio: %f" % (self.id, price))
        res["price"] = price
        res["discount"] = discount
        res["decimals"] = decimals
        res["explanation"] += explanation
        res["promotion"] = promotion
        return res
Beispiel #21
0
 def _get_partner_pricelist_multi_search_domain_hook(self):
     domain = super(ProductPricelist, self)._get_partner_pricelist_multi_search_domain_hook()
     website = ir_http.get_request_website()
     if website:
         domain += self._get_website_pricelists_domain(website.id)
     return domain
Beispiel #22
0
 def _get_partner_pricelist_multi_filter_hook(self):
     res = super(ProductPricelist, self)._get_partner_pricelist_multi_filter_hook()
     website = ir_http.get_request_website()
     if website:
         res = res.filtered(lambda pl: pl._is_available_on_website(website.id))
     return res