Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions website_sale_ribbon_from_discount/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
41 changes: 41 additions & 0 deletions website_sale_ribbon_from_discount/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
##############################################################################
#
# Copyright (C) 2015 ADHOC SA (http://www.adhoc.com.ar)
# All Rights Reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# 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/>.
#
##############################################################################
{
'name': 'Website Sale Ribbon From Discount',
'category': 'Website',
'summary': 'Website Sale',
'version': "16.0.1.0.0",
'author': 'ADHOC SA',
'website': 'www.adhoc.com.ar',
'license': 'AGPL-3',
'depends': [
'website_sale',
'product',
'base_automation',
],
'data': [
'views/product_pricelist_item.xml',
'views/product_template.xml',
'views/website_sale_templates.xml',
'data/base_automation.xml',
],
'installable': True,
'application': False,
}
77 changes: 77 additions & 0 deletions website_sale_ribbon_from_discount/data/base_automation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version='1.0' encoding='UTF-8'?>
<odoo>
<record id="create_ribbon_from_discount_on_update_record" model="base.automation">
<field name="name">create Ribbon from discount on record update</field>
<field ref="product.model_product_pricelist_item" name="model_id"/>
<field name="state">code</field>
<field name="binding_type">action</field>
<field name="code">

for rec in record:
if rec.create_ribbon:
if rec.compute_price == 'fixed':
raise UserError("Solo puede crearse un ribbon desde decuento si el tipo es 'Descuento' o 'Formula'")
elif rec.applied_on in ['3_global', '0_product_variant']:
raise UserError("Solo puede crearse un ribbon desde decuento si se selecciona aplicable en: 'Producto' o 'Categoría de producto'")
elif not rec.date_start or not rec.date_end:
raise UserError("Solo puede crearse un ribbon desde decuento si estan establecidas fechas de inicio y fin")
elif not rec.website_ribbon_id:
raise UserError("No se ha creado un ribbon para el website, primero cree uno y luego guarde")
else:
if rec.applied_on == '2_product_category':
products = rec.env['product.template'].search([('categ_id.id', '=', rec.categ_id.id)])
elif rec.applied_on == '1_product':
products = rec.env['product.template'].search([('id', '=', rec.product_tmpl_id.id)])
if rec.date_start.date() == datetime.datetime.today().date():
rec.website_ribbon_id.write({'html_class':'text-bg-success o_ribbon_right','ribbon_from_discount':True})
for product in products:
product.write({'ribbon_from_discount':rec.website_ribbon_id})</field>
<field name="trigger">on_write</field>
</record>
<record id="delete_ribbon_from_discount_on_date_end_reached" model="base.automation">
<field name="name">delete ribbon when date_end reached</field>
<field ref="product.model_product_pricelist_item" name="model_id"/>
<field name="state">code</field>
<field name="binding_type">action</field>
<field name="code">

products = env['product.template'].search([('ribbon_from_discount','=','rec.website_ribbon_id')])
for rec in record:
for product in products:
product.write({'ribbon_from_discount':False})</field>
<field name="trigger">on_time</field>
<field name="trg_date_id" ref="product.field_product_pricelist_item__date_end" />
<field name="trg_date_range">0</field>
<field name="trg_date_range_type">minutes</field>
</record>
<record id="create_ribbon_from_discount_on_date_start_reached" model="base.automation">
<field name="name">create ribbon when date_start reached</field>
<field ref="product.model_product_pricelist_item" name="model_id"/>
<field name="state">code</field>
<field name="binding_type">action</field>
<field name="code">

for rec in record:
if rec.create_ribbon:
if rec.compute_price == 'fixed':
pass
elif rec.applied_on in ['3_global', '0_product_variant']:
pass
elif not rec.date_start or not rec.date_end:
pass
elif not rec.website_ribbon_id:
pass
else:
if rec.applied_on == '2_product_category':
products = rec.env['product.template'].search([('categ_id.id', '=', rec.categ_id.id)])
elif rec.applied_on == '1_product':
products = rec.env['product.template'].search([('id', '=', rec.product_tmpl_id.id)])
rec.website_ribbon_id.write({'html_class':'text-bg-success o_ribbon_right','ribbon_from_discount':True})
for product in products:
product.write({'ribbon_from_discount':rec.website_ribbon_id})</field>
<field name="trigger">on_time</field>
<field name="trg_date_id" ref="product.field_product_pricelist_item__date_start" />
<field name="trg_date_range">0</field>
<field name="trg_date_range_type">minutes</field>
</record>
</odoo>
3 changes: 3 additions & 0 deletions website_sale_ribbon_from_discount/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import product_pricelist_item
from . import product_template
from . import product_ribbon
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-

from odoo import models, fields

class PricelistItem(models.Model):
_inherit = "product.pricelist.item"

create_ribbon = fields.Boolean(string="Promocionar en eCommerce")
website_ribbon_id = fields.Many2one('product.ribbon', string="Ribbon")
10 changes: 10 additions & 0 deletions website_sale_ribbon_from_discount/models/product_ribbon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models


class ProductRibbon(models.Model):
_inherit = "product.ribbon"

ribbon_from_discount = fields.Boolean("Ribbon creado desde un descuento")
8 changes: 8 additions & 0 deletions website_sale_ribbon_from_discount/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-

from odoo import models, fields

class PricelistItem(models.Model):
_inherit = "product.template"

ribbon_from_discount = fields.Many2one('product.ribbon', string='Ribbon from discount', readonly=True)
27 changes: 27 additions & 0 deletions website_sale_ribbon_from_discount/views/product_pricelist_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record model="ir.ui.view" id="product_pricelist_item">
<field name="name">product_pricelist_item</field>
<field name="model">product.pricelist.item</field>
<field name="inherit_id" ref="product.product_pricelist_item_form_view"/>
<field name="priority">99</field>
<field name="arch" type="xml">
<xpath expr="//sheet" position="inside">
<group string="Website Ribbon" attrs="{'invisible':['|','|',('applied_on', '=', '3_global'), ('date_start', '=', False), ('date_end', '=', False)]}">
<group>
<div class="o_row">
<label for="create_ribbon" />
<field name="create_ribbon" />
</div>
</group>
<group attrs="{'invisible': [('create_ribbon', '=', False)]}" >
<div class="o_row">
<label for="website_ribbon_id" />
<field name="website_ribbon_id" domain="[('id', '=', False)]" style="width:300px !important"/>
</div>
</group>
</group>
</xpath>
</field>
</record>
</odoo>
16 changes: 16 additions & 0 deletions website_sale_ribbon_from_discount/views/product_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record model="ir.ui.view" id="product_template">
<field name="name">product_template</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="website_sale.product_template_form_view"/>
<field name="arch" type="xml">
<field name="website_ribbon_id" position="after">
<field name="ribbon_from_discount" />
</field>
<field name="website_ribbon_id" position="attributes">
<attribute name="domain">[('ribbon_from_discount', '=', False)]</attribute>
</field>
</field>
</record>
</odoo>
11 changes: 11 additions & 0 deletions website_sale_ribbon_from_discount/views/website_sale_templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="products_item" inherit_id="website_sale.products_item">
<xpath expr="//a[hasclass('oe_product_image_link')]" position="inside">
<t t-set="bg_color_ribbon_from_discount" t-value="product.ribbon_from_discount.bg_color or ''"/>
<t t-set="text_color_ribbon_from_discount" t-value="product.ribbon_from_discount.text_color"/>
<t t-set="bg_class_ribbon_from_discount" t-value="product.ribbon_from_discount.html_class"/>
<span t-attf-class="o_ribbon #{bg_class_ribbon_from_discount}" t-attf-style="#{text_color_ribbon_from_discount and ('color: %s; ' % text_color)}#{bg_color and 'background-color:' + bg_color_ribbon_from_discount}" t-out="product.ribbon_from_discount.html or ''"/>
</xpath>
</template>
</odoo>