소스 검색

[ADD] Se mejoro la inserción de registros y se agrego gran parte de las validaciones

Rodney Elpidio Enciso Arias 7 년 전
부모
커밋
4371fc57b6
4개의 변경된 파일75개의 추가작업 그리고 181개의 파일을 삭제
  1. 14 26
      model/account_payment_term.py
  2. BIN
      model/account_payment_term.pyc
  3. 60 154
      static/src/js/account_payment_term.js
  4. 1 1
      static/src/xml/account_payment_term_button.xml

+ 14 - 26
model/account_payment_term.py

@@ -10,29 +10,17 @@ class AccountPaymentTerm(models.Model):
 	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)
+	@api.model
+	def join_payment_term_lines(self, values):
+		new_line = self.env['account.payment.term.line']
+		for x in values:
+			payment_term_line = ( {
+			    'payment_id': x['payment_id'],
+			    'value': x['value'],
+			    'value_amount' : x['value_amount'],
+			    'days' : x['days'],
+			    'days2' : x['days2'],
+			    'weeks' : x['weeks'],
+			    'months' : x['months'],
+			})
+			new_line.create(payment_term_line)

BIN
model/account_payment_term.pyc


+ 60 - 154
static/src/js/account_payment_term.js

@@ -28,188 +28,96 @@ openerp.eiru_payment_term_generator = function (instance, local) {
         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();
+            self.fecthAccountPaymentTerm(id).then(function(PaymentTerm){
+                return PaymentTerm;
+            }).then(function(PaymentTerm){
+                self.PaymentTerm = PaymentTerm;
+                return self.fetchAccountPaymentTermLine();
+            }).then(function(PaymentTermLine){
+                self.PaymentTermLine = PaymentTermLine;
+                self.fectchCalculatePaymentTerm();
             });
             return false;
         },
 
-        fecthSale: function(id){
+        fecthAccountPaymentTerm: function(id){
+            var self = this;
             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){
+            var fields=['id','name','invoice_amount','amount','frequency','active'];
+            var PaymentTerm = new instance.web.Model('account.payment.term');
+            PaymentTerm.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 () {
+        fetchAccountPaymentTermLine: function () {
+            var self = this;
             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){
+            var id = _.flatten(_.map(self.PaymentTerm,function(map){
+                return map.id;
+            }));
+            var fields=['id','payment_id','value','days','days2','weeks','months','value_amount','amount_round'];
+            var domain=[['payment_id','in', id]];
+            var PaymentTermLine = new instance.web.Model('account.payment.term.line');
+            PaymentTermLine.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){
+        fectchCalculatePaymentTerm: function () {
             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;
-                    }  
-                });   
+            var defer = $.Deferred();
+            var data = [];
+            var type = 'fixed';
+            var PaymentTerm = self.PaymentTerm;
+            var months_count = 0;
+            var weeks_count = 0;
+            var paid = 0;
+            var value_amount = 0;
+            var qty = PaymentTerm[0].invoice_amount / PaymentTerm[0].amount;
+            if (qty % 1 == 0) {
+                qty-=1
             }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;
-                    }  
-                });
+                qty = Math.trunc(qty)
             }
-        },
-
-        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();
+            for (var i = 0; i <= qty; i++) {
+                value_amount = PaymentTerm[0].amount;
+                if(i == qty){
+                    type = 'balance';
+                    value_amount = PaymentTerm[0].invoice_amount - paid;
+                } 
+                paid += PaymentTerm[0].amount;
+                data.push({
+                    payment_id : PaymentTerm[0].id,
+                    value : type,
+                    value_amount : value_amount,
+                    days : 0,
+                    days2 : 0,
+                    weeks : weeks_count,
+                    months : months_count
                 });
-                if (contador === template.length) { 
-                    contador = 0;
+
+                if(PaymentTerm[0].frequency == 'week'){
+                    weeks_count += 1;       
+                }else{
+                    months_count += 1;
                 }
             }
-        },
-
-        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) {
+            self.joinPaymentTermLine(data).then(function(results) {
                 return results;
             }).then(function(){
                 self.reloadLine();
             });
         },
 
-        joinSaleLine: function(product_id, qty) {
+        joinPaymentTermLine: function(data) {
             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
-                }
-            ], {
+            var AccountPaymentTerm = new openerp.web.Model('account.payment.term');
+            AccountPaymentTerm.call('join_payment_term_lines',[data], {
                     context: new openerp.web.CompoundContext()
             }).then(function(results) {
                 defer.resolve(results);
@@ -229,9 +137,7 @@ openerp.eiru_payment_term_generator = function (instance, local) {
                 }
                 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);
+                elemento =  elemento.find('.calculate_term_box');              
                 local.widgetInstance.appendTo(elemento);
                 local.widgetInstance.updateId(record.id);
             }

+ 1 - 1
static/src/xml/account_payment_term_button.xml

@@ -2,7 +2,7 @@
 <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>
+        	<button class="oe_button oe_form_button oe_highlight calculate-payment-term" type="button">Calcular</button>
 		</div>
     </t>
 </template>