Selaa lähdekoodia

commit inicial

Rodney Enciso Arias 7 vuotta sitten
commit
dfd75368b8

+ 0 - 0
.scannerwork/.sonar_lock


+ 5 - 0
.scannerwork/report-task.txt

@@ -0,0 +1,5 @@
+projectKey=website:sale:add:curve
+serverUrl=http://181.40.66.126:9000
+dashboardUrl=http://181.40.66.126:9000/dashboard/index/website:sale:add:curve
+ceTaskId=AV94oOt9LmS3QZZeLmuW
+ceTaskUrl=http://181.40.66.126:9000/api/ce/task?id=AV94oOt9LmS3QZZeLmuW

+ 2 - 0
__init__.py

@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+from . import models

BIN
__init__.pyc


+ 31 - 0
__openerp__.py

@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+{
+    "name": "Website Sale Add Curve",
+    "summary": """ Actualizacion del carro de compras para el eCommerce""",
+    "category": "eCommerce",
+    "images": [],
+    "version": "2.0",
+
+    "author": "Eiru Software",
+    "website": "https://www.eiru.com.py",
+    "license": "GPL-3",
+
+    "depends": [
+        "website_sale","website","product_curve"
+    ],
+    "external_dependencies": {"python": [], "bin": []},
+    "data": [
+        "view/product_view.xml",
+        "templates.xml",
+    ],
+    "qweb": [
+    ],
+    "demo": [
+    ],
+
+    "post_load": None,
+    "pre_init_hook": None,
+    "post_init_hook": None,
+    "installable": True,
+    "auto_install": False,
+}

+ 2 - 0
models/__init__.py

@@ -0,0 +1,2 @@
+from . import product
+from . import partner

BIN
models/__init__.pyc


BIN
models/partner.pyc


+ 7 - 0
models/product.py

@@ -0,0 +1,7 @@
+from openerp import api, fields, models
+
+class ProductTemplate(models.Model):
+    _inherit = 'product.template'
+
+    curva = fields.Char("Curva")
+    product_website_sale_type = fields.Boolean()

BIN
models/product.pyc


+ 5 - 0
sonar-project.properties

@@ -0,0 +1,5 @@
+sonar.projectKey=website:sale:add:curve
+sonar.projectName=website_sale_add_curve
+sonar.projectVersion=1.0
+sonar.sources=static/src
+sonar.javascript.globals=openerp

+ 98 - 0
static/src/js/website_sale_multi_add.js

@@ -0,0 +1,98 @@
+// Comprar productos por unidad
+$('.js_variant_change').click(function(e) {
+    var attributeList = $('#attribute_list').val();
+    var add_qty = $('#add_qty').val();
+    var attribute_color = $('input:radio[id=product_color]:checked').val();
+    var target = $(e.currentTarget).prop('id');
+    var attribute_id = target.substring(target.indexOf('_') + 1);
+    var indexOfValue;
+    if(attribute_color === undefined){
+        indexOfValue = attributeList.indexOf('[' + attribute_id + ']');
+    }else{
+        indexOfValue = attributeList.indexOf('[' + attribute_color + ', ' + attribute_id);
+        if(indexOfValue < 0){
+            indexOfValue = attributeList.indexOf('[' + attribute_id + ', ' + attribute_color);   
+        }
+    }
+    var buffer = '';
+    for (var i = indexOfValue - 2; i > 0; i--) {
+        var charValue = attributeList.charAt(i);
+        if (charValue === '[') {
+            break;
+        }
+        if ($.isNumeric(charValue)) {
+            buffer = attributeList.charAt(i) + buffer;
+        }
+    }
+    var data = '&product_id=' + buffer + '&add_qty=' + add_qty;
+    $.ajax({
+        url: '/shop/cart/update',
+        type: 'POST',
+        async: false,
+        data: data,
+    });
+    window.location.reload();
+    return false;
+});
+ 
+// comprar por curva
+$('#curva').off('click').click(function() {
+    var attribute_color = $('input:radio[id=product_color2]:checked').val();
+    var attributeList = $('#attribute_list').val();
+    var variantList = $('#variant_list').val();  
+    var variant = variantList.substring(variantList.indexOf('(')).split(",");
+    var indexOfValue;
+    var buffer;
+    var valor;
+    var dato;
+    var array_ids = [];
+    var productCurva = $('#product_curva_qty').val().split(",");
+    for (var i = 0; i < variant.length; i++) {
+        valor = variant[i];
+        if(i === 0){
+            dato = valor.split("(");
+            valor = dato[1];
+        }else {
+            if (i === variant.length-1) {
+                dato = valor.split(")");
+                valor = dato[0];
+            }
+        }
+        valor = parseInt(valor);
+        if(attribute_color === undefined){
+            indexOfValue = attributeList.indexOf('[' + valor + ']');
+        }else{
+            indexOfValue = attributeList.indexOf('[' + attribute_color + ', ' + valor);
+            if(indexOfValue < 0){
+                indexOfValue = attributeList.indexOf('[' + valor + ', ' + attribute_color);   
+            }
+        }
+        buffer = '';
+        for (var j = indexOfValue - 2; j >= 0; j--) {
+            var charValue = attributeList.charAt(j);
+            if (charValue === '[') {
+                break;
+            }
+            if ($.isNumeric(charValue)) {
+                buffer = attributeList.charAt(j) + buffer;
+            }
+        }
+        var number = parseInt(buffer);
+        array_ids.push(number);
+    }
+    array_ids.sort(function(a, b) {
+        return a - b
+    });
+    for (var k = 0; k < array_ids.length; k++) {
+        var add_qty = productCurva[k];
+        var data = '&product_id=' + array_ids[k] + '&add_qty=' + add_qty;
+        $.ajax({
+            url: '/shop/cart/update',
+            type: 'POST',
+            async: false,
+            data: data,
+        });
+    }
+    window.location.reload();
+    return false;
+});

+ 159 - 0
templates.xml

@@ -0,0 +1,159 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <template id="assets_frontend" inherit_id="website.assets_frontend" name="Shop">
+            <xpath expr="." position="inside">
+                <script type="text/javascript" src="/website_sale_add_curve/static/src/js/website_sale_multi_add.js"></script>
+            </xpath>
+        </template>
+        <template id="variant_form" inherit_id="website_sale.variants" name="variants">
+            <xpath expr="//t[@t-as='variant_id']" position="replace">
+                <t t-foreach="product.attribute_line_ids" t-as="variant_id">
+                    <li t-if="len(variant_id.value_ids) &gt; 1">
+                        <t t-if="variant_id.attribute_id.type in ['select', 'hidden']">
+                            <select class="form-control js_variant_change" t-att-name="'attribute-%s-%s' % (product.id, variant_id.attribute_id.id)">
+                                <t t-foreach="variant_id.value_ids" t-as="value_id">
+                                    <option t-att-value="value_id.id">
+                                        <span t-field="value_id.name"/>
+                                        <span t-if="value_id.price_extra">
+                                            <t t-esc="value_id.price_extra &gt; 0 and '+' or ''"/><span
+                                                t-field="value_id.price_extra"
+                                                style="white-space: nowrap;"
+                                                t-field-options="{                                &quot;widget&quot;: &quot;monetary&quot;,                                 &quot;from_currency&quot;: &quot;product.company_id.currency_id&quot;,                                &quot;display_currency&quot;: &quot;user_id.partner_id.property_product_pricelist.currency_id&quot;                            }"/>
+                                        </span>
+                                    </option>
+                                </t>
+                            </select>
+                        </t> 
+                        <t t-if="product.product_website_sale_type == False">
+                            <input id="attribute_list" type="hidden" t-att-value="attribute_value_ids"></input>
+                            <div class="container">
+                                <div class="row text-left">
+                                    <div class="col-md-12">
+                                        <h3 t-field="variant_id.attribute_id.name"></h3>
+                                        <table class="table text-center">
+                                            <t t-if="variant_id.attribute_id.type == 'radio'">
+                                                <ul class="list-unstyled">
+                                                    <t t-set="inc" t-value="0"/>
+                                                    <t t-foreach="variant_id.value_ids" t-as="value_id">
+                                                        <li class="form-group js_attribute_value">
+                                                            <tr>
+                                                                <td>
+                                                                    <span t-field="value_id.name"/>
+                                                                    <span class="badge" t-if="value_id.price_extra">
+                                                                        <t t-esc="value_id.price_extra &gt; 0 and '+' or ''"/>
+                                                                        <span t-field="value_id.price_extra" t-field-options="{                                       &quot;widget&quot;: &quot;monetary&quot;,                                       &quot;from_currency&quot;: &quot;product.company_id.currency_id&quot;,                                       &quot;display_currency&quot;: &quot;user_id.partner_id.property_product_pricelist.currency_id&quot;                                    }"/>
+                                                                        </span>
+                                                                </td>
+                                                                <td>
+                                                                   <div class="input-group oe_website_spinner">
+                                                                        <span class="input-group-addon">
+                                                                            <a t-attf-href="#" class="mb8 js_add_cart_json">
+                                                                                <i class="fa fa-minus"/>
+                                                                            </a>
+                                                                        </span>
+                                                                        <input type="text" class="js_quantity form-control" data-min="1" name="add_qty" value="1" id="add_qty"/>
+                                                                        <span class="input-group-addon">
+                                                                            <a t-attf-href="#" class="mb8 float_left js_add_cart_json">
+                                                                                <i class="fa fa-plus"/>
+                                                                            </a>
+                                                                        </span>
+                                                                    </div>
+                                                                </td>
+                                                                <td>
+                                                                    <button t-att-id="'attribute_%s' % value_id.id" type="button" class="js_variant_change btn btn-primary" t-att-checked="'checked' if not inc else ''" t-att-name="'attribute-%s-%s' % (product.id, variant_id.attribute_id.id)" t-att-value="inc+1">añadir a la cesta</button>
+                                                                </td>
+                                                            </tr>
+                                                        </li>
+                                                    <t t-set="inc" t-value="inc+1"/></t>
+                                                </ul>
+                                            </t>
+                                        </table>
+                                        
+                                        <!-- Variante tipo color -->
+                                        <t t-if="variant_id.attribute_id.type == 'color'">
+                                            <input id="variant_list_color" type="hidden" t-att-value="variant_id.value_ids"></input>
+                                            <ul class="list-inline">
+                                                <t t-set="inc" t-value="0"/>
+                                                <li t-foreach="variant_id.value_ids" t-as="value_id">
+                                                    <label t-attf-style="background-color:#{value_id.color or value_id.name}" t-attf-class="css_attribute_color #{'active' if not inc else ''}">
+                                                    <input type="radio" t-att-checked="'checked' if not inc else ''" t-att-name="'attribute_%s_%s' % (product.id, variant_id.attribute_id.id)" t-att-value="value_id.id" t-att-title="value_id.name" id="product_color"/>
+                                                    </label>
+                                                    <t t-set="inc" t-value="inc+1"/>
+                                                </li>
+                                            </ul>
+                                        </t>
+                                    </div>
+                                </div>
+                            </div>
+                        </t>               
+                        <t t-if="product.product_website_sale_type == True">
+                            <input id="attribute_list" type="hidden" t-att-value="attribute_value_ids"></input>
+                            <input id="product_curva_qty" type="hidden" t-att-value="product.curva"></input>
+                            <div class="container">
+                                <div class="row">
+                                    <div class="col-md-12">
+                                        <t t-if="variant_id.attribute_id.type == 'color'">
+                                            <input id="variant_list_color" type="hidden" t-att-value="variant_id.value_ids"></input>
+                                            <h2 class="panel-title" t-field="variant_id.attribute_id.name"></h2>
+                                            <ul class="list-inline">
+                                                <t t-set="inc" t-value="0"/>
+                                                <li t-foreach="variant_id.value_ids" t-as="value_id">
+                                                    <label t-attf-style="background-color:#{value_id.color or value_id.name}" t-attf-class="css_attribute_color #{'active' if not inc else ''}">
+                                                    <input type="radio" t-att-checked="'checked' if not inc else ''" t-att-name="'attribute_%s_%s' % (product.id, variant_id.attribute_id.id)" t-att-value="value_id.id" t-att-title="value_id.name" id="product_color2"/>
+                                                    </label>
+                                                    <t t-set="inc" t-value="inc+1"/>
+                                                </li>
+                                            </ul>
+                                        </t>
+                                        <t t-if="variant_id.attribute_id.type == 'radio'">
+                                            <input id="variant_list" t-att-value="variant_id.value_ids" type="hidden"></input>
+                                            <div class="panel panel-default">
+                                                <div class="panel-heading">Detalle de Curva</div>
+                                                <div class="panel-body text-center">
+                                                    <h1 class="panel-title" t-field="product.curva"></h1>
+                                                </div>
+                                            </div>
+                                            <h2 class="panel-title" t-field="variant_id.attribute_id.name"></h2>
+                                            <table class="table table-condenced text-center">
+                                                <ul class="list-unstyled">
+                                                    <t t-set="inc" t-value="0"/>
+                                                    <tr>
+                                                        <t t-foreach="variant_id.value_ids" t-as="value_id">
+                                                            <li class="form-group js_attribute_value">
+                                                                <td>
+                                                                    <span t-field="value_id.name"/>
+                                                                </td>
+                                                            </li>
+                                                        <t t-set="inc" t-value="inc+1"/></t>
+                                                    </tr>
+                                                </ul>
+                                            </table>
+                                            <div class="container text-center">
+                                                <button id="curva" class="btn btn-primary" href="">Comprar Curva</button>
+                                            </div>
+                                        </t>
+                                    </div>
+                                </div>
+                            </div>
+                        </t>
+
+                    </li>
+                </t>
+            </xpath>
+        </template>
+
+        <!-- Oculta el boton 'add to cart' por defecto del odoo -->
+        <template id="product_form" inherit_id="kingfisher_pro.kingfisher_pro_product_details" name="product">
+            <xpath expr="//div[@class='add-to-cart']" position="replace">
+                <div class="add-to-cart" style="display:none;">
+                    <a class="btn cart-btn btn-lg js_check_product a-submit" href="#" id="add_to_cart">
+                        <i class="fa fa-shopping-cart"/>Add to Cart</a>
+                </div>
+            </xpath>
+            <xpath expr="//p[@class='css_not_available_msg bg-danger']" position="replace">
+                <p style="display:none;" t-if="len(product.product_variant_ids) &gt; 1">Product not available</p>
+            </xpath>
+        </template>
+    </data>
+</openerp>

+ 28 - 0
view/product_view.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+  <data>
+    <record id="view_product_curve_form" model="ir.ui.view">
+        <field name="name">product.curve.form</field>
+        <field name="model">product.template</field>
+        <field name="inherit_id" ref="product.product_template_only_form_view"/>
+        <field name="arch" type="xml">
+            <div name="options" position="inside">
+                <field name="product_website_sale_type" class="oe_inline"/><label for="product_website_sale_type" string="¿Se vende por curva?"/>
+            </div>
+            <field name="product_curve_id" position="replace"></field>
+            <xpath expr="//notebook/page[@string='Variants']" position="after">
+                <page string="Configurar Curva" attrs="{'invisible': [('product_website_sale_type','=', False)],'required': [('product_website_sale_type','=', True)]}">
+                    <group>
+                        <group>
+                            <field name="product_curve_id" string="Tipo de Curva"/>
+                        </group>
+                        <group>
+                            <field name="curva" string="Configuración de curva" attrs="{'invisible': [('product_website_sale_type','=', False)],'required': [('product_website_sale_type','=', True)]}"/>   
+                        </group> 
+                    </group>
+                </page>
+            </xpath>
+        </field>
+    </record>
+  </data>
+</openerp>