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
3 changes: 3 additions & 0 deletions website_sale_installment/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import models
from . import controllers
from . import wizards
26 changes: 26 additions & 0 deletions website_sale_installment/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
'name': 'Website Sale Card Installment',
'category': 'Website',
'summary': 'Website Sale',
'version': "15.0.1.0.0",
'author': 'ADHOC SA',
'website': 'www.adhoc.com.ar',
'license': 'AGPL-3',
'depends': [
'website',
'website_sale',
'card_installment',
],
'data': [
'views/templates.xml',
'views/account_card.xml',
'wizards/res_config_setting.xml',
],
'assets': {
'web.assets_frontend': [
'website_sale_installment/static/src/js/card_installment.js',
],
},
'installable': True,
'application': False,
}
1 change: 1 addition & 0 deletions website_sale_installment/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
18 changes: 18 additions & 0 deletions website_sale_installment/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
from odoo import http
from odoo.http import request


class WebsiteSale(http.Controller):
@http.route(['/installment_prices'], type='json', auth="public", methods=['POST'], website=True)
def product_installment(self, product_tmpl, product, **post):
product_tmpl_id = request.env['product.template'].browse(int(product_tmpl)).exists()
return product_tmpl_id._website_installment_variant_tree(int(product))

@http.route(['/installment_page/<model("product.template"):product>'], type='http', auth="public", methods=['GET'], website=True)
def page_product_installment(self, product, **post):
render_values = {
'installment_tree': product._website_installment_tree(),
'product_template': product,
}
return request.render("website_sale_installment.product_installment_page", render_values)
3 changes: 3 additions & 0 deletions website_sale_installment/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import product_template
from . import account_card
from . import website
8 changes: 8 additions & 0 deletions website_sale_installment/models/account_card.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from odoo import models


class AccountCard(models.Model):

_inherit = ['account.card', 'website.published.multi.mixin']
_name = 'account.card'

43 changes: 43 additions & 0 deletions website_sale_installment/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from odoo import fields, models


class ProductTemplate(models.Model):

_inherit = 'product.template'

def _website_installment_tree(self):
self.ensure_one()
current_website = self.env['website'].get_current_website()
installment_ids = self.env['account.card.installment'].sudo().search([
('card_id.website_published', '=', True)
])
pricelist = current_website.get_current_pricelist()

context = dict(self.env.context, quantity=1, pricelist=pricelist.id)
product_template = self.with_context(context)
list_price = product_template.price_compute('list_price')[product_template.id]
tax_price = product_template.taxes_id.compute_all(list_price)['total_included']
return installment_ids.card_installment_tree(tax_price)

def _website_installment_variant_tree(self, product_id):
self.ensure_one()
current_website = self.env['website'].get_current_website()
installment_ids = self.env['account.card.installment'].sudo().search([
('card_id.website_published', '=', True)
])
pricelist = current_website.get_current_pricelist()
combination_info = self._get_combination_info(product_id=product_id, add_qty=1, pricelist=pricelist)
return installment_ids.card_installment_tree(combination_info['list_price'])

def _get_combination_info(self, combination=False, product_id=False, add_qty=1, pricelist=False, parent_combination=False, only_template=False):

combination_info = super()._get_combination_info(combination, product_id,
add_qty, pricelist, parent_combination, only_template)
combination_info['installment_price'] = []
if self.env.context.get('website_id'):
website = self.env['website'].get_current_website()
if website.installment_price_ids:
combination_info['installment_price'] = website.installment_price_ids.card_installment_tree(combination_info['price'])

return combination_info

11 changes: 11 additions & 0 deletions website_sale_installment/models/website.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from odoo import fields, models


class Website(models.Model):

_inherit = 'website'

installment_price_ids = fields.Many2many(
'account.card.installment',
string='Installments',
)
82 changes: 82 additions & 0 deletions website_sale_installment/static/src/js/card_installment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
odoo.define('website_sale_installment.installment_popup', function (require) {
'use strict';


var core = require('web.core');
var publicWidget = require('web.public.widget');
const Dialog = require('web.Dialog');
var utils = require('web.utils');
var website_sale_utils = require('website_sale.utils');
var VariantMixin = require('sale.VariantMixin');

var qweb = core.qweb;
var _t = core._t;
publicWidget.registry.installmentPopup = publicWidget.Widget.extend( {
xmlDependencies: ['/website_sale_installment/static/src/xml/card_installment.xml'],
//template: 'website_sale_installment.instalment_popup',
selector: '.js_card',
init: function () {
this._super.apply(this, arguments);
},
events: {
'change .card': '_onChangeCardSelector',
'click .o_installment_button': '_openInstallmentPopUp',
},
_openInstallmentPopUp: function(event){
let product_product_id = document.querySelector('input.product_id').value;
let product_template_id = document.querySelector('input.product_template_id').value;
var self = this;
this._rpc({
route: '/installment_prices',
params: {
product_tmpl: product_template_id,
product: product_product_id,
},
}).then(function (data) {
let content = $(qweb.render('website_sale_installment.instalment_popup', {
installment_tree: data,
_priceToStr: VariantMixin._priceToStr
}));

const dialog = new Dialog(this, {
size: 'medium',
title: "Calcula tus cuotas",
renderFooter: false ,
$content: content ,
});
dialog._opened.then(() => {
let card_selector = dialog.el.querySelector('.o_card_selector');
card_selector.addEventListener('change', function(event){
self._onChangeDialogCardSelector(event, dialog.el);
});
});
dialog.open();

});
},
_onChangeDialogCardSelector : function(event, dialog_element){
let selected_card = event.target.options[event.target.selectedIndex];
let all_installment_list = dialog_element.querySelectorAll('.o_card_list');
for(var i = 0, all = all_installment_list.length; i < all; i++){
all_installment_list[i].classList.add("d-none");
}
if (selected_card.value){
let installment_list = dialog_element.querySelector('#o_card_' + selected_card.value);
if (installment_list) installment_list.classList.remove("d-none");
}

},
_onChangeCardSelector : function(event){
let selected_card = event.target.options[event.target.selectedIndex];
let all_installment_list = this.el.querySelectorAll('.o_card_list');
for(var i = 0, all = all_installment_list.length; i < all; i++){
all_installment_list[i].classList.add("d-none");
}
if (selected_card.value){
let installment_list = this.el.querySelector('#o_card_' + selected_card.value);
installment_list.classList.remove("d-none");
}

},
});
});
32 changes: 32 additions & 0 deletions website_sale_installment/static/src/xml/card_installment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="website_sale_installment.instalment_popup">
<div class="card js_card">
<t t-call="website_sale_installment.instalment_popup_select"/>
<t t-call="website_sale_installment.instalment_popup_list"/>
</div>
</t>
<t t-name="website_sale_installment.instalment_popup_select" >
<div class="form-group">
<select class="form-control form-control-lg o_card_selector">
<option >Seleccione su medio de pago</option>
<option t-att-value="installment_tree[card]['id']" t-foreach="installment_tree" t-as="card"><t t-esc="installment_tree[card]['name']"/></option>
</select>
</div>
</t>
<t t-name="website_sale_installment.instalment_popup_list" >
<ul t-foreach="installment_tree" t-att-id="'o_card_' + installment_tree[card]['id']" t-as="card" class="list-group d-none o_card_list">
<li t-foreach="installment_tree[card]['installments']" t-as="installment" class="list-group-item">
<span t-if="installment['divisor']==1">Un pago de </span>
<span t-elif="typeof(installment['name']) == 'number' &amp;&amp; installment['divisor']>1"><span t-esc="installment['divisor']"/> cuotas de </span>
<span t-elif="typeof(installment['name']) != 'number'"><span t-esc="installment['name']"/> cuotas de </span>
<span t-esc="_priceToStr(installment['amount'] / installment['divisor'])"/>
<i t-if="installment['divisor']>1"> (total
<span t-esc="_priceToStr(installment['amount'])" />
) </i>
</li>
</ul>

</t>

</templates>
27 changes: 27 additions & 0 deletions website_sale_installment/views/account_card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="account_card_tree" model="ir.ui.view">
<field name="name">account_card.tree</field>
<field name="model">account.card</field>
<field name="inherit_id" ref="card_installment.account_card_tree"/>
<field name="arch" type="xml">
<field name="company_id" position="after">
<field name="is_published" string="Show on Website" widget="boolean_toggle"/>
<field name="website_id" groups="website.group_multi_website" domain="['|', ('company_id', '=', company_id), ('company_id', '=', False)]" optional="show"/>
</field>
</field>
</record>
<record id="account_card_form" model="ir.ui.view">
<field name="name">account_card.form</field>
<field name="model">account.card</field>
<field name="inherit_id" ref="card_installment.account_card_form" />
<field name="arch" type="xml">
<field name="company_id" position="after">
<field name="website_id" options="{'no_create': True}" domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]" groups="website.group_multi_website"/>
<field name="is_published" string="Show on Website" widget="boolean_toggle"/>
</field>
</field>
</record>
<menuitem action="card_installment.action_account_card" id="menu_account_card" parent="website_sale.menu_ecommerce_settings" sequence="20" />
<menuitem action="card_installment.action_card_installment" id="menu_account_finacial_plans" parent="website_sale.menu_ecommerce_settings" sequence="21" />
</odoo>
94 changes: 94 additions & 0 deletions website_sale_installment/views/templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="show_installment_prices" name="show installment prices" active="False" customize_show="True" inherit_id="website_sale.product_price" >
<xpath expr="//div/h3[2]" position="after">
<div t-foreach="combination_info['installment_price']" t-as="card">
<t t-foreach="combination_info['installment_price'][card]['installments']" t-as="line">
<div>
<t t-call="website_sale_installment.instalment_render_line">
<t t-set="inst" t-value="line"/>
</t>
</div>
</t>
</div>
</xpath>
</template>
<template id="item_show_installment_prices" name="show installment prices" active="False" customize_show="True" inherit_id="website_sale.products_item">
<xpath expr="//div[hasclass('product_price')]" position="after">
<div t-foreach="combination_info['installment_price']" t-as="card">
<t t-foreach="combination_info['installment_price'][card]['installments']" t-as="line">
<div>
<t t-call="website_sale_installment.instalment_render_line">
<t t-set="inst" t-value="line"/>
</t>
</div>
</t>
</div>
</xpath>
</template>

<template id="show_installment" name="show installment button" active="False" customize_show="True" inherit_id="website_sale.product_price" >
<xpath expr="//div/h3[2]" position="after">
<div class="js_card">
<a href="#" role="button" class="btn btn-primary o_installment_button" t-att-data-product-id="product.id" aria-label="Show installment price" title="Show installment price">
<span class="fa fa-credit-card"/> Calcula tus cuotas
</a>
</div>
</xpath>
</template>
<template id="show_installment_info" name="show installment Info" active="False" customize_show="True" inherit_id="website_sale.product" >
<xpath expr="//div[@id='product_attributes_simple']" position="before">
<div class="js_card">
<t t-set="installment_tree" t-value="product._website_installment_tree()"/>
<t t-call="website_sale_installment.product_installment_form"/>
</div>
</xpath>
</template>
<template id="product_installment_page" name="Intallment form">
<t t-call="website.layout">
<t t-set="additional_title">Shop</t>
<div id="wrap" class="js_card">
<t t-call="website_sale_installment.product_installment_form"/>
</div>
</t>
</template>
<template id="product_installment_form" name="Intallment form">
<div class="card">
<div class="card-body">
<h5 class="card-title">Calcula tus cuotas</h5>
</div>
<t t-call="website_sale_installment.instalment_select"/>
<t t-call="website_sale_installment.instalment_list"/>
</div>
</template>
<template id="instalment_select">
<div class="form-group">
<select class="form-control form-control-lg o_card_selector">
<option >Seleccione su medio de pago</option>
<option t-att-value="installment_tree[card]['id']" t-foreach="installment_tree" t-as="card"><t t-esc="installment_tree[card]['name']"/></option>
</select>
</div>
</template>
<template id="instalment_list">
<ul t-foreach="installment_tree" t-att-id="'o_card_%s' % installment_tree[card]['id']" t-as="card" class="list-group d-none o_card_list">
<li t-foreach="installment_tree[card]['installments']" t-as="installment" class="list-group-item">
<span t-if="installment['name'].isnumeric() and installment['divisor']==1">Un pago de </span>
<span t-elif="installment['name'].isnumeric() and installment['divisor']>1"><span t-esc="installment['divisor']"/> cuotas de </span>
<span t-elif="not installment['name'].isnumeric()"><span t-esc="installment['name']"/> cuotas de </span>
<span t-esc="installment['amount'] / installment['divisor']" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"/>
<i t-if="installment['divisor']>1"> (total
<span t-esc="installment['amount']" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"/>
) </i>
</li>
</ul>
</template>
<template id="instalment_render_line">
<span t-if="inst['name'].isnumeric() and inst['divisor']==1">Un pago de </span>
<span t-elif="inst['name'].isnumeric() and inst['divisor']>1"><span t-esc="inst['divisor']"/> cuotas de </span>
<span t-elif="not inst['name'].isnumeric()"><span t-esc="inst['name']"/> cuotas de </span>
<span t-esc="inst['amount'] / inst['divisor']" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"/>
<i t-if="inst['divisor']>1"> (total
<span t-esc="inst['amount']" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"/>
) </i>
</template>
</odoo>
1 change: 1 addition & 0 deletions website_sale_installment/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_config_settings
29 changes: 29 additions & 0 deletions website_sale_installment/wizards/res_config_setting.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.website.sale</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="website.res_config_settings_view_form"/>
<field name="arch" type="xml">
<div id="webmaster_settings" position="after">
<div id="webmaster_settings" position="after">
<h2>Prices</h2>
<div class="row mt16 o_settings_container" id="sale_pricing_settings">
<div class="col-12 col-lg-6 o_setting_box" id="price_id_setting">
<div class="o_setting_right_pane">
<label for="installment_price_ids" string="Installment price"/>
<div class="text-muted">Installment price
</div>
<div class="content-group">
<div class="mt16">
<field name="installment_price_ids" widget="many2many_tags"/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</field>
</record>
</odoo>
Loading