Parcourir la source

commit inicial

Rodney Elpidio Enciso Arias il y a 7 ans
commit
322693d6ab

+ 2 - 0
__init__.py

@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+from model import account_payment_term

BIN
__init__.pyc


+ 20 - 0
__openerp__.py

@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+{
+    'name' : 'Eiru Payment Term Generator',
+    'version' : '1.0',
+    'description' : """
+    """,
+    'author' : 'Eiru',
+    'category' : 'sale',
+    'depends' : [
+        'account',
+        'account_payment_term_extension',
+    ],
+    'data' : [
+        'views/template.xml',
+        'views/account_payment_term.xml',
+    ],
+    'qweb' : ['static/src/xml/*.xml',],
+    'installable' : True,
+    'auto_install' : False,
+}

BIN
model/__init__.pyc


+ 38 - 0
model/account_payment_term.py

@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+
+from openerp import api, fields, models
+from openerp.exceptions import except_orm
+
+class AccountPaymentTerm(models.Model):
+	_inherit = 'account.payment.term'
+
+	invoice_amount = fields.Float(string="Invoice Amount") 
+	amount = fields.Float(string="Amount")
+	frequency = fields.Selection([('week','Week'), ('month','Month')], string="Frequency")
+
+	# amount_untaxed = fields.Float( compute='_compute_amount_all') 
+	# amount_tax = fields.Float( compute='_compute_amount_all') 
+	# amount_total = fields.Float( compute='_compute_amount_all') 
+
+	# @api.model
+	# def join_sale_lines(self, values):
+	#     new_line = self.env['sale.order.line']
+	#     sale_order_line = {
+	#         'product_id': values['product_id'],
+	#         'product_uom_qty': values['product_uom_qty'],
+	#         'order_id' : values['id']
+	#     }
+
+	#     new_line.create(sale_order_line)
+
+	# @api.depends('order_line.price_subtotal')
+	# def _compute_amount_all(self):
+	# 	for order in self:
+	# 		amount_tax = amount_untaxed = 0.0
+	# 		currency = order.currency_id.with_context(date=order.date_order or fields.Date.context_today(order))
+	# 		for line in order.order_line:
+	# 			amount_untaxed += line.price_subtotal
+	# 			amount_tax += (line.product_uom_qty * line.price_unit) - line.price_subtotal
+	# 		order.amount_tax = currency.round(amount_tax)
+	# 		order.amount_untaxed = currency.round(amount_untaxed)
+	# 		order.amount_total = currency.round(amount_tax + amount_untaxed)

BIN
model/account_payment_term.pyc


BIN
model/sale.pyc


BIN
model/sale_order.pyc


BIN
static/description/icon.png


+ 240 - 0
static/src/js/account_payment_term.js

@@ -0,0 +1,240 @@
+openerp.eiru_payment_term_generator = function (instance, local) {
+    local.widgetInstance = null;
+    local.parentInstance = null;
+
+    local.AccountPaymentTermWidget = instance.Widget.extend({
+        template : "eiru_payment_term_generator.AccountPaymentTerm",
+        init:function(parent){
+            this._super(parent);
+            this.buttons = parent.$buttons;
+        },
+
+        updateId : function(id){
+            var self = this;
+            self.id=id;
+        },
+
+        reloadLine: function() {
+            local.parentInstance.reload();
+        },
+
+        start: function () {
+            var self = this;
+            this.$el.click(function () {
+                self.fecthInitial();
+            });
+        },
+
+        fecthInitial: function(){
+            var id= openerp.webclient._current_state.id;
+            var self = this;
+            self.fecthSale(id).then(function(sale){
+                return sale;
+            }).then(function(sale){
+                self.sale = sale;
+                return self.fetchProductTemplate();
+            }).then(function(ProductTemplate){
+                self.ProductTemplate = ProductTemplate;
+                return self.fetchProductProduct();
+            }).then(function(ProductProduct){
+                self.ProductProduct = ProductProduct;
+                self.inicializarBuscador();
+            });
+            return false;
+        },
+
+        fecthSale: function(id){
+            var defer = $.Deferred();
+            var fields=['id','name','partner_id','state'];
+            var domain=[['id','=', id]];
+            var Sale = new instance.web.Model('sale.order');
+            Sale.query(fields).filter(domain).order_by('id').all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+        
+        fetchProductTemplate: function () {
+            var defer = $.Deferred();
+            var fields=['id','name','curva'];
+            var domain=[['active','=', true],['product_website_sale_type','=', true],['sale_ok','=', true]];
+            var ProductTemplate = new instance.web.Model('product.template');
+            ProductTemplate.query(fields).filter(domain).order_by('id').all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        fetchProductProduct: function () {
+            var defer = $.Deferred();
+            var fields=['id','name','product_tmpl_id','attribute_str','default_code','ean13'];
+            var domain=[['active','=', true],['sale_ok','=', true]];
+            var ProductProduct = new instance.web.Model('product.product');
+            ProductProduct.query(fields).filter(domain).order_by('id').all().then(function(results){
+                defer.resolve(results);
+            });
+            return defer;
+        },
+
+        valorNull:function(dato){
+            var valor ="";
+            if (dato){
+                valor=dato;
+            }
+            return valor;
+        },
+
+        getTemplate : function(id){
+            var self = this;
+            return _.filter(self.ProductTemplate, function(item){
+                return item.id == id;
+            });
+        },
+        
+        getProduct : function(product_tmpl_id){
+            var self = this;
+            return _.filter(self.ProductProduct, function(item){
+                return item.product_tmpl_id[0] == product_tmpl_id;
+            });
+        },
+
+        getProductProduct : function(id){
+            var self = this;
+            return _.filter(self.ProductProduct, function(item){
+                return item.id == id;
+            });
+        },
+
+        inicializarBuscador: function () {
+            var self = this;
+            var selectProduct;
+            var searchType = $('#SearchByCurve').is(":checked");
+            if(searchType){
+                var results = self.ProductTemplate;
+                results = _.map(results, function (item) {
+                return {
+                        label: item.name,
+                        value: item.id + '-'+ item.name
+                    }
+                });
+                self.$('#productSearch').autocomplete({
+                    source: results,
+                    minLength:3,
+                    response: function (e, ui){
+                        if (ui.content instanceof Array && ui.content.length === 1) {
+                            selectProduct = ui.content[0];    
+                            $(this).autocomplete("close");
+                            $(this).val('');
+                            self.factInsert(selectProduct);
+                        }                
+                    },
+                    select: function (e, ui) {
+                        $(this).val('');
+                        selectProduct = ui.item;
+                        self.factInsert(selectProduct);
+                        return false;
+                    }  
+                });   
+            }else{
+                var results = self.ProductProduct;
+                results = _.map(results, function (item) {
+                return {
+                        label: '[ ' + self.valorNull(item.default_code) + ' - ' + self.valorNull(item.ean13) + ' ] ' + item.name + ' (' + self.valorNull(item.attribute_str) + ')',
+                        value: item.id + ' - '+ item.name + ' (' + item.attribute_str + ')'
+                    }
+                });
+                $('#productSearch').autocomplete({
+                    source: results,
+                    minLength: 3,
+                    response: function (e, ui){
+                        if (ui.content instanceof Array && ui.content.length === 1) {
+                            selectProduct = ui.content[0];    
+                            $(this).autocomplete("close");
+                            $(this).val('');
+                            self.factInsertProduct(selectProduct);
+                            return false;
+                        }                
+                    },
+                    select: function (e, ui) {
+                        $(this).val('');
+                        selectProduct = ui.item;
+                        self.factInsertProduct(selectProduct);
+                        return false;
+                    }  
+                });
+            }
+        },
+
+        factInsert:function(selectProduct){
+            var self = this;
+            var product = selectProduct.value.split('-');
+            var template = self.getTemplate(product[0]);
+            var variant = self.getProduct(product[0]);
+            template = template[0].curva.split(',');
+            var qty = 0;
+            var contador = 0;
+            for (var i = 0; i < variant.length; i++) {
+                qty = template[contador];
+                contador += 1;
+                self.joinSaleLine(variant[i].id, qty).then(function(results) {
+                    return results;
+                }).then(function(){
+                    self.reloadLine();
+                });
+                if (contador === template.length) { 
+                    contador = 0;
+                }
+            }
+        },
+
+        factInsertProduct:function(selectProduct){
+            var self = this;
+            var product = selectProduct.value.split('-');
+            var variant = self.getProductProduct(product[0]);
+            var qty = 1;
+            self.joinSaleLine(variant[0].id, qty).then(function(results) {
+                return results;
+            }).then(function(){
+                self.reloadLine();
+            });
+        },
+
+        joinSaleLine: function(product_id, qty) {
+            var self = this;
+            var defer = $.Deferred();
+            var sale = new openerp.web.Model('account.payment.term');
+            sale.call('join_sale_lines',[
+                {
+                    id: self.sale[0].id,
+                    product_id: product_id,
+                    product_uom_qty: qty
+                }
+            ], {
+                    context: new openerp.web.CompoundContext()
+            }).then(function(results) {
+                defer.resolve(results);
+            });
+            return defer;
+        },
+    });
+
+    if (instance.web && instance.web.FormView) {
+        instance.web.FormView.include({
+            load_form: function (record) {
+                this._super.apply(this, arguments);
+                if (this.model !== 'account.payment.term') return;
+                local.parentInstance = this;
+                if (local.widgetInstance) {
+                    local.widgetInstance.updateId(record.id);
+                }
+                local.widgetInstance = new local.AccountPaymentTermWidget(this);
+                var elemento = this.$el.find('.oe_form_nosheet');
+                console.log(elemento);
+                elemento =  elemento.find('.calculate_term_box');
+                console.log(elemento);
+                local.widgetInstance.appendTo(elemento);
+                local.widgetInstance.updateId(record.id);
+            }
+        });
+    }
+}

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

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<template xml:space="preserve">
+    <t t-name="eiru_payment_term_generator.AccountPaymentTerm">
+        <div class="ui-widget col-md-8 col-md-offset-2">
+        	<button class="btn btn-default">Button</button>
+		</div>
+    </t>
+</template>

+ 25 - 0
views/account_payment_term.xml

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+	<data>
+        <record model="ir.ui.view" id="account_payment_term_form_view">
+            <field name="name">account.payment.term.form.view</field>
+            <field name="model">account.payment.term</field>
+            <field name="inherit_id" ref="account.view_payment_term_form"/>
+            <field name="arch" type="xml">
+                <field name="note" position="after">
+                    <group strin="Calcular Cuotas">
+                        <group>
+                            <field name="invoice_amount"/>
+                            <field name="amount"/>
+                            <field name="frequency"/>  
+                        </group>
+                        <group>
+                            <div class="calculate_term_box"></div>
+                        </group>
+                    </group>
+                    
+                </field>
+            </field>
+        </record>
+	</data>
+</openerp>

+ 9 - 0
views/template.xml

@@ -0,0 +1,9 @@
+<openerp>
+    <data>
+        <template id="eiru_payment_term_generator.assets_backend" name="eiru_payment_term_generator_assets" inherit_id="eiru_assets.assets">
+            <xpath expr="." position="inside">
+                <script type="text/javascript" src="/eiru_payment_term_generator/static/src/js/account_payment_term.js"/>
+            </xpath>
+        </template>
+    </data>
+</openerp>