Browse Source

Agregar calculo semanal y quincenal

sebas 4 years ago
commit
297469a7b9

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+*.pyc

+ 2 - 0
__init__.py

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

+ 25 - 0
__openerp__.py

@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+{
+    'name' : 'Eiru Payment Term Configurator',
+    'version' : '2.1',
+    'description' : """
+    """,
+    'author' : 'Eiru/Adrielso Kunert Bueno',
+    'category' : 'sale',
+    'depends' : [
+        'sale',
+        'account',
+        'currency_utility',
+    ],
+    'data' : [
+        'security/ir.model.access.csv',
+        'views/template.xml',
+        'views/views.xml',
+        'views/account_payment_term_type.xml',
+        'views/account_payment_term_config.xml',
+    ],
+    'qweb' : [
+        'static/src/xml/*.xml',
+        'static/src/xml/modal/*.xml'
+    ]
+}

+ 6 - 0
models/__init__.py

@@ -0,0 +1,6 @@
+# -*- coding: utf-8 -*-
+import payment_term_configurator
+import account_payment_term_type
+import accont_payments_term_config
+import sale_order_term_configurator
+import purchase_order_term_configurator

+ 34 - 0
models/accont_payments_term_config.py

@@ -0,0 +1,34 @@
+# -*- coding: utf-8 -*-
+from openerp import models, fields, tools, api
+import openerp.addons.decimal_precision as dp
+
+class AccontPaymentsTermConfig(models.Model):
+    _name = 'accont.payments.term.config'
+
+    name = fields.Char('Name', required=True, readonly=True)
+    interest_rate = fields.Float('Tasa de interés', digits=(3,6), digits_compute=dp.get_precision('Interest'), required=True, help="Tasa de interés %")
+    message_default = fields.Char('Message', default='La tasa de interés por defecto es 4% mensual, tasa diaria (4 / 30 = 0,1333).')
+    compute =  fields.Boolean(help="Indica si sera calculado los interés")
+    comment = fields.Text('Comment', help="Información adicional")
+
+    @api.model
+    def _create_default_config(self):
+        config = {
+            'name': 'Interés por cambio de fecha de cuota',
+            'interest_rate': '0.1333',
+            'compute': True,
+        }
+
+        termConfig = self.env['accont.payments.term.config'].search([('name','=', config['name'])])
+        if (not termConfig):
+            self.env['accont.payments.term.config'].create({
+                'name':  config['name'],
+                'interest_rate': config['interest_rate'],
+                'compute': config['compute'],
+            })
+
+
+class SaleOrderLineInterest(models.Model):
+    _inherit = 'sale.order.line'
+
+    is_interest =  fields.Boolean('Is Interest',default=False)

+ 41 - 0
models/account_payment_term_type.py

@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+
+from openerp import models, fields, tools, api
+
+class 	AccountPaymentTermType(models.Model):
+    _name = 'account.payment.term.type'
+
+    name = fields.Char('name')
+    comment = fields.Text('comment')
+    qty_add = fields.Integer('incrementar', help="Indica la cantidad que sera incrementada a la fecha.")
+    type_calculation = fields.Selection([('day', 'Día'),('month','Mes'),('semanal','Semanal'),('quincenal','Quincenal')], default='day', help='Indica la forma que  sera incrementado la fecha  de las cuotas.')
+
+    @api.model
+    def _create_default_type_term(self):
+        term = [
+            {
+                'name': 'Días',
+                'qty_add': 1,
+                'type_calculation': 'day',
+            },{
+                'name': 'Meses',
+                'qty_add': 1,
+                'type_calculation': 'month',
+            },{
+                'name': 'Semanal',
+                'qty_add': 7,
+                'type_calculation': 'semanal',
+            },{
+                'name': 'Quincenal',
+                'qty_add': 15,
+                'type_calculation': 'quincenal',
+            }
+        ]
+        for termDefault in term:
+            paymentTerm = self.env['account.payment.term.type'].search([('name', '=', termDefault['name'])])
+            if (not paymentTerm):
+                    self.env['account.payment.term.type'].create({
+                        'name': termDefault['name'],
+                        'qty_add': termDefault['qty_add'],
+                        'type_calculation': termDefault['type_calculation'],
+                    })

+ 13 - 0
models/payment_term_configurator.py

@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+from openerp import api, fields, models
+from openerp.exceptions import except_orm
+from datetime import datetime, timedelta
+from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
+from dateutil.relativedelta import relativedelta
+
+class AccountPaymentTerm(models.Model):
+	_inherit = 'account.payment.term'
+
+	config = fields.Boolean(default='False')
+	type_operation = fields.Selection([('all', 'Todo'),('sale','Venta'),('purchase', 'Compra')],'Tipo de operacion', default='all', help='Define si el plazo de pago puede sera utilizado por Ventas, Compras o Todos')
+	user_term = fields.Many2one('res.users', 'user')

+ 145 - 0
models/purchase_order_term_configurator.py

@@ -0,0 +1,145 @@
+# -*- coding: utf-8 -*-
+from openerp import api, fields, models
+from openerp.exceptions import except_orm
+from datetime import datetime, timedelta
+from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
+from dateutil.relativedelta import relativedelta
+
+class PurchaseOrder (models.Model):
+	_inherit = 'purchase.order'
+
+	date_quota = fields.Date("Fecha de la primera cuota")
+
+	def sale_convert_str_to_datetime(self, date):
+		return datetime.strptime(date, DEFAULT_SERVER_DATE_FORMAT)
+
+	''' Get Purchase '''
+	@api.model
+	def getPurchaseOrder(self,idOrder):
+		return[{
+			'id': order.id,
+			'amountTotal': order.amount_total,
+			'dateOrder': order.date_order.split(" ")[0],
+			'dateQuota': order.date_quota or order.date_order.split(" ")[0],
+			'currency': {
+				'id': order.pricelist_id.currency_id.id,
+				'symbol': order.pricelist_id.currency_id.symbol,
+				'decimalSeparator': order.pricelist_id.currency_id.decimal_separator,
+				'decimalPlaces': order.pricelist_id.currency_id.decimal_places,
+				'thousandsSeparator': order.pricelist_id.currency_id.thousands_separator,
+			}
+		} for order in self.env['purchase.order'].browse(idOrder)]
+
+	''' CALCULATOR '''
+	@api.model
+	def calculatePaymentTermPurchaseOrder(self, values):
+		order = self.env['purchase.order'].browse(values['orderId'])
+
+		if (not order):
+			return False
+
+		dateSale = self.sale_convert_str_to_datetime(order.date_order.split(" ")[0])
+		datefirst = self.sale_convert_str_to_datetime(order.date_quota or order.date_order.split(" ")[0])
+
+		amountTotal = order.amount_total
+		amountPayments  = values['amountPayments']
+		amountResidual = amountTotal - amountPayments
+		cuotaCant = (amountResidual /values['amountCuota'])
+
+		if (amountPayments > 0):
+			cuotaCant +=1
+
+		termCalculator = []
+		cuotaTotal= int(cuotaCant) if ((cuotaCant - int(cuotaCant)) <= 0) else int(cuotaCant)+1
+		termType = self.env['account.payment.term.type'].browse(values['typeTerm'])
+		if (not termType):
+			return False
+
+		numberCuota = 0
+		for cuota in xrange(int(cuotaCant)):
+			numberCuota = cuota+1
+			amount = values['amountCuota']
+			adddaysMaturity = datefirst - dateSale
+			date = datefirst
+
+			if (numberCuota == 1 and (amountPayments > 0)):
+				amount = amountPayments
+				if (adddaysMaturity.days > 0):
+					adddaysMaturity = dateSale - dateSale
+				date = dateSale
+
+			amountTotal -= amount
+			termCalculator.append({
+				'number' : numberCuota,
+				'cuotaNumber': str(numberCuota)+"/"+str(cuotaTotal),
+				'date': date.strftime(DEFAULT_SERVER_DATE_FORMAT),
+				'amount': amount,
+				'days': adddaysMaturity.days,
+				'value': 'fixed' if (numberCuota < cuotaTotal) else 'balance'
+			})
+
+			days = datefirst - dateSale
+			if(numberCuota == 1 and (amountPayments > 0) and days.days > 0 ):
+				continue
+
+			if (termType.type_calculation == 'month' ):
+				datefirst += relativedelta(months=termType.qty_add)
+			else :
+				datefirst += timedelta(days=termType.qty_add)
+
+
+		if (amountTotal > 0 ):
+			numberCuota +=1
+			adddaysMaturity = datefirst - dateSale
+
+			termCalculator.append({
+				'number' : numberCuota,
+				'cuotaNumber': str(numberCuota)+"/"+str(cuotaTotal),
+				'date': datefirst.strftime(DEFAULT_SERVER_DATE_FORMAT),
+				'amount': amountTotal,
+				'days': adddaysMaturity.days,
+				'value': 'fixed' if (numberCuota < cuotaTotal) else 'balance'
+			})
+
+		return termCalculator
+
+	''' Config Term '''
+	@api.model
+	def accountPaymentTermConfigurator(self, values, orderId):
+		resUser = self.env.user
+		if (not resUser):
+			return {
+				'state': False,
+				'message': 'No fue posible localizar el usuario.'
+			}
+
+		term = self.env['account.payment.term'].search([('config', '=', True),('user_term', '=', resUser.id),('type_operation', '=', 'purchase')])
+		if (term):
+			term.unlink()
+
+		line = []
+		for configTerm in values:
+			line.append([0,False,{
+				'payment_id': term.id,
+				'value': configTerm['value'],
+				'days': configTerm['days'],
+				'value_amount': - configTerm['amount'] if (configTerm['value'] == 'fixed') else  0
+			}])
+
+		term = self.env['account.payment.term'].create({
+			'name': 'Plazos Configurables %s - %s'%('Compras', resUser.name),
+			'type_operation': 'purchase',
+			'user_term': resUser.id,
+			'config': True,
+			'line_ids': line,
+		})
+
+		''' Actualizar condiciones de pago en la purchase '''
+		order = self.env['purchase.order'].browse(orderId)
+		if (order):
+			order.write({'payment_term_id': term.id})
+
+		return {
+			'state': True,
+			'message': 'Condiciones de pago configurado con éxito'
+		}

+ 229 - 0
models/sale_order_term_configurator.py

@@ -0,0 +1,229 @@
+# -*- coding: utf-8 -*-
+from openerp import api, fields, models
+from openerp.exceptions import except_orm
+from datetime import datetime, timedelta
+from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
+from dateutil.relativedelta import relativedelta
+
+class SaleOrder(models.Model):
+	_inherit = 'sale.order'
+
+	date_quota = fields.Date("Fecha de la primera cuota")
+
+	def sale_convert_str_to_datetime(self, date):
+		return datetime.strptime(date, DEFAULT_SERVER_DATE_FORMAT)
+
+	@api.model
+	def getSaleOrder(self,idOrder):
+		return[{
+			'id': order.id,
+			'amountTotal': order.amount_total,
+			'dateOrder': order.date_order.split(" ")[0],
+			'dateQuota': order.date_quota or order.date_order.split(" ")[0],
+			'currency': {
+				'id': order.pricelist_id.currency_id.id,
+				'symbol': order.pricelist_id.currency_id.symbol,
+				'decimalSeparator': order.pricelist_id.currency_id.decimal_separator,
+				'decimalPlaces': order.pricelist_id.currency_id.decimal_places,
+				'thousandsSeparator': order.pricelist_id.currency_id.thousands_separator,
+			}
+		} for order in self.env['sale.order'].browse(idOrder)]
+
+	@api.model
+	def getSaleOrderInterest(self,idOrder):
+		termConfig = self.env['accont.payments.term.config'].search([('compute', '=', True)])
+		if (not termConfig):
+			return []
+
+		saleOrder = self.env['sale.order'].browse(idOrder)
+		if (not saleOrder):
+			return []
+		dateSale = self.sale_convert_str_to_datetime(saleOrder.date_order.split(" ")[0])
+		datefirst = self.sale_convert_str_to_datetime(saleOrder.date_quota or saleOrder.date_order.split(" ")[0])
+		daysDiference = datefirst - dateSale
+
+		orderLine = self.env['sale.order.line'].search([('order_id', '=', idOrder),('is_interest','=',True)])
+		amountInteres = orderLine.price_subtotal or 0
+
+		return [{
+			'id': order.id,
+			'amountTotal': (order.amount_total - amountInteres),
+			'dateOrder': order.date_order.split(" ")[0],
+			'dateQuota': order.date_quota or order.date_order.split(" ")[0],
+			'amountInteres': round(daysDiference.days * ((order.amount_total - amountInteres) * (termConfig.interest_rate / 100)),order.pricelist_id.currency_id.decimal_places),
+			'differenceDay': daysDiference.days,
+			'messageDefault': termConfig.message_default,
+			'currency': {
+				'id': order.pricelist_id.currency_id.id,
+				'symbol': order.pricelist_id.currency_id.symbol,
+				'decimalSeparator': order.pricelist_id.currency_id.decimal_separator,
+				'decimalPlaces': order.pricelist_id.currency_id.decimal_places,
+				'thousandsSeparator': order.pricelist_id.currency_id.thousands_separator,
+			}
+		} for order in saleOrder]
+
+	''' Discount '''
+	@api.model
+	def account_Sale_line_add_discount(self,idOrder, newAmount):
+		saleOrder = self.env['sale.order'].browse(idOrder)
+		if (not saleOrder):
+			return {'state': False }
+
+		discount = abs(saleOrder.amount_total - newAmount)
+
+		discountLine = {
+			'order_id': saleOrder.id,
+			'name':"DESCUENTO APLICADO",
+			'price_unit': - discount,
+			'price_subtotal': - discount,
+		}
+
+		line = self.env['sale.order.line'].create(discountLine)
+		if (not line):
+			return { 'state': False }
+
+		return { 'state': True }
+
+
+	''' Interest '''
+	@api.model
+	def account_sale_line_interest(self, values):
+		interestLine = {
+			'order_id': values['saleId'],
+			'name':"Cambio de fecha de vencimiento, Diferencia("+str(values['differenceDay'])+") días.",
+			'price_unit':values['amountInteres'],
+			'price_subtotal':values['amountInteres'],
+			'is_interest': True
+		}
+
+		saleLine = self.env['sale.order.line'].search([('order_id', '=', values['saleId']),('is_interest','=',True)])
+
+		if (not saleLine):
+			if (values['amountInteres'] <= 0):
+				return { 'state': True }
+
+			saleLine.create(interestLine)
+			return { 'state': True }
+
+		if (values['amountInteres'] <= 0):
+			saleLine.unlink()
+			return { 'state': True }
+
+		saleLine.write(interestLine)
+		return { 'state': True }
+
+	@api.model
+	def calculatePaymentTermSaleOrder(self, values):
+		order = self.env['sale.order'].browse(values['orderId'])
+
+		if (not order):
+			return False
+
+		dateSale = self.sale_convert_str_to_datetime(order.date_order.split(" ")[0])
+		datefirst = self.sale_convert_str_to_datetime(order.date_quota or order.date_order.split(" ")[0])
+
+		amountTotal = order.amount_total
+		amountPayments  = values['amountPayments']
+		amountResidual = amountTotal - amountPayments
+		cuotaCant = (amountResidual /values['amountCuota'])
+
+		if (amountPayments > 0):
+			cuotaCant +=1
+
+		termCalculator = []
+
+		cuotaTotal= int(cuotaCant) if ((cuotaCant - int(cuotaCant)) <= 0) else int(cuotaCant)+1
+
+		termType = self.env['account.payment.term.type'].browse(values['typeTerm'])
+		if (not termType):
+			return False
+
+		numberCuota = 0
+		for cuota in xrange(int(cuotaCant)):
+			numberCuota = cuota+1
+			amount = values['amountCuota']
+			adddaysMaturity = datefirst - dateSale
+			date = datefirst
+
+			if (numberCuota == 1 and (amountPayments > 0)):
+				amount = amountPayments
+				if (adddaysMaturity.days > 0):
+					adddaysMaturity = dateSale - dateSale
+				date = dateSale
+
+			amountTotal -= amount
+
+			termCalculator.append({
+				'number' : numberCuota,
+				'cuotaNumber': str(numberCuota)+"/"+str(cuotaTotal),
+				'date': date.strftime(DEFAULT_SERVER_DATE_FORMAT),
+				'amount': amount,
+				'days': adddaysMaturity.days,
+				'value': 'fixed' if (numberCuota < cuotaTotal) else 'balance'
+			})
+
+			days = datefirst - dateSale
+			if(numberCuota == 1 and (amountPayments > 0) and days.days > 0 ):
+				continue
+
+			if (termType.type_calculation == 'month' ):
+				datefirst += relativedelta(months=termType.qty_add)
+			else :
+				datefirst += timedelta(days=termType.qty_add)
+
+		if (amountTotal > 0 ):
+			numberCuota +=1
+			adddaysMaturity = datefirst - dateSale
+
+			termCalculator.append({
+				'number' : numberCuota,
+				'cuotaNumber': str(numberCuota)+"/"+str(cuotaTotal),
+				'date': datefirst.strftime(DEFAULT_SERVER_DATE_FORMAT),
+				'amount': amountTotal,
+				'days': adddaysMaturity.days,
+				'value': 'fixed' if (numberCuota < cuotaTotal) else 'balance'
+			})
+
+		return termCalculator
+
+	''' Payments Term '''
+	@api.model
+	def accountPaymentTermConfiguratorSale(self, values, orderId):
+		resUser = self.env.user
+		if (not resUser):
+			return {
+				'state': False,
+				'message': 'No fue posible localizar el usuario.'
+			}
+
+		term = self.env['account.payment.term'].search([('config', '=', True),('user_term', '=', resUser.id),('type_operation', '=', 'sale')])
+		if (term):
+			term.unlink()
+
+		line = []
+		for configTerm in values:
+			line.append([0,False,{
+				'payment_id': term.id,
+				'value': configTerm['value'],
+				'days': configTerm['days'],
+				'value_amount': configTerm['amount'] if (configTerm['value'] == 'fixed') else  0
+			}])
+
+		term = self.env['account.payment.term'].create({
+			'name': 'Plazos Configurables %s - %s'%('Ventas', resUser.name),
+			'type_operation': 'sale',
+			'user_term': resUser.id,
+			'config': True,
+			'line_ids': line,
+		})
+
+		''' Actualizar condiciones de pago en la venta '''
+
+		order = self.env['sale.order'].browse(orderId)
+		if (order):
+			order.write({'payment_term': term.id})
+
+		return {
+			'state': True,
+			'message': 'Condiciones de pago configurado con éxito'
+		}

+ 3 - 0
security/ir.model.access.csv

@@ -0,0 +1,3 @@
+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
+account_payment_term_type_from,account.payment.term.type,model_account_payment_term_type,base.group_sale_manager,1,1,1,1
+accont_payments_term_config_from,accont.payments.term.config,model_accont_payments_term_config,base.group_sale_manager,1,1,1,1

BIN
static/description/icon.png


+ 136 - 0
static/src/css/style.css

@@ -0,0 +1,136 @@
+@media (min-width: 768px){
+    .expired-account-modal .modal-lg {
+        width: 800px !important;
+    }
+}
+.widget-content.widget-loading-term-configurator {
+    position: absolute;
+    width: 100%;
+    height: 100%;
+    color : #000;
+    display: none;
+    z-index: 1100;
+    background: #8080806b;
+    align-items: center;
+    justify-content: center;
+}
+.payment_term_configurator{
+    float: left;
+    margin-right: 10px;
+}
+.button-action-term{
+    float: left;
+    margin-right: 10px !important;
+}
+.term-configurator-header {
+    font-size: 12pt;
+    padding-bottom: 10px;
+    padding-top: 10px;
+}
+.term-configurator-from-label {
+    width: 150px;
+    height: 30px;
+    font-size: 14px;
+    padding-top: 5px;
+    padding-left: 5px;
+}
+.term-configurator-from-group-input {
+    width: calc(100% - 150px);
+    height: 30px;
+    padding-left: 5px;
+    padding-right: 5px;
+    float: right;
+}
+.term-configurator-input-currency {
+    width: calc(100% - 30px);
+    height: 30px;
+    float: left;
+    font-size: 12pt;
+    text-align: right;
+}
+.term-configurator-symbol-currency{
+    width: 30px;
+    height: 30px;
+    float: right;
+    text-align: center;
+    font-size: 16pt;
+    border: 1px solid #ccc;
+    background: #e3e3e3;
+}
+/* bottom CALCULAR */
+.term-configurator-button-calculator{
+    margin-left: 30px !important;
+    margin-top: 10px !important;
+    margin-bottom: 10px !important;
+}
+/*____________ TABLE _____________*/
+ .term-configurator-table {
+     margin-top: 0px !important;
+ }
+.expired-account-modal .modal-head-wrapper-term-configurator {
+     width: 100%;
+}
+.expired-account-modal .modal-item-term-configurator {
+    width: 100%;
+    height: 246px;
+    overflow-y: auto;
+}
+
+/* Table Header */
+.expired-account-modal .term-configurator-table table thead tr {
+    height: 40px !important;
+}
+.expired-account-modal .term-configurator-table table thead tr th:nth-child(1){
+    width: 137px;
+    text-align: center;
+    font-size: 12pt;
+    font-weight: bold;
+}
+.expired-account-modal .term-configurator-table table thead tr th:nth-child(2){
+    width: 300px;
+    font-size: 12pt;
+    font-weight: bold;
+}
+.expired-account-modal .term-configurator-table table thead tr th:nth-child(3){
+    width: 300px;
+    font-size: 12pt;
+    font-weight: bold;
+}
+
+/* TBODY */
+.expired-account-modal .term-configurator-table table tbody tr {
+    height: 35px;
+}
+ .expired-account-modal .term-configurator-table table tbody tr td:nth-child(1) {
+    width: 137px;
+    font-size: 12pt;
+    padding-left: 10px;
+    padding-top: 8px;
+    text-align: center;
+}
+
+.expired-account-modal .term-configurator-table table tbody tr td:nth-child(2) {
+    width: 294px;
+    font-size: 12pt;
+    padding-left: 10px;
+    padding-top: 8px;
+}
+.expired-account-modal .term-configurator-table table tbody tr td:nth-child(3) {
+    width: 279px;
+    font-size: 12pt;
+    padding-right: 25px;
+    padding-top: 8px;
+    text-align: right;
+}
+/*---------------------
+        Button
+------------------------*/
+.term-configurator-footer {
+    padding-top: 10px;
+    padding-bottom: 10px;
+}
+.term-configurator-button {
+    font-size: 12pt !important;
+    width: 130px;
+    height: 35px;
+}

+ 333 - 0
static/src/js/eiru_payment_term_configurator.js

@@ -0,0 +1,333 @@
+(function() {
+
+    openerp.widgetInstancePaymentTermConfigurator = null;
+    openerp.parentInstancePaymentTermConfigurator = null;
+    var Qweb = openerp.web.qweb;
+    var instance = openerp;
+    var instanceWeb = openerp.web;
+
+    openerp.PaymentTermConfigurator = instance.Widget.extend({
+        template: 'eiruPaymentTerm.Configurator',
+        id: undefined,
+
+        saleOrder: [],
+        calculatorTerm: [],
+        termType: [],
+
+        init: function(parent) {
+            this._super(parent);
+            this.buttons = parent.$buttons;
+        },
+        start: function() {
+            var self = this;
+
+            this.$el.click(function(){
+                self.fectchInitial();
+            });
+            self.buttons.click(function(e) {
+                /* E (Editar) */
+                if (e.target.accessKey === 'E')
+                    self.$el.css('display','none');
+                /* S (Guarrdar) */
+                if (e.target.accessKey === 'S')
+                    self.$el.css('display','flex');
+                /* D (Cancelar) */
+                if (e.target.accessKey === 'D')
+                    self.$el.css('display','flex');
+                /* CREAR */
+                if (e.target.accessKey === 'C')
+                    self.$el.css('display','none');
+            });
+        },
+
+        updateId: function(id) {
+            var self = this;
+            self.id = id;
+
+            self.$el.css('display','flex');
+            if (!id)
+                self.$el.css('display','none');
+        },
+        /* Remover */
+        removeModal: function() {
+            $('.expired-account-modal').remove();
+            $('.modal-backdrop').remove();
+        },
+        /* Reloada */
+        reloadPage: function() {
+            openerp.parentInstancePaymentTermConfigurator.reload();
+        },
+        /* Metodo Inicial */
+        fectchInitial: function() {
+            var self = this;
+
+            self.fetchSaleOrder().then(function(saleOrder) {
+                return saleOrder;
+            }).then(function(saleOrder) {
+                self.saleOrder = saleOrder;
+                return self.fetchTypeTerm();
+            }).then(function(termType) {
+                self.termType = termType;
+                return self.showTaskSelected();
+            });
+        },
+        /* Get SALE ORDER */
+        fetchSaleOrder: function() {
+            var self = this;
+            var order = new openerp.web.Model('sale.order');
+            return order.call('getSaleOrder',[self.id],{
+                context: new openerp.web.CompoundContext()
+            });
+        },
+        /* GET  Tipo de condicion de pagos  */
+        fetchTypeTerm: function() {
+            var typeTerm = new openerp.web.Model('account.payment.term.type');
+            return typeTerm.query(['id','name']).all()
+        },
+        /* Modal */
+        showTaskSelected: function() {
+            var self = this;
+            var defer = $.Deferred();
+            var state = true;
+            /*Curency Order*/
+            var saleOrder = self.saleOrder[0];
+            var currencyOrder = saleOrder.currency;
+            /*term type */
+            var typeTerm = self.termType;
+
+            if (!typeTerm.length){
+                instanceWeb.notification.do_warn("Atencion", "No existe tipo de condiciones de pagos.");
+                return ;
+            }
+            typeTerm.unshift({"id": '', 'name': ''})
+
+            /* Modal */
+            var modal = Qweb.render('eiruPaymentTerm.ModalConfigurator', {'termTypes':typeTerm});
+            $('.openerp_webclient_container').after(modal);
+            $('.expired-account-modal').modal();
+
+
+            var amountSale = $('.expired-account-modal').find('.amount-sale');
+            var symbolCurrency = $('.expired-account-modal').find('.symbol-currency');
+
+            var initialpayments = $('.expired-account-modal').find('.initial-payments-amount');
+            var amountResidual = $('.expired-account-modal').find('.amount-residual');
+
+            var dateSale = $('.expired-account-modal').find('.date-sale');
+            var dateQuota = $('.expired-account-modal').find('.date-quota');
+            var typeTerm = $('.expired-account-modal').find('.term-select');
+            var amountQuota = $('.expired-account-modal').find('.amount-quota');
+            /* Bottom Calcular */
+            var bottomCalcular = $('.expired-account-modal').find('.bt-calular');
+            /* table */
+            var tableRow = $('.expired-account-modal').find('.table-tbody');
+            /*Bottom Guardar */
+            buttonAccept = $('.expired-account-modal').find('.button-accept');
+            /* Value initial */
+            amountSale.val(instanceWeb.formatCurrency(saleOrder.amountTotal, currencyOrder));
+            amountResidual.val(instanceWeb.formatCurrency(saleOrder.amountTotal, currencyOrder));
+
+            symbolCurrency.text(currencyOrder.symbol);
+            dateSale.val(moment(saleOrder.dateOrder).format('DD/MM/YYYY'));
+            dateQuota.val(moment(saleOrder.dateQuota).format('DD/MM/YYYY'));
+
+            /*******************************
+            *  FOCUSIN initialpayments     *
+            *******************************/
+            initialpayments.focusin(function(e){
+                var amount = instanceWeb.unFormatCurrency(initialpayments.val());
+                if (amount === 0)
+                    initialpayments.val('');
+            });
+            /****************************
+            *   KEYUP initialpayments   *
+            ****************************/
+            initialpayments.keyup(function(e) {
+                var amountPayments = instanceWeb.unFormatCurrency(initialpayments.val());
+                var saleAmount = instanceWeb.unFormatCurrency(amountSale.val());
+
+                if (e.key === currencyOrder.decimalSeparator && currencyOrder.decimalPlaces > 0)
+                    return false ;
+
+                initialpayments.val(instanceWeb.formatCurrency(amountPayments, currencyOrder));
+                amountResidual.val(instanceWeb.formatCurrency((saleAmount - amountPayments), currencyOrder))
+
+            });
+            /********************************
+            *    FOCUS OUT initialpayments  *
+            ********************************/
+            initialpayments.focusout(function(e) {
+                var saleAmount = instanceWeb.unFormatCurrency(amountSale.val());
+                var amount = instanceWeb.unFormatCurrency(initialpayments.val());
+
+                if (amount > saleAmount) {
+                    instanceWeb.notification.do_warn("Atencion", "El valor de la entrega supera el valor de la venta.");
+                    initialpayments.focus();
+                    return false;
+                }
+                amountResidual.val(instanceWeb.formatCurrency((saleAmount - amount), currencyOrder))
+            });
+            /*--------------------------
+                FOCUSIN amountQuota
+            ----------------------------*/
+            amountQuota.focusin(function(e) {
+                var amount = instanceWeb.unFormatCurrency( amountQuota.val());
+                if (amount === 0)
+                     amountQuota.val('');
+            });
+            /*-----------------------
+                KEYUP amountQuota
+            ------------------------*/
+            amountQuota.keyup(function(e) {
+                if (e.key === currencyOrder.decimalSeparator && currencyOrder.decimalPlaces > 0)
+                    return false ;
+
+                cuotaAmount = instanceWeb.unFormatCurrency(amountQuota.val());
+                amountQuota.val(instanceWeb.formatCurrency(cuotaAmount, currencyOrder));
+            });
+            /*---------------------------
+                FOCUS OUT amountQuota
+            ----------------------------*/
+            amountQuota.focusout(function(e) {
+                var saleAmount = instanceWeb.unFormatCurrency(amountSale.val());
+                var amountPayments = instanceWeb.unFormatCurrency(initialpayments.val());
+                var amount = instanceWeb.unFormatCurrency(amountQuota.val());
+
+                if (amount <= 0) {
+                    instanceWeb.notification.do_warn("Atencion", "El valor de la cuota debe de ser mayor que cero.");
+                    amountQuota.focus();
+                    return false;
+                }
+
+                if (amount > (saleAmount - amountPayments)) {
+                    instanceWeb.notification.do_warn("Atencion", "El valor de la cuota no puede superar el valor total de la venta.\nVenta ="+saleAmount+"\nEntrega ="+amountPayments+"\nCuota = "+amount);
+                    amountQuota.focus();
+                    return false;
+                }
+            });
+            /*-------------------
+                CLICK CALCULAR
+            ---------------------*/
+            bottomCalcular.click(function(e) {
+                tableRow.find('tr').remove();
+                var htmlLine = '';
+                var cuotaAmount = instanceWeb.unFormatCurrency(amountQuota.val());
+                var amountPayments = instanceWeb.unFormatCurrency(initialpayments.val());
+                /* */
+                if(!typeTerm.val()) {
+                    instanceWeb.notification.do_warn("Atencion", "Debes de Seleccionar el tipo de plazo de pago.");
+                    typeTerm.focus();
+                    return;
+                }
+                /* */
+                if (cuotaAmount <= 0) {
+                    instanceWeb.notification.do_warn("Atencion", "El valor de la cuota debe de ser mayor que cero.");
+                    amountQuota.focus();
+                    return;
+                }
+
+                var termSale = {
+                    'orderId': self.id,
+                    'typeTerm': parseInt(typeTerm.val().trim()),
+                    'amountCuota': cuotaAmount,
+                    'amountPayments': amountPayments,
+                }
+
+                /* GENERAR LA LISTA DE CUOTA */
+                $('.expired-account-modal').find('.widget-content.widget-loading-term-configurator').css('display','flex');
+                self.calculatePaymentTerm(termSale).then(function(calculatorTerm) {
+                    return calculatorTerm;
+                }).then(function(calculatorTerm) {
+                    self.calculatorTerm = calculatorTerm;
+                    $('.expired-account-modal').find('.widget-content.widget-loading-term-configurator').css('display','none');
+                    if (!!calculatorTerm.length) {
+                        _.each(calculatorTerm, function(line) {
+                           var dateMaturity = moment(line.date).format('DD/MM/YYYY');
+                           var amount = instanceWeb.formatCurrency(line.amount, currencyOrder) +" "+currencyOrder.symbol;
+                            htmlLine +='<tr><td><span>'+line.cuotaNumber+'</span></td><td><span>'+dateMaturity+'</span></td><td><span>'+amount+'</span></td></tr>';
+                        })
+                        tableRow.append(htmlLine);
+                    }
+                });
+            });
+            /*----------------------
+                ACEPTAR / GUARDAR
+            ----------------------*/
+            buttonAccept.click(function(e) {
+                if (!self.calculatorTerm.length) {
+                    instanceWeb.notification.do_warn("Atencion", "Debes de calcular las cuota antes de guardar.");
+                    return ;
+                }
+
+                $('.expired-account-modal').find('.widget-content.widget-loading-term-configurator').css('display','flex');
+                self.accountPaymentTermConfigurator(self.calculatorTerm, self.id).then(function(termConfigurator) {
+                    return termConfigurator;
+                }).then(function(termConfigurator) {
+                    $('.expired-account-modal').find('.widget-content.widget-loading-term-configurator').css('display','none');
+                    self.removeModal(e);
+                    state = termConfigurator.state;
+                    self.reloadPage();
+                });
+
+                defer.resolve(state);
+            });
+            /*-----------
+                CERRAR
+            -----------*/
+            $('.expired-account-modal').on('hidden.bs.modal', function (e) {
+                defer.resolve(false);
+                self.removeModal(e);
+            });
+
+            return defer;
+        },
+        /*----------------------
+            CALCULATOR TERM
+        ----------------------*/
+        calculatePaymentTerm: function(values) {
+            var order = new instance.web.Model('sale.order');
+            return order.call('calculatePaymentTermSaleOrder',[values], {
+                context: new instance.web.CompoundContext()
+            });
+        },
+        /* --------------------------------------
+            Create / writer - Term Paymen
+        ---------------------------------------- */
+        accountPaymentTermConfigurator: function(values, id){
+            var term = new instance.web.Model('sale.order');
+            return term.call('accountPaymentTermConfiguratorSale',[values, id], {
+                context: new instance.web.CompoundContext()
+            });
+        }
+    });
+
+    if (instance.web && instance.web.FormView) {
+        instance.web.FormView.include({
+            load_record: function(record) {
+                this._super.apply(this, arguments);
+
+                if (this.model !== 'sale.order')
+                    return;
+
+                openerp.parentInstancePaymentTermConfigurator = this;
+
+                if (openerp.widgetInstancePaymentTermConfigurator) {
+                    openerp.widgetInstancePaymentTermConfigurator.updateId(record.id);
+                    if (this.$el.find('.button-term-configurator').length !== 0){
+                        return
+                    }
+                }
+
+                if (this.$el.find('.button-term-configurator').length !== 0 )
+                    return;
+
+                openerp.widgetInstancePaymentTermConfigurator = new openerp.PaymentTermConfigurator(this);
+                var elemento = this.$el.find('.oe_form').find('.payment_term_configurator');
+
+                openerp.widgetInstancePaymentTermConfigurator.appendTo(elemento);
+                openerp.widgetInstancePaymentTermConfigurator.updateId(record.id);
+            },
+
+        });
+    }
+})();

+ 359 - 0
static/src/js/eiru_payment_term_configurator_purchase.js

@@ -0,0 +1,359 @@
+(function() {
+
+    openerp.widgetInstancePaymentTermPurchase = null;
+    openerp.parentInstancePaymentTermPurchase = null;
+    var Qweb = openerp.web.qweb;
+    var instance = openerp;
+    var instanceWeb = openerp.web;
+
+    openerp.PaymentTermPurchase = instance.Widget.extend({
+        template: 'eiruPaymentTerm.Purchase',
+
+        id: undefined,
+        order: [],
+        calculatorTerm: [],
+        termType: [],
+
+        /************
+        |   INIT    |
+        ************/
+        init: function(parent) {
+            this._super(parent);
+            this.buttons = parent.$buttons;
+        },
+
+        /************
+        |   START   |
+        ************/
+        start: function() {
+            var self = this;
+            this.$el.click(function() {
+                self.fectchInitial();
+            });
+            self.buttons.click(function(e) {
+                /* E (Editar) */
+                if (e.target.accessKey === 'E')
+                    self.$el.css('display','none');
+                /* S (Guarrdar) */
+                if (e.target.accessKey === 'S')
+                    self.$el.css('display','flex');
+                /* D (Cancelar) */
+                if (e.target.accessKey === 'D')
+                    self.$el.css('display','flex');
+                /* CREAR */
+                if (e.target.accessKey === 'C')
+                    self.$el.css('display','none');
+            });
+        },
+
+        /*===============
+        |   ID ORDER    |
+        ===============*/
+        updateId: function(id) {
+            var self = this;
+            self.id = id;
+
+            self.$el.css('display','flex');
+            if (!id)
+                self.$el.css('display','none');
+        },
+
+        /*=====================
+        |   Remover Modal     |
+        =====================*/
+        removeModal: function() {
+            $('.expired-account-modal').remove();
+            $('.modal-backdrop').remove();
+        },
+
+        /*===============================
+        |       Recargar la Pagina      |
+        ===============================*/
+        reloadPage: function() {
+            openerp.parentInstancePaymentTermPurchase.reload();
+        },
+
+        /******************************
+        ||       Metodo Inicial      ||
+        ******************************/
+        fectchInitial: function() {
+            var self = this;
+
+            self.fetchPurchaseOrder(self.id).then(function(order) {
+                return order;
+            }).then(function(order) {
+                self.order = order;
+                return self.fetchTypeTerm();
+            }).then(function(termType) {
+                self.termType = termType;
+                return self.showTaskSelected();
+            });
+        },
+
+        /*===============================
+        |       GET Purchase Order      |
+        ===============================*/
+        fetchPurchaseOrder: function(id) {
+            var order = new openerp.web.Model('purchase.order');
+            return order.call('getPurchaseOrder',[id],{
+                context: new openerp.web.CompoundContext()
+            });
+        },
+
+        /*=========================================
+        |     GET  Tipo de condicion de pagos     |
+        =========================================*/
+        fetchTypeTerm: function() {
+            var typeTerm = new openerp.web.Model('account.payment.term.type');
+            return typeTerm.query(['id','name']).all()
+        },
+
+        /*===================
+        |       Modal       |
+        ===================*/
+        showTaskSelected: function() {
+            var self = this;
+            var defer = $.Deferred();
+            var state = true;
+            /*Curency Order*/
+            var saleOrder = self.order[0];
+            var currencyOrder = saleOrder.currency;
+            /*term type */
+            var typeTerm = self.termType;
+
+            if (!typeTerm.length){
+                instanceWeb.notification.do_warn("Atencion", "No existe tipo de condiciones de pagos.");
+                return ;
+            }
+            typeTerm.unshift({"id": '', 'name': ''})
+
+            /* Modal */
+            var modal = Qweb.render('eiruPaymentTerm.ModalConfigurator', {'termTypes':typeTerm});
+            $('.openerp_webclient_container').after(modal);
+            $('.expired-account-modal').modal();
+
+            var amountSale = $('.expired-account-modal').find('.amount-sale');
+            var symbolCurrency = $('.expired-account-modal').find('.symbol-currency');
+
+            var initialpayments = $('.expired-account-modal').find('.initial-payments-amount');
+            var amountResidual = $('.expired-account-modal').find('.amount-residual');
+
+            var dateSale = $('.expired-account-modal').find('.date-sale');
+            var dateQuota = $('.expired-account-modal').find('.date-quota');
+            var typeTerm = $('.expired-account-modal').find('.term-select');
+            var amountQuota = $('.expired-account-modal').find('.amount-quota');
+            /* Bottom Calcular */
+            var bottomCalcular = $('.expired-account-modal').find('.bt-calular');
+            /* table */
+            var tableRow = $('.expired-account-modal').find('.table-tbody');
+            /*Bottom Guardar */
+            buttonAccept = $('.expired-account-modal').find('.button-accept');
+            /* Value initial */
+            amountSale.val(instanceWeb.formatCurrency(saleOrder.amountTotal, currencyOrder));
+            amountResidual.val(instanceWeb.formatCurrency(saleOrder.amountTotal, currencyOrder));
+
+            symbolCurrency.text(currencyOrder.symbol);
+            dateSale.val(moment(saleOrder.dateOrder).format('DD/MM/YYYY'));
+            dateQuota.val(moment(saleOrder.dateQuota).format('DD/MM/YYYY'));
+
+            /*******************************
+            *  FOCUSIN initialpayments     *
+            *******************************/
+            initialpayments.focusin(function(e){
+                var amount = instanceWeb.unFormatCurrency(initialpayments.val());
+                if (amount === 0)
+                    initialpayments.val('');
+            });
+            /****************************
+            *   KEYUP initialpayments   *
+            ****************************/
+            initialpayments.keyup(function(e) {
+                var amountPayments = instanceWeb.unFormatCurrency(initialpayments.val());
+                var saleAmount = instanceWeb.unFormatCurrency(amountSale.val());
+                if (e.key === currencyOrder.decimalSeparator && currencyOrder.decimalPlaces > 0)
+                    return false ;
+
+                initialpayments.val(instanceWeb.formatCurrency(amountPayments, currencyOrder));
+                amountResidual.val(instanceWeb.formatCurrency((saleAmount - amountPayments), currencyOrder))
+
+            });
+            /********************************
+            *    FOCUS OUT initialpayments  *
+            ********************************/
+            initialpayments.focusout(function(e) {
+                var saleAmount = instanceWeb.unFormatCurrency(amountSale.val());
+                var amount = instanceWeb.unFormatCurrency(initialpayments.val());
+
+                if (amount > saleAmount) {
+                    instanceWeb.notification.do_warn("Atencion", "El valor de la entrega supera el valor de la venta.");
+                    initialpayments.focus();
+                    return false;
+                }
+                amountResidual.val(instanceWeb.formatCurrency((saleAmount - amount), currencyOrder))
+            });
+
+            /*--------------------------
+                FOCUSIN amountQuota
+            ----------------------------*/
+            amountQuota.focusin(function(e) {
+                var amount = instanceWeb.unFormatCurrency( amountQuota.val());
+                if (amount === 0)
+                     amountQuota.val('');
+            });
+            /*-----------------------
+                KEYUP amountQuota
+            ------------------------*/
+            amountQuota.keyup(function(e) {
+                if (e.key === currencyOrder.decimalSeparator && currencyOrder.decimalPlaces > 0)
+                    return false ;
+
+                cuotaAmount = instanceWeb.unFormatCurrency(amountQuota.val());
+                amountQuota.val(instanceWeb.formatCurrency(cuotaAmount, currencyOrder));
+
+            });
+            /*---------------------------
+                FOCUS OUT amountQuota
+            ----------------------------*/
+            amountQuota.focusout(function(e) {
+                var saleAmount = instanceWeb.unFormatCurrency(amountSale.val());
+                var amountPayments = instanceWeb.unFormatCurrency(initialpayments.val());
+                var amount = instanceWeb.unFormatCurrency(amountQuota.val());
+
+                if (amount <= 0) {
+                    instanceWeb.notification.do_warn("Atencion", "El valor de la cuota debe de ser mayor que cero.");
+                    amountQuota.focus();
+                    return false;
+                }
+
+                if (amount > (saleAmount - amountPayments)) {
+                    instanceWeb.notification.do_warn("Atencion", "El valor de la cuota no puede superar el valor total de la venta.\nVenta ="+saleAmount+"\nEntrega ="+amountPayments+"\nCuota = "+amount);
+                    amountQuota.focus();
+                    return false;
+                }
+            });
+            /*-------------------
+                CLICK CALCULAR
+            ---------------------*/
+            bottomCalcular.click(function(e) {
+                tableRow.find('tr').remove();
+                var htmlLine = '';
+                var cuotaAmount = instanceWeb.unFormatCurrency(amountQuota.val());
+                var amountPayments = instanceWeb.unFormatCurrency(initialpayments.val());
+                /* */
+                if(!typeTerm.val()) {
+                    instanceWeb.notification.do_warn("Atencion", "Debes de Seleccionar el tipo de plazo de pago.");
+                    typeTerm.focus();
+                    return;
+                }
+                /* */
+                if (cuotaAmount <= 0) {
+                    instanceWeb.notification.do_warn("Atencion", "El valor de la cuota debe de ser mayor que cero.");
+                    amountQuota.focus();
+                    return;
+                }
+
+                var termSale = {
+                    'orderId': self.id,
+                    'typeTerm': parseInt(typeTerm.val().trim()),
+                    'amountCuota': cuotaAmount,
+                    'amountPayments': amountPayments,
+                }
+
+                /* GENERAR LA LISTA DE CUOTA */
+                $('.expired-account-modal').find('.widget-content.widget-loading-term-configurator').css('display','flex');
+                self.calculatePaymentTerm(termSale).then(function(calculatorTerm) {
+                    return calculatorTerm;
+                }).then(function(calculatorTerm) {
+                    self.calculatorTerm = calculatorTerm;
+                    $('.expired-account-modal').find('.widget-content.widget-loading-term-configurator').css('display','none');
+                    if (!!calculatorTerm.length) {
+                        _.each(calculatorTerm, function(line) {
+                           var dateMaturity = moment(line.date).format('DD/MM/YYYY');
+                           var amount = instanceWeb.formatCurrency(line.amount, currencyOrder) +" "+currencyOrder.symbol;
+                            htmlLine +='<tr><td><span>'+line.cuotaNumber+'</span></td><td><span>'+dateMaturity+'</span></td><td><span>'+amount+'</span></td></tr>';
+                        })
+                        tableRow.append(htmlLine);
+                    }
+                });
+            });
+            /*----------------------
+                ACEPTAR / GUARDAR
+            ----------------------*/
+            buttonAccept.click(function(e) {
+                if (!self.calculatorTerm.length) {
+                    instanceWeb.notification.do_warn("Atencion", "Debes de calcular las cuota antes de guardar.");
+                    return ;
+                }
+
+                $('.expired-account-modal').find('.widget-content.widget-loading-term-configurator').css('display','flex');
+                self.accountPaymentTermConfigurator(self.calculatorTerm, self.id).then(function(termConfigurator) {
+                    return termConfigurator;
+                }).then(function(termConfigurator) {
+                    $('.expired-account-modal').find('.widget-content.widget-loading-term-configurator').css('display','none');
+                    self.removeModal(e);
+                    state = termConfigurator.state;
+                    self.reloadPage();
+                });
+
+                defer.resolve(state);
+            });
+            /*-----------
+                CERRAR
+            -----------*/
+            $('.expired-account-modal').on('hidden.bs.modal', function (e) {
+                defer.resolve(false);
+                self.removeModal(e);
+            });
+
+            return defer;
+        },
+        /*----------------------
+            CALCULATOR TERM
+        ----------------------*/
+        calculatePaymentTerm: function(values) {
+            var order = new instance.web.Model('purchase.order');
+            return order.call('calculatePaymentTermPurchaseOrder',[values], {
+                context: new instance.web.CompoundContext()
+            });
+        },
+        /* --------------------------------------
+            Create / writer - Term Paymen
+        ---------------------------------------- */
+        accountPaymentTermConfigurator: function(values, id){
+            var term = new instance.web.Model('purchase.order');
+            return term.call('accountPaymentTermConfigurator',[values, id], {
+                context: new instance.web.CompoundContext()
+            });
+        }
+    });
+
+    if (instance.web && instance.web.FormView) {
+        instance.web.FormView.include({
+            load_record: function(record) {
+                this._super.apply(this, arguments);
+
+                if (this.model !== 'purchase.order')
+                    return;
+
+                openerp.parentInstancePaymentTermPurchase = this;
+
+                if (openerp.widgetInstancePaymentTermPurchase) {
+                    openerp.widgetInstancePaymentTermPurchase.updateId(record.id);
+                    if (this.$el.find('.button-term-configurator-purchase').length !== 0){
+                        return
+                    }
+                }
+
+                if (this.$el.find('.button-term-configurator-purchase').length !== 0 )
+                    return;
+
+                openerp.widgetInstancePaymentTermPurchase = new openerp.PaymentTermPurchase(this);
+                var elemento = this.$el.find('.oe_form').find('.purchase-payment-term-configurator');
+
+                openerp.widgetInstancePaymentTermPurchase.appendTo(elemento);
+                openerp.widgetInstancePaymentTermPurchase.updateId(record.id);
+            },
+
+        });
+    }
+})();

+ 251 - 0
static/src/js/eiru_payment_term_discount.js

@@ -0,0 +1,251 @@
+(function() {
+
+    openerp.widgetInstancePaymentTermDiscount = null;
+    openerp.parentInstancePaymentTermDiscount = null;
+    var Qweb = openerp.web.qweb;
+    var instance = openerp;
+    var instanceWeb = openerp.web;
+
+    openerp.PaymentTermDiscount = instance.Widget.extend({
+        template: 'eiruPaymentTerm.Discount',
+        id: undefined,
+
+        termConfig: [],
+        saleOrderInterst: [],
+        saleOrder: [],
+
+        init: function(parent) {
+            this._super(parent);
+            this.buttons = parent.$buttons;
+        },
+        start: function() {
+            var self = this;
+
+            this.$el.click(function(){
+                self.fectchInitial();
+            });
+            self.buttons.click(function(e) {
+                /* E (Editar) */
+                if (e.target.accessKey === 'E')
+                    self.$el.css('display','none');
+                /* S (Guarrdar) */
+                if (e.target.accessKey === 'S')
+                    self.$el.css('display','flex');
+                /* D (Cancelar) */
+                if (e.target.accessKey === 'D')
+                    self.$el.css('display','flex');
+                /* CREAR */
+                if (e.target.accessKey === 'C')
+                    self.$el.css('display','none');
+            });
+        },
+        updateId: function(id) {
+            var self = this;
+            self.id = id;
+
+            self.$el.css('display','flex');
+            if (!id)
+                self.$el.css('display','none');
+        },
+        /* Remover */
+        removeModal: function() {
+            $('.expired-account-modal').remove();
+            $('.modal-backdrop').remove();
+        },
+        /* Reloada */
+        reloadPage: function() {
+            openerp.parentInstancePaymentTermDiscount.reload();
+        },
+        /* Metodo Inicial */
+        fectchInitial: function() {
+            var self = this;
+            self.fetchSaleOrderDiscount().then(function(saleOrder) {
+                return saleOrder
+            }).then(function(saleOrder) {
+                self.saleOrder = saleOrder;
+                return self.showModalDiscount();
+            });
+        },
+
+        fetchSaleOrderDiscount: function() {
+            var self = this;
+            var order = new openerp.web.Model('sale.order');
+            return order.call('getSaleOrder',[self.id],{
+                context: new openerp.web.CompoundContext()
+            });
+        },
+
+        showModalDiscount: function() {
+            var self = this;
+            var defer = $.Deferred();
+            var state = true;
+            if (!self.saleOrder.length)
+                return
+
+            var order = self.saleOrder[0];
+            var currency = order.currency;
+
+            /* Modal */
+            var modal = Qweb.render('eiruPaymentTerm.ModalDiscount');
+            $('.openerp_webclient_container').after(modal);
+            $('.expired-account-modal').modal();
+
+            var dateSale = $('.expired-account-modal').find('.date-sale-discount');
+            // var dateQuotaInterest = $('.expired-account-modal').find('.date-quota-interest');
+            var amountSale = $('.expired-account-modal').find('.amount-sale');
+            var amountDiscount = $('.expired-account-modal').find('.amount-discount');
+            var amountTotal = $('.expired-account-modal').find('.amount-total');
+            var symbolCurrencyInterest = $('.expired-account-modal').find('.symbol-currency-interest');
+            var buttonAcceptDiscount = $('.expired-account-modal').find('.button-accept-discount');
+
+            /*--------------
+                Inicial.
+            ----------------*/
+            dateSale.val(moment(order.dateOrder).format('DD/MM/YYYY'));
+            amountSale.val(instanceWeb.formatCurrency(order.amountTotal, currency));
+            amountDiscount.val(0);
+            amountTotal.val(instanceWeb.formatCurrency(order.amountTotal, currency));
+            symbolCurrencyInterest.text(currency.symbol);
+            buttonAcceptDiscount.attr("disabled", true)
+
+            /*--------------------------
+                FOCUSIN amountDiscount
+            ----------------------------*/
+            amountDiscount.focusin(function(e) {
+                var amount = instanceWeb.unFormatCurrency( amountDiscount.val());
+                if (amount === 0)
+                    amountDiscount.val('');
+            });
+            /*-----------------------
+                KEYUP amountDiscount
+            ------------------------*/
+            amountDiscount.keyup(function(e) {
+                var discountAmount = instanceWeb.unFormatCurrency(amountDiscount.val());
+                var amountReal = instanceWeb.unFormatCurrency(amountSale.val());
+
+                if (e.key === currency.decimalSeparator && currency.decimalPlaces > 0)
+                 return false ;
+
+                if (discountAmount > amountReal){
+                    instanceWeb.notification.do_warn("Atencion", "El valor del descuento superar el valor total de la venta.");
+                    amountDiscount.focus();
+                    return false
+                }
+
+                amountDiscount.val(instanceWeb.formatCurrency(discountAmount, currency));
+                amountTotal.val(instanceWeb.formatCurrency((amountReal - discountAmount), currency))
+
+                if (e.keyCode === 13) {
+                    if (discountAmount > amountReal) {
+                        buttonAcceptDiscount.attr("disabled", true);
+                        amountDiscount.focus();
+                        return false
+                    }
+
+                    buttonAcceptDiscount.removeAttr("disabled");
+                    buttonAcceptDiscount.focus()
+                  }
+            });
+            /*---------------------------
+                FOCUS OUT amountDiscount
+            ----------------------------*/
+            amountDiscount.focusout(function(e) {
+                var discountAmount = instanceWeb.unFormatCurrency(amountDiscount.val());
+                var amountReal = instanceWeb.unFormatCurrency(amountSale.val());
+
+                if (discountAmount > amountReal) {
+                    instanceWeb.notification.do_warn("Atencion", "El valor del descuento superar el valor total de la venta.");
+                    buttonAcceptDiscount.attr("disabled", true);
+                    amountDiscount.focus();
+                    return false;
+                }
+                if (discountAmount <= 0){
+                    buttonAcceptDiscount.attr("disabled", true);
+                    return false;
+                }
+                buttonAcceptDiscount.removeAttr("disabled");
+            });
+            /*-------------
+                Guardar.
+            -------------- */
+            buttonAcceptDiscount.click(function(e){
+                var discountAmount = instanceWeb.unFormatCurrency(amountDiscount.val());
+                var amountReal = instanceWeb.unFormatCurrency(amountSale.val());
+                var amount = instanceWeb.unFormatCurrency(amountTotal.val());
+
+                if (discountAmount > amountReal) {
+                    instanceWeb.notification.do_warn("Atencion", "El valor del descuento superar el valor total de la venta.");
+                    buttonAcceptDiscount.attr("disabled", true);
+                    amountDiscount.focus();
+                    return false;
+                }
+                if (discountAmount <= 0){
+                    buttonAcceptDiscount.attr("disabled", true);
+                    return false;
+                }
+
+
+                $('.expired-account-modal').find('.widget-content.widget-loading-term-configurator').css('display','flex');
+                self.accountSaleLineAddDiscount(self.id, amount).then(function(saleDiscont) {
+                    return saleDiscont;
+                }).then(function(saleDiscont) {
+                    $('.expired-account-modal').find('.widget-content.widget-loading-term-configurator').css('display','none');
+                    self.reloadPage();
+                    self.removeModal(e);
+                    state = saleDiscont.state;
+                });
+
+                defer.resolve(state);
+            }),
+
+            /*-----------
+                CERRAR
+            -----------*/
+            $('.expired-account-modal').on('hidden.bs.modal', function (e) {
+                defer.resolve(false);
+                self.removeModal(e);
+            });
+
+            return defer;
+        },
+        /* -----------------------
+            Guardar Interest
+        -------------------------- */
+        accountSaleLineAddDiscount: function(id, amount) {
+            var sale = new instance.web.Model('sale.order');
+            return sale.call('account_Sale_line_add_discount',[id,amount], {
+                context: new instance.web.CompoundContext()
+            });
+        },
+    });
+
+    if (instance.web && instance.web.FormView) {
+        instance.web.FormView.include({
+            load_record: function(record) {
+                this._super.apply(this, arguments);
+
+                if (this.model !== 'sale.order')
+                    return;
+
+                openerp.parentInstancePaymentTermDiscount = this;
+
+                if (openerp.widgetInstancePaymentTermDiscount) {
+                    openerp.widgetInstancePaymentTermDiscount.updateId(record.id);
+                    if (this.$el.find('.button-term-discount').length !== 0){
+                        return
+                    }
+                }
+
+                if (this.$el.find('.button-term-discount').length !== 0 )
+                    return;
+
+                openerp.widgetInstancePaymentTermDiscount = new openerp.PaymentTermDiscount(this);
+                var elemento = this.$el.find('.oe_form').find('.payment_term_discont');
+
+                openerp.widgetInstancePaymentTermDiscount.appendTo(elemento);
+                openerp.widgetInstancePaymentTermDiscount.updateId(record.id);
+            },
+
+        });
+    }
+})();

+ 183 - 0
static/src/js/eiru_payment_term_interest.js

@@ -0,0 +1,183 @@
+(function() {
+
+    openerp.widgetInstancePaymentTermInterest = null;
+    openerp.parentInstancePaymentTermInterest = null;
+    var Qweb = openerp.web.qweb;
+    var instance = openerp;
+    var instanceWeb = openerp.web;
+
+    openerp.PaymentTermInterest = instance.Widget.extend({
+        template: 'eiruPaymentTerm.Interest',
+        id: undefined,
+
+        termConfig: [],
+        saleOrderInterst: [],
+
+        init: function(parent) {
+            this._super(parent);
+            this.buttons = parent.$buttons;
+        },
+        start: function() {
+            var self = this;
+
+            this.$el.click(function(){
+                self.fectchInitial();
+            });
+            self.buttons.click(function(e) {
+                /* E (Editar) */
+                if (e.target.accessKey === 'E')
+                    self.$el.css('display','none');
+                /* S (Guarrdar) */
+                if (e.target.accessKey === 'S')
+                    self.$el.css('display','flex');
+                /* D (Cancelar) */
+                if (e.target.accessKey === 'D')
+                    self.$el.css('display','flex');
+                /* CREAR */
+                if (e.target.accessKey === 'C')
+                    self.$el.css('display','none');
+            });
+        },
+        updateId: function(id) {
+            var self = this;
+            self.id = id;
+
+            self.$el.css('display','flex');
+            if (!id)
+                self.$el.css('display','none');
+        },
+        /* Remover */
+        removeModal: function() {
+            $('.expired-account-modal').remove();
+            $('.modal-backdrop').remove();
+        },
+        /* Reloada */
+        reloadPage: function() {
+            openerp.parentInstancePaymentTermInterest.reload();
+        },
+        /* Metodo Inicial */
+        fectchInitial: function() {
+            var self = this;
+            self.fetchSaleOrderInterest().then(function(saleOrderInterst) {
+                return saleOrderInterst
+            }).then(function(saleOrderInterst) {
+                self.saleOrderInterst = saleOrderInterst;
+                return self.showModalInterest();
+            });
+        },
+
+        fetchSaleOrderInterest: function() {
+            var self = this;
+            var order = new openerp.web.Model('sale.order');
+            return order.call('getSaleOrderInterest',[self.id],{
+                context: new openerp.web.CompoundContext()
+            });
+        },
+        showModalInterest: function() {
+            var self = this;
+            var defer = $.Deferred();
+            var state = true;
+            if (!self.saleOrderInterst.length)
+                return
+
+            var order = self.saleOrderInterst[0];
+            var currency = order.currency;
+
+            /* Modal */
+            var modal = Qweb.render('eiruPaymentTerm.ModalInterest');
+            $('.openerp_webclient_container').after(modal);
+            $('.expired-account-modal').modal();
+
+            var dateSaleInterest = $('.expired-account-modal').find('.date-sale-interest');
+            var dateQuotaInterest = $('.expired-account-modal').find('.date-quota-interest');
+            var dayDifference = $('.expired-account-modal').find('.day-difference');
+            var amountInterest = $('.expired-account-modal').find('.amount-interest');
+            var symbolCurrencyInterest = $('.expired-account-modal').find('.symbol-currency-interest');
+            var buttonAcceptInterest = $('.expired-account-modal').find('.button-accept-interest');
+
+            /*--------------
+                Inicial.
+            ----------------*/
+            dateSaleInterest.val(moment(order.dateOrder).format('DD/MM/YYYY'));
+            dateQuotaInterest.val(moment(order.dateQuota).format('DD/MM/YYYY'));
+            dayDifference.val(order.differenceDay);
+            amountInterest.val(instanceWeb.formatCurrency(order.amountInteres, currency));
+            symbolCurrencyInterest.text(currency.symbol);
+
+            /*-------------
+                Guardar.
+            -------------- */
+            buttonAcceptInterest.click(function(e){
+                var interest ={
+                    'amountTotal' : order.amountTotal,
+                    'dateOrder' : order.dateOrder,
+                    'dateQuota' : order.dateQuota,
+                    'amountInteres' : order.amountInteres,
+                    'differenceDay' : order.differenceDay,
+                    'messageDefault' : order.messageDefault,
+                    'saleId': self.id,
+                }
+                $('.expired-account-modal').find('.widget-content.widget-loading-term-configurator').css('display','flex');
+                self.accountSaleInterest(interest).then(function(saleInterest) {
+                    return saleInterest;
+                }).then(function(saleInterest) {
+                    $('.expired-account-modal').find('.widget-content.widget-loading-term-configurator').css('display','none');
+                    self.reloadPage();
+                    self.removeModal(e);
+                    state = saleInterest.state;
+                });
+
+                defer.resolve(state);
+            }),
+
+            /*-----------
+                CERRAR
+            -----------*/
+            $('.expired-account-modal').on('hidden.bs.modal', function (e) {
+                defer.resolve(false);
+                self.removeModal(e);
+            });
+
+            return defer;
+        },
+        /* -----------------------
+            Guardar Interest
+        -------------------------- */
+        accountSaleInterest: function(interest) {
+            var term = new instance.web.Model('sale.order');
+            return term.call('account_sale_line_interest',[interest], {
+                context: new instance.web.CompoundContext()
+            });
+        },
+    });
+
+    if (instance.web && instance.web.FormView) {
+        instance.web.FormView.include({
+            load_record: function(record) {
+                this._super.apply(this, arguments);
+
+                if (this.model !== 'sale.order')
+                    return;
+
+                openerp.parentInstancePaymentTermInterest = this;
+
+                if (openerp.widgetInstancePaymentTermInterest) {
+                    openerp.widgetInstancePaymentTermInterest.updateId(record.id);
+                    if (this.$el.find('.button-term-interest').length !== 0){
+                        return
+                    }
+                }
+
+                if (this.$el.find('.button-term-interest').length !== 0 )
+                    return;
+
+                openerp.widgetInstancePaymentTermInterest = new openerp.PaymentTermInterest(this);
+                var elemento = this.$el.find('.oe_form').find('.payment_term_configurator');
+
+                openerp.widgetInstancePaymentTermInterest.appendTo(elemento);
+                openerp.widgetInstancePaymentTermInterest.updateId(record.id);
+            },
+
+        });
+    }
+})();

+ 8 - 0
static/src/xml/add_discont.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="eiruPaymentTerm.Discount">
+        <button type="button" class="button-term-discount oe_button oe_highlight">
+            Generar Descuento
+        </button>
+    </t>
+</template>

+ 8 - 0
static/src/xml/eiru_payment_term_configurator_purchase.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="eiruPaymentTerm.Purchase">
+        <button type="button" class="button-term-configurator-purchase button-action-term oe_button oe_highlight">
+            Configuración de Cuota
+        </button>
+    </t>
+</template>

+ 8 - 0
static/src/xml/interest_Line.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="eiruPaymentTerm.Interest">
+        <button type="button" class="button-term-interest oe_button oe_highlight">
+            Actualizar Interés
+        </button>
+    </t>
+</template>

+ 122 - 0
static/src/xml/modal/modal_eiru_payment_term_configurator.xml

@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="eiruPaymentTerm.ModalConfigurator">
+        <div class="modal in expired-account-modal" tabindex="-1" role="dialog"  data-backdrop="static">
+            <div class="modal-dialog modal-lg" role="document">
+                <div class="modal-content openerp">
+                    <div class="widget-content widget-loading-term-configurator">
+                        <i class='fa fa-cog fa-spin fa-3x fa-fw'></i>
+                    </div>
+                    <!-- title  -->
+                    <div class="modal-header term-configurator-header">
+                        <button type="button" class="close" data-dismiss="modal" aria-label="Close" aria-hidden="true">×</button>
+                        <h3 class="modal-title">Configuración de Cuota</h3>
+                    </div>
+                    <!-- Body -->
+                    <div class="modal-body">
+                        <div class="row">
+                            <div class="col-xs-6">
+                                <label class="term-configurator-from-label">Valor de Venta</label>
+                                <div class="term-configurator-from-group-input">
+                                  <input type="text" class="form-control term-configurator-input-currency amount-sale" readonly="readonly" value="0"></input>
+                                  <div class="term-configurator-symbol-currency">
+                                    <span class="symbol-currency"></span>
+                                  </div>
+                                </div>
+                            </div>
+                        </div>
+                        <div class="row">
+                            <div class="col-xs-6">
+                                <label class="term-configurator-from-label">Valor de Entrega</label>
+                                <div class="term-configurator-from-group-input">
+                                  <input type="text" class="form-control term-configurator-input-currency initial-payments-amount" value="0"></input>
+                                  <div class="term-configurator-symbol-currency">
+                                    <span class="symbol-currency"></span>
+                                  </div>
+                                </div>
+                            </div>
+                            <div class="col-xs-6">
+                                <label class="term-configurator-from-label">Saldo</label>
+                                <div class="term-configurator-from-group-input">
+                                  <input type="text" class="form-control term-configurator-input-currency amount-residual" readonly="readonly" value="0"></input>
+                                  <div class="term-configurator-symbol-currency">
+                                    <span class="symbol-currency"></span>
+                                  </div>
+                                </div>
+                            </div>
+                        </div>
+                        <div class="row">
+                            <div class="col-xs-6">
+                                <label class="term-configurator-from-label">Fecha de venta</label>
+                                <div class="term-configurator-from-group-input">
+                                    <input type="text" class="form-control date-sale" readonly="readonly"></input>
+                                </div>
+                            </div>
+                            <div class="col-xs-6">
+                                <label class="term-configurator-from-label">Fecha Primera Cuota</label>
+                                <div class="term-configurator-from-group-input">
+                                    <input type="text" class="form-control date-quota" readonly="readonly"></input>
+                                </div>
+                            </div>
+                        </div>
+                        <div class="row">
+                            <div class="col-xs-6">
+                                <label class="term-configurator-from-label">Plazo de Pago:</label>
+                                <div class="term-configurator-from-group-input">
+                                    <select class="form-control term-select">
+                                        <t t-foreach='termTypes' t-as='termType'>
+                                            <option t-attf-value="{{ termType_value.id }}">
+                                                <t t-esc="termType_value.name"/>
+                                            </option>
+                                        </t>
+                                    </select>
+                                </div>
+                            </div>
+                            <div class="col-xs-6">
+                                <label class="term-configurator-from-label">Monto de Cuota</label>
+                                <div class="term-configurator-from-group-input">
+                                  <input type="text" class="form-control term-configurator-input-currency amount-quota"  value="0"></input>
+                                  <div class="term-configurator-symbol-currency">
+                                    <span class="symbol-currency"></span>
+                                  </div>
+                                </div>
+                            </div>
+                        </div>
+                        <div class="row">
+                            <button type="button" class="oe_button oe_form_button oe_highlight term-configurator-button-calculator bt-calular">
+                                Calcular
+                            </button>
+                        </div>
+                        <!-- Table -->
+                        <div class="oe_view_manager_body term-configurator-table">
+                            <div class="modal-head-wrapper-term-configurator">
+                                <table class="oe_list_content">
+                                    <thead >
+                                        <tr class="oe_list_header_columns"  >
+                                            <th class="oe_list_header_char oe_sortable">Cuota</th>
+                                            <th class="oe_list_header_char oe_sortable">Vencimiento</th>
+                                            <th class="oe_list_header_char oe_sortable">Valor de la cuota </th>
+                                        </tr>
+                                    </thead>
+                                </table>
+                            </div>
+                            <div class="modal-item-term-configurator">
+                                <table class="oe_list_content">
+                                    <tbody class="table-tbody">
+                                    </tbody>
+                                </table>
+                            </div>
+                        </div>
+                    </div>
+
+                    <!-- Pie de Pagina -->
+                    <div class="modal-footer term-configurator-footer">
+                        <button type="button" class="oe_button oe_form_button oe_highlight button-accept term-configurator-button">Guardar</button>
+                        <button type="button" class="oe_button oe_form_button oe_link dismmis-modal term-configurator-button" data-dismiss="modal">Salir</button>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </t>
+
+</template>

+ 65 - 0
static/src/xml/modal/modal_eiru_payment_term_discount.xml

@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="eiruPaymentTerm.ModalDiscount">
+        <div class="modal in expired-account-modal" tabindex="-1" role="dialog"  data-backdrop="static">
+            <div class="modal-dialog modal-lg" role="document">
+                <div class="modal-content openerp">
+                    <div class="widget-content widget-loading-term-configurator">
+                        <i class='fa fa-cog fa-spin fa-3x fa-fw'></i>
+                    </div>
+                    <!-- title  -->
+                    <div class="modal-header term-configurator-header">
+                        <button type="button" class="close" data-dismiss="modal" aria-label="Close" aria-hidden="true">×</button>
+                        <h3 class="modal-title">Calculo de Descuento</h3>
+                    </div>
+                    <!-- Body -->
+                    <div class="modal-body">
+                        <div class="row">
+                            <div class="col-xs-6">
+                                <label class="term-configurator-from-label">Valor de la venta</label>
+                                <div class="term-configurator-from-group-input">
+                                  <input type="text" class="form-control term-configurator-input-currency amount-sale" readonly="readonly" value="0"></input>
+                                  <div class="term-configurator-symbol-currency">
+                                    <span class="symbol-currency-interest"></span>
+                                  </div>
+                                </div>
+                            </div>
+                            <div class="col-xs-6">
+                                <label class="term-configurator-from-label">Fecha de venta</label>
+                                <div class="term-configurator-from-group-input">
+                                    <input type="text" class="form-control date-sale-discount" readonly="readonly"></input>
+                                </div>
+                            </div>
+                        </div>
+                        <div class="row">
+                            <div class="col-xs-6">
+                                <label class="term-configurator-from-label">Valor de descuento</label>
+                                <div class="term-configurator-from-group-input">
+                                  <input type="text" class="form-control term-configurator-input-currency amount-discount" value="0"></input>
+                                  <div class="term-configurator-symbol-currency">
+                                    <span class="symbol-currency-interest"></span>
+                                  </div>
+                                </div>
+                            </div>
+                            <div class="col-xs-6">
+                                <label class="term-configurator-from-label">Total</label>
+                                <div class="term-configurator-from-group-input">
+                                  <input type="text" class="form-control term-configurator-input-currency amount-total" readonly="readonly" value="0"></input>
+                                  <div class="term-configurator-symbol-currency">
+                                    <span class="symbol-currency-interest"></span>
+                                  </div>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                    <!-- Pie de Pagina -->
+                    <div class="modal-footer term-configurator-footer">
+                        <button type="button" class="oe_button oe_form_button oe_highlight button-accept-discount term-configurator-button">Guardar</button>
+                        <button type="button" class="oe_button oe_form_button oe_link dismmis-modal term-configurator-button" data-dismiss="modal">Salir</button>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </t>
+
+</template>

+ 59 - 0
static/src/xml/modal/modal_eiru_payment_term_interest.xml

@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="eiruPaymentTerm.ModalInterest">
+        <div class="modal in expired-account-modal" tabindex="-1" role="dialog"  data-backdrop="static">
+            <div class="modal-dialog modal-lg" role="document">
+                <div class="modal-content openerp">
+                    <div class="widget-content widget-loading-term-configurator">
+                        <i class='fa fa-cog fa-spin fa-3x fa-fw'></i>
+                    </div>
+                    <!-- title  -->
+                    <div class="modal-header term-configurator-header">
+                        <button type="button" class="close" data-dismiss="modal" aria-label="Close" aria-hidden="true">×</button>
+                        <h3 class="modal-title">Calculo de interés por cambio de fecha </h3>
+                    </div>
+                    <!-- Body -->
+                    <div class="modal-body">
+                        <div class="row">
+                            <div class="col-xs-6">
+                                <label class="term-configurator-from-label">Fecha de venta</label>
+                                <div class="term-configurator-from-group-input">
+                                    <input type="text" class="form-control date-sale-interest" readonly="readonly"></input>
+                                </div>
+                            </div>
+                            <div class="col-xs-6">
+                                <label class="term-configurator-from-label">Fecha Primera Cuota</label>
+                                <div class="term-configurator-from-group-input">
+                                    <input type="text" class="form-control date-quota-interest" readonly="readonly"></input>
+                                </div>
+                            </div>
+                        </div>
+                        <div class="row">
+                            <div class="col-xs-6">
+                                <label class="term-configurator-from-label">Dia de Diferencia </label>
+                                <div class="term-configurator-from-group-input">
+                                    <input type="text" class="form-control day-difference" readonly="readonly"></input>
+                                </div>
+                            </div>
+                            <div class="col-xs-6">
+                                <label class="term-configurator-from-label">Interés calculado</label>
+                                <div class="term-configurator-from-group-input">
+                                  <input type="text" class="form-control term-configurator-input-currency amount-interest" readonly="readonly" value="0"></input>
+                                  <div class="term-configurator-symbol-currency">
+                                    <span class="symbol-currency-interest"></span>
+                                  </div>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                    <!-- Pie de Pagina -->
+                    <div class="modal-footer term-configurator-footer">
+                        <button type="button" class="oe_button oe_form_button oe_highlight button-accept-interest term-configurator-button">Guardar</button>
+                        <button type="button" class="oe_button oe_form_button oe_link dismmis-modal term-configurator-button" data-dismiss="modal">Salir</button>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </t>
+
+</template>

+ 8 - 0
static/src/xml/view.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="eiruPaymentTerm.Configurator">
+        <button type="button" class="button-term-configurator button-action-term oe_button oe_highlight">
+            Configuración de Cuota
+        </button>
+    </t>
+</template>

+ 64 - 0
views/account_payment_term_config.xml

@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+    <data>
+        <function model="accont.payments.term.config" name="_create_default_config"/>
+        <!-- from -->
+        <record id="accont_payments_term_config_form" model="ir.ui.view">
+            <field name="name">accont_payments_term_config.form</field>
+            <field name="model">accont.payments.term.config</field>
+            <field name="arch" type="xml">
+                <form create="0" delet="0">
+                    <sheet>
+                        <h2>
+                            <field name="name" string="Descripción"/>
+                        </h2>
+                        <group col="2">
+                            <group>
+                                <field name="interest_rate" string="Tasa de interés"/>
+                            </group>
+                            <group>
+                                <field name="compute" string="Calcular Interés"/>
+                            </group>
+                        </group>
+                        <group>
+                            <field name="message_default" string="Descripción"/>
+                        </group>
+                        <group>
+                            <field name="comment" string="Información Adicional"/>
+                        </group>
+                    </sheet>
+                </form>
+            </field>
+        </record>
+
+        <!-- Tree -->
+        <record id="accont_payments_term_config_tree" model="ir.ui.view">
+			<field name="name">accont_payments_term_config.tree</field>
+			<field name="model">accont.payments.term.config</field>
+			<field name="arch" type="xml">
+				<tree>
+                    <field name="name" string="Descripción"/>
+                    <field name="interest_rate" string="Tasa de interés"/>
+                    <field name="compute" string="Calcular Interés"/>
+				</tree>
+			</field>
+	    </record>
+
+        <!-- Actions  -->
+        <record id="accont_payments_term_config_actions" model="ir.actions.act_window">
+            <field name="name">Configuración de Interés</field>
+            <field name="res_model">accont.payments.term.config</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">tree,form</field>
+            <field name="target">current</field>
+        </record>
+
+        <!-- Menu Item -->
+        <menuitem
+            id="accont_payments_term_config_menu"
+            name="Configuración de Interés"
+            parent="eiru_account_payment_term_sale_menu"
+            action="accont_payments_term_config_actions"
+            sequence="2"/>
+    </data>
+</openerp>

+ 68 - 0
views/account_payment_term_type.xml

@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+    <data>
+        <function model="account.payment.term.type" name="_create_default_type_term"/>
+        <!-- from -->
+        <record id="eiru_account_payment_term_type_form" model="ir.ui.view">
+            <field name="name">eiru_account_payment_term_type.form</field>
+            <field name="model">account.payment.term.type</field>
+            <field name="arch" type="xml">
+                <form>
+                    <sheet>
+                        <h2>
+                            <field name="name" string="Descripción"/>
+                        </h2>
+                        <group col="2">
+                            <group>
+                                <field name="type_calculation" string="Forma de Calculo"/>
+                            </group>
+                            <group>
+                                <field name="qty_add" string="Cantidad a adicionar"/>
+                            </group>
+                        </group>
+                        <group>
+                            <field name="comment" string="Información Adicional"/>
+                        </group>
+                    </sheet>
+                </form>
+            </field>
+        </record>
+
+        <!-- Tree -->
+        <record id="eiru_account_payment_term_type_tree" model="ir.ui.view">
+			<field name="name">eiru_account_payment_term_type.tree</field>
+			<field name="model">account.payment.term.type</field>
+			<field name="arch" type="xml">
+				<tree>
+                    <field name="name" string="Descripción"/>
+                    <field name="type_calculation" string="Forma de Calculo"/>
+                    <field name="qty_add" string="Cantidad a adicionar"/>
+				</tree>
+			</field>
+	    </record>
+
+        <!-- Actions  -->
+        <record id="eiru_account_payment_term_type_actions" model="ir.actions.act_window">
+            <field name="name">Tipo de Condiciones de Pago</field>
+            <field name="res_model">account.payment.term.type</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">tree,form</field>
+            <field name="target">current</field>
+        </record>
+
+        <!-- Menu  -->
+        <menuitem
+            id="eiru_account_payment_term_sale_menu"
+            name="Configuración Condiciones de Pago"
+            parent="base.menu_base_partner"
+            sequence="10"/>
+
+        <!-- Menu Item -->
+        <menuitem
+            id="eiru_account_payment_term_type_menu"
+            name="Tipo de Condiciones de Pago"
+            parent="eiru_account_payment_term_sale_menu"
+            action="eiru_account_payment_term_type_actions"
+            sequence="1"/>
+    </data>
+</openerp>

+ 13 - 0
views/template.xml

@@ -0,0 +1,13 @@
+<openerp>
+    <data>
+        <template id="eiru_payment_term_configurator.assets_backend" name="eiru_payment_term_configurator_assets" inherit_id="eiru_assets.assets">
+            <xpath expr="." position="inside">
+                <link rel="stylesheet" href="/eiru_payment_term_configurator/static/src/css/style.css"/>
+                <script type="text/javascript" src="/eiru_payment_term_configurator/static/src/js/eiru_payment_term_configurator.js"/>
+                <script type="text/javascript" src="/eiru_payment_term_configurator/static/src/js/eiru_payment_term_interest.js"/>
+                <script type="text/javascript" src="/eiru_payment_term_configurator/static/src/js/eiru_payment_term_configurator_purchase.js"/>
+                <script type="text/javascript" src="/eiru_payment_term_configurator/static/src/js/eiru_payment_term_discount.js"/>
+            </xpath>
+        </template>
+    </data>
+</openerp>

+ 36 - 0
views/views.xml

@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+	<data>
+		<!-- sale.order -->
+        <record id="views_eiru_payment_term_configurator" model="ir.ui.view">
+            <field name="name">eiru.payment.term.configurator</field>
+            <field name="model">sale.order</field>
+            <field name="inherit_id" ref="sale.view_order_form"/>
+            <field name="arch" type="xml">
+				<field name="date_order" position="after">
+                    <field name="date_quota" required="1"/>
+                </field>
+                <field name="order_line" position="before">
+                    <div class="payment_term_configurator" attrs="{'invisible': [('state','not in',['draft','sent'])]}"></div>
+                </field>
+                <field name="order_line" position="before">
+                    <div class="payment_term_discont" attrs="{'invisible': [('state','not in',['draft','sent'])]}"></div>
+                </field>
+            </field>
+        </record>
+		<!-- purchase.order -->
+		<record id="views_eiru_payment_term_configurator_purchase" model="ir.ui.view">
+			<field name="name">views_eiru_payment_term_configurator.purchase</field>
+			<field name="model">purchase.order</field>
+			<field name="inherit_id" ref="purchase.purchase_order_form"/>
+			<field name="arch" type="xml">
+				<field name="date_order" position="after">
+					<field name="date_quota" required="1"/>
+				</field>
+				<field name="order_line" position="before">
+					<div class="purchase-payment-term-configurator" attrs="{'invisible': [('state','not in',['draft','sent'])]}"></div>
+				</field>
+			</field>
+		</record>
+	</data>
+</openerp>