Kaynağa Gözat

[ADD] nuevo metodo para calcular totales

Rodney Enciso Arias 7 yıl önce
ebeveyn
işleme
f57e106a63

+ 1 - 0
__init__.py

@@ -1,2 +1,3 @@
 # -*- coding: utf-8 -*-
 from model import sale_order
+# from model import sale

BIN
__init__.pyc


+ 37 - 0
model/sale.py

@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+
+from datetime import datetime, timedelta
+import time
+from openerp import SUPERUSER_ID
+from openerp.osv import fields, osv
+from openerp.tools.translate import _
+from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
+import openerp.addons.decimal_precision as dp
+from openerp import workflow
+
+class sale_order(osv.osv):
+    _inherit = "sale.order"
+
+    def _amount_all_wrapper(self, cr, uid, ids, field_name, arg, context=None):
+        """ Wrapper because of direct method passing as parameter for function fields """
+        return self._amount_all(cr, uid, ids, field_name, arg, context=context)
+
+    def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
+        cur_obj = self.pool.get('res.currency')
+        res = {}
+        # print "******************************algo*************************"
+        # for order in self.browse(cr, uid, ids, context=context):
+        #     res[order.id] = {
+        #         'amount_untaxed': 0.0,
+        #         'amount_tax': 0.0,
+        #         'amount_total': 0.0,
+        #     }
+        #     val = val1 = 0.0
+        #     cur = order.pricelist_id.currency_id
+        #     for line in order.order_line:
+        #         val1 += line.price_subtotal
+        #         val += self._amount_line_tax(cr, uid, line, context=context)
+        #     res[order.id]['amount_tax'] = cur_obj.round(cr, uid, cur, val)
+        #     res[order.id]['amount_untaxed'] = cur_obj.round(cr, uid, cur, val1)
+        #     res[order.id]['amount_total'] = res[order.id]['amount_untaxed'] + res[order.id]['amount_tax']
+        # return res

BIN
model/sale.pyc


+ 16 - 1
model/sale_order.py

@@ -6,6 +6,9 @@ from openerp.exceptions import except_orm
 class SaleOrder(models.Model):
 	_inherit = 'sale.order'
 
+	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_payslip_faults(self, values):
@@ -17,4 +20,16 @@ class SaleOrder(models.Model):
 	        'order_id' : values['id']
 	    }
 
-	    new_line.create(sale_order_line)
+	    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/sale_order.pyc


+ 4 - 2
static/src/js/account_bank_statement.js

@@ -154,12 +154,13 @@ openerp.eiru_sale_order = function (instance, local) {
                 qty = template[contador];
                 contador += 1;
                 
+                // self.joinSaleLine(variant[i].id, qty);
                 self.joinSaleLine(variant[i].id, qty).then(function(results) {
                     return results;
                 }).then(function(results){
                     self.reloadLine();
-                    if (!results)
-                        results = false;
+                    // if (!results)
+                    //     results = false;
                 });
 
                 // break;
@@ -167,6 +168,7 @@ openerp.eiru_sale_order = function (instance, local) {
                     contador = 0;
                 }
             }
+            // self.reloadLine();
         },
 
         // llama el metodo de insert en el python