diff --git a/sale_discount_total/__init__.py b/sale_discount_total/__init__.py
index 2c4eac3f8..158fa9056 100644
--- a/sale_discount_total/__init__.py
+++ b/sale_discount_total/__init__.py
@@ -1 +1,2 @@
-import models
\ No newline at end of file
+import models
+import report
diff --git a/sale_discount_total/__openerp__.py~ b/sale_discount_total/__openerp__.py~
index ddf9a3994..d0b5a7ac0 100644
--- a/sale_discount_total/__openerp__.py~
+++ b/sale_discount_total/__openerp__.py~
@@ -3,7 +3,7 @@
'version': '1.0',
'category': 'sale',
'sequence': 6,
- 'summary': "extension of default Sale Management module meant to provide discount for total amount and Discount limit with approval,
+ 'summary': "extension of default Sale Management module meant to provide discount for total amount",
'author': 'Cybrosys Techno Solutions',
'company': 'Cybrosys Techno Solutions',
'website': 'http://www.cybrosys.com',
diff --git a/sale_discount_total/models/__init__.py~ b/sale_discount_total/models/__init__.py~
index 5e45c7052..aa35028cb 100644
--- a/sale_discount_total/models/__init__.py~
+++ b/sale_discount_total/models/__init__.py~
@@ -1,3 +1,2 @@
import account_invoice
import sale
-sale_discount_approval
diff --git a/sale_discount_total/models/account_invoice.py b/sale_discount_total/models/account_invoice.py
index 65b76c21e..a359c61fb 100644
--- a/sale_discount_total/models/account_invoice.py
+++ b/sale_discount_total/models/account_invoice.py
@@ -33,7 +33,6 @@ class AccountInvoice(models.Model):
@api.multi
def compute_discount(self, discount):
- print "^^^^^^^^^^^^^^^^^^^^^compute_discount"
for inv in self:
val1 = val2 = 0.0
disc_amnt = 0.0
diff --git a/sale_discount_total/models/sale.py b/sale_discount_total/models/sale.py
index 61870b364..beea07a5f 100644
--- a/sale_discount_total/models/sale.py
+++ b/sale_discount_total/models/sale.py
@@ -6,11 +6,9 @@ import openerp.addons.decimal_precision as dp
class SaleOrder(osv.Model):
_inherit = 'sale.order'
-
def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
cur_obj = self.pool.get('res.currency')
res = {}
- print "_amount_all"
for order in self.browse(cr, uid, ids, context=context):
res[order.id] = {
'amount_untaxed': 0.0,
@@ -24,12 +22,11 @@ class SaleOrder(osv.Model):
val1 += line.price_subtotal
val2 += self._amount_line_tax(cr, uid, line, context=context)
val3 += (line.product_uom_qty * line.price_unit) * line.discount / 100
- total = val1 + val2
res[order.id]['amount_untaxed'] = round(cur_obj.round(cr, uid, cur, val1))
res[order.id]['amount_tax'] = round(cur_obj.round(cr, uid, cur, val2))
res[order.id]['amount_discount'] = round(cur_obj.round(cr, uid, cur, val3))
- res[order.id]['amount_total'] = round(cur_obj.round(cr, uid, cur, total))
- return res
+ res[order.id]['amount_total'] = round(res[order.id]['amount_untaxed'] + res[order.id]['amount_tax'])
+ return res
def _get_order(self, cr, uid, ids, context=None):
result = {}
diff --git a/sale_discount_total/models/sale.py~ b/sale_discount_total/models/sale.py~
index 03e68c67f..7ad50b7f9 100644
--- a/sale_discount_total/models/sale.py~
+++ b/sale_discount_total/models/sale.py~
@@ -6,11 +6,9 @@ import openerp.addons.decimal_precision as dp
class SaleOrder(osv.Model):
_inherit = 'sale.order'
-
def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
cur_obj = self.pool.get('res.currency')
res = {}
- print "_amount_all"
for order in self.browse(cr, uid, ids, context=context):
res[order.id] = {
'amount_untaxed': 0.0,
@@ -18,17 +16,21 @@ class SaleOrder(osv.Model):
'amount_tax': 0.0,
'amount_total': 0.0,
}
+ val = val1 = val2 = 0.0
cur = order.pricelist_id.currency_id
- val1 = val2 = val3 = 0.0
for line in order.order_line:
val1 += line.price_subtotal
- val2 += self._amount_line_tax(cr, uid, line, context=context)
- val3 += (line.product_uom_qty * line.price_unit) * line.discount / 100
- total = val1 + val2
- res[order.id]['amount_untaxed'] = round(cur_obj.round(cr, uid, cur, val1))
- res[order.id]['amount_tax'] = round(cur_obj.round(cr, uid, cur, val2))
- res[order.id]['amount_discount'] = round(cur_obj.round(cr, uid, cur, val3))
- res[order.id]['amount_total'] = round(cur_obj.round(cr, uid, cur, total))
+ val += self._amount_line_tax(cr, uid, line, context=context)
+ if order.discount_type == 'amount':
+ val2 = order.discount_rate
+ elif order.discount_type == 'percent':
+ val2 = ((val1 + val) * order.discount_rate) / 100
+ 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_discount'] = cur_obj.round(cr, uid, cur, val2)
+ res[order.id]['amount_total'] = res[order.id]['amount_untaxed'] + res[order.id]['amount_tax'] - \
+ res[order.id]['amount_discount']
+ return res
def _get_order(self, cr, uid, ids, context=None):
result = {}
@@ -40,7 +42,7 @@ class SaleOrder(osv.Model):
'discount_type': fields.selection([
('percent', 'Percentage'),
('amount', 'Amount')], 'Discount type'),
- 'discount_rate': fields.float('Discount Rate', digits_compute=dp.get_precision('Account'),
+ 'discount_rate': fields.float('Discount Amount', digits_compute=dp.get_precision('Account'),
readonly=True,
states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, ),
'amount_discount': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Discount',
@@ -58,33 +60,27 @@ class SaleOrder(osv.Model):
'discount_type': 'percent',
}
- @api.multi
- def compute_discount(self, discount):
+ @api.onchange('discount_type', 'discount_rate')
+ def compute_discount(self):
for order in self:
val1 = val2 = 0.0
- disc_amnt = 0.0
for line in order.order_line:
- val1 += (line.product_uom_qty * line.price_unit)
- line.discount = discount
+ val1 += line.price_subtotal
val2 += self._amount_line_tax(line)
- disc_amnt += (line.product_uom_qty * line.price_unit * line.discount)/100
- total = val1 + val2 - disc_amnt
- self.currency_id = order.pricelist_id.currency_id
- self.amount_discount = round(disc_amnt)
- self.amount_tax = round(val2)
- self.amount_total = round(total)
-
- @api.onchange('discount_type', 'discount_rate')
- def supply_rate(self):
- for order in self:
if order.discount_type == 'percent':
- self.compute_discount(order.discount_rate)
+ if order.discount_rate == 100:
+ disc_amnt = val1 + val2
+ else:
+ disc_amnt = (val1 + val2) * order.discount_rate / 100
+ total = val1 + val2 - disc_amnt
+ self.currency_id = order.pricelist_id.currency_id
+ self.amount_discount = disc_amnt
+ self.amount_total = total
else:
- total = 0.0
- for line in order.order_line:
- total += (line.product_uom_qty * line.price_unit)
- discount = (order.discount_rate / total) * 100
- self.compute_discount(discount)
+ total = (val1 + val2) - order.discount_rate
+ self.currency_id = order.pricelist_id.currency_id
+ self.amount_discount = order.discount_rate
+ self.amount_total = total
def _prepare_invoice(self, cr, uid, order, lines, context=None):
invoice_vals = super(SaleOrder, self)._prepare_invoice(cr, uid, order, lines, context=context)
diff --git a/sale_discount_total/models/sale_discount_approval.py b/sale_discount_total/models/sale_discount_approval.py
index b80c48ff5..409411bb6 100644
--- a/sale_discount_total/models/sale_discount_approval.py
+++ b/sale_discount_total/models/sale_discount_approval.py
@@ -84,33 +84,6 @@ class SaleInherit(osv.Model):
no_line += 1
discnt += line.discount
discnt = (discnt / no_line)
- # if sale_obj.discount_type == "percent":
- # dicnt_amt = sale_obj.discount_rate
- # if dicnt_amt >= min_disct:
- # assert len(ids) == 1, 'This option should only be used for a single id at a time.'
- # self.signal_workflow(cr, uid, ids, 'order_toapprov')
- # return True
- #
- # else:
- #
- # for line in sale_obj.order_line:
- # no_line += 1
- # discnt = discnt + line.discount
- # if dicnt_amt:
- # discnt = (discnt / no_line) + dicnt_amt
- # else:
- # discnt = (discnt / no_line)
- #
- # else:
- # dicnt_amt = sale_obj.discount_rate
- # for line in sale_obj.order_line:
- # prod_price = prod_price + line.price_unit
- # no_line += 1
- # if line.discount:
- # line_dicnt = line_dicnt + line.discount
- # line_dicnt = line_dicnt/no_line
- # prcnt = 100 - (((prod_price - dicnt_amt) * 100) / prod_price)
- # discnt = prcnt + line_dicnt
if discnt >= min_disct:
assert len(ids) == 1, 'This option should only be used for a single id at a time.'
self.signal_workflow(cr, uid, ids, 'order_toapprov')
diff --git a/sale_discount_total/report/__init__.py b/sale_discount_total/report/__init__.py
new file mode 100644
index 000000000..998ed8390
--- /dev/null
+++ b/sale_discount_total/report/__init__.py
@@ -0,0 +1,2 @@
+import sale_report
+import invoice_report
\ No newline at end of file
diff --git a/sale_discount_total/report/invoice_report.py b/sale_discount_total/report/invoice_report.py
new file mode 100644
index 000000000..352d533b0
--- /dev/null
+++ b/sale_discount_total/report/invoice_report.py
@@ -0,0 +1,22 @@
+from openerp.osv import fields, osv
+
+
+class DiscountInvoiceReport(osv.osv):
+ _inherit = 'account.invoice.report'
+
+ _columns = {
+ 'discount': fields.float('Discount', readonly=True),
+ }
+
+ def _select(self):
+ res = super(DiscountInvoiceReport,self)._select()
+ select_str = res + """, sub.discount / cr.rate as discount """
+ return select_str
+
+ def _sub_select(self):
+ res = super(DiscountInvoiceReport,self)._sub_select()
+ select_str = res + """,SUM(CASE
+ WHEN ai.type::text = ANY (ARRAY['out_refund'::character varying::text, 'in_invoice'::character varying::text])
+ THEN - ((ail.quantity / u.factor * u2.factor) * ail.price_unit * (ail.discount) / 100.0)
+ ELSE ((ail.quantity / u.factor * u2.factor) * ail.price_unit * (ail.discount) / 100.0) END) as discount"""
+ return select_str
diff --git a/sale_discount_total/report/sale_report.py b/sale_discount_total/report/sale_report.py
new file mode 100644
index 000000000..29b95b06f
--- /dev/null
+++ b/sale_discount_total/report/sale_report.py
@@ -0,0 +1,14 @@
+from openerp.osv import fields, osv
+
+
+class DiscountSaleReport(osv.osv):
+ _inherit = 'sale.report'
+
+ _columns = {
+ 'discount': fields.float('Discount', readonly=True),
+ }
+
+ def _select(self):
+ res = super(DiscountSaleReport,self)._select()
+ select_str = res+""",sum(l.product_uom_qty * cr.rate * l.price_unit * (l.discount) / 100.0) as discount"""
+ return select_str
diff --git a/sale_discount_total/views/sale_discount_approval_workflow.xml b/sale_discount_total/views/sale_discount_approval_workflow.xml
index 6c81a03d9..84631a160 100644
--- a/sale_discount_total/views/sale_discount_approval_workflow.xml
+++ b/sale_discount_total/views/sale_discount_approval_workflow.xml
@@ -19,6 +19,9 @@
waitingapproval,manual,progress
+
+ waitingapproval,manual,progress
+