Browse Source

removed rounding

master
cybroodoo 9 years ago
parent
commit
a9ac5e256b
  1. 8
      sale_discount_total/models/sale.py
  2. 64
      sale_discount_total/models/sale.py~

8
sale_discount_total/models/sale.py

@ -22,10 +22,10 @@ class SaleOrder(osv.Model):
val1 += line.price_subtotal val1 += line.price_subtotal
val2 += self._amount_line_tax(cr, uid, line, context=context) val2 += self._amount_line_tax(cr, uid, line, context=context)
val3 += (line.product_uom_qty * line.price_unit) * line.discount / 100 val3 += (line.product_uom_qty * line.price_unit) * line.discount / 100
res[order.id]['amount_untaxed'] = round(cur_obj.round(cr, uid, cur, val1)) res[order.id]['amount_untaxed'] = cur_obj.round(cr, uid, cur, val1)
res[order.id]['amount_tax'] = round(cur_obj.round(cr, uid, cur, val2)) res[order.id]['amount_tax'] = cur_obj.round(cr, uid, cur, val2)
res[order.id]['amount_discount'] = round(cur_obj.round(cr, uid, cur, val3)) res[order.id]['amount_discount'] = cur_obj.round(cr, uid, cur, val3)
res[order.id]['amount_total'] = round(res[order.id]['amount_untaxed'] + res[order.id]['amount_tax']) res[order.id]['amount_total'] = res[order.id]['amount_untaxed'] + res[order.id]['amount_tax']
return res return res
def _get_order(self, cr, uid, ids, context=None): def _get_order(self, cr, uid, ids, context=None):

64
sale_discount_total/models/sale.py~

@ -16,20 +16,16 @@ class SaleOrder(osv.Model):
'amount_tax': 0.0, 'amount_tax': 0.0,
'amount_total': 0.0, 'amount_total': 0.0,
} }
val = val1 = val2 = 0.0
cur = order.pricelist_id.currency_id cur = order.pricelist_id.currency_id
val1 = val2 = val3 = 0.0
for line in order.order_line: for line in order.order_line:
val1 += line.price_subtotal val1 += line.price_subtotal
val += self._amount_line_tax(cr, uid, line, context=context) val2 += self._amount_line_tax(cr, uid, line, context=context)
if order.discount_type == 'amount': val3 += (line.product_uom_qty * line.price_unit) * line.discount / 100
val2 = order.discount_rate res[order.id]['amount_untaxed'] = round(cur_obj.round(cr, uid, cur, val1))
elif order.discount_type == 'percent': res[order.id]['amount_tax'] = round(cur_obj.round(cr, uid, cur, val2))
val2 = ((val1 + val) * order.discount_rate) / 100 res[order.id]['amount_discount'] = round(cur_obj.round(cr, uid, cur, val3))
res[order.id]['amount_tax'] = cur_obj.round(cr, uid, cur, val) res[order.id]['amount_total'] = round(res[order.id]['amount_untaxed'] + res[order.id]['amount_tax'])
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 return res
def _get_order(self, cr, uid, ids, context=None): def _get_order(self, cr, uid, ids, context=None):
@ -42,45 +38,51 @@ class SaleOrder(osv.Model):
'discount_type': fields.selection([ 'discount_type': fields.selection([
('percent', 'Percentage'), ('percent', 'Percentage'),
('amount', 'Amount')], 'Discount type'), ('amount', 'Amount')], 'Discount type'),
'discount_rate': fields.float('Discount Amount', digits_compute=dp.get_precision('Account'), 'discount_rate': fields.float('Discount Rate', digits_compute=dp.get_precision('Account'),
readonly=True, readonly=True,
states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, ), states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, ),
'amount_discount': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Discount', 'amount_discount': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Discount',
multi='sums', help="The total discount."), multi='sums', store=True, help="The total discount."),
'amount_untaxed': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), 'amount_untaxed': fields.function(_amount_all, digits_compute=dp.get_precision('Account'),
string='Untaxed Amount', string='Untaxed Amount',
multi='sums', help="The amount without tax.", track_visibility='always'), multi='sums', store=True, help="The amount without tax.", track_visibility='always'),
'amount_tax': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Taxes', 'amount_tax': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Taxes',
multi='sums', help="The tax amount."), multi='sums', store=True, help="The tax amount."),
'amount_total': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Total', 'amount_total': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Total',
multi='sums', help="The total amount."), multi='sums', store=True, help="The total amount."),
} }
_defaults = { _defaults = {
'discount_type': 'percent', 'discount_type': 'percent',
} }
@api.onchange('discount_type', 'discount_rate') @api.multi
def compute_discount(self): def compute_discount(self, discount):
for order in self: for order in self:
val1 = val2 = 0.0 val1 = val2 = 0.0
disc_amnt = 0.0
for line in order.order_line: for line in order.order_line:
val1 += line.price_subtotal val1 += (line.product_uom_qty * line.price_unit)
line.discount = discount
val2 += self._amount_line_tax(line) 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': if order.discount_type == 'percent':
if order.discount_rate == 100: self.compute_discount(order.discount_rate)
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: else:
total = (val1 + val2) - order.discount_rate total = 0.0
self.currency_id = order.pricelist_id.currency_id for line in order.order_line:
self.amount_discount = order.discount_rate total += (line.product_uom_qty * line.price_unit)
self.amount_total = total discount = (order.discount_rate / total) * 100
self.compute_discount(discount)
def _prepare_invoice(self, cr, uid, order, lines, context=None): def _prepare_invoice(self, cr, uid, order, lines, context=None):
invoice_vals = super(SaleOrder, self)._prepare_invoice(cr, uid, order, lines, context=context) invoice_vals = super(SaleOrder, self)._prepare_invoice(cr, uid, order, lines, context=context)

Loading…
Cancel
Save