from __future__ import division
from openerp import fields, models, api, osv
import openerp.addons.decimal_precision as dp
import math
class saleorder_discount(models.Model):
_inherit = 'sale.order'
fee_type = fields.Selection([('Blind Ship', 'Blind Ship'), ('Blind Ship Rush', 'Blind Ship Rush')], string='Fee Type',
states={'draft': [('readonly', False)]},
help='Fee is percentage of subtotal plus fixed fee')
minimum_order_fee_exempt = fields.Boolean('Exempt from Minimum Order Fee', help='If checked, customer will not be charged any fees even if the order is under the minimum.')
discounted_amount = fields.Float(string='Fees', store=True, readonly=True, compute='compute_amounts')
amount_total = fields.Float(string='Total', digits=dp.get_precision('Account'),
store=True, readonly=True, compute='compute_amounts')
def _prepare_invoice(self, cr, uid, order, lines, context=None):
res = super(saleorder_discount, self)._prepare_invoice(cr, uid, order, lines, context=context)
res.update({'fee_type' : order.fee_type,
'minimum_order_fee_exempt' : order.minimum_order_fee_exempt})
return res
@api.one
@api.onchange('minimum_order_fee_exempt','fee_type')
@api.depends('order_line.price_subtotal', 'discounted_amount', 'fee_type', 'minimum_order_fee_exempt')
def compute_amounts(self):
self.amount_untaxed = sum(line.price_subtotal for line in self.order_line)
# Get "order amount" without shipping charges because they don't count towards the minimum
price_shipping = 0
for line in self.order_line:
if line.product_id.default_code in ['mage_shipping','Shipping Charge'] or line.name in ['Magento Shipping','Shipping Charge']:
price_shipping += line.price_subtotal
elif line.name in ['Discount - Low Order Fee']:
self.minimum_order_fee_exempt = True
price_subtotal_excluding_shipping = self.amount_untaxed - price_shipping
val = 0
minimum_order_amt = 25.00
if self.name.count('-') >= 2:
self.minimum_order_fee_exempt = True
if price_subtotal_excluding_shipping < minimum_order_amt and not self.minimum_order_fee_exempt:
low_order_fee = 10.00
else:
low_order_fee = 0.00
for line in self.order_line:
val += self._amount_line_tax(line)
print "Fee Type: " + str(self.fee_type)
if self.fee_type == 'Blind Ship Rush':
fee_fixed = 20.00
fee_percentage = 0.05
amount_to_dis = round( (price_subtotal_excluding_shipping) * (fee_percentage) , 2)
self.discounted_amount = amount_to_dis + fee_fixed + low_order_fee
self.amount_total = self.amount_untaxed + val + amount_to_dis + fee_fixed + low_order_fee
elif self.fee_type == 'Blind Ship':
fee_fixed = 10.00
fee_percentage = 0.035
amount_to_dis = round( (price_subtotal_excluding_shipping) * (fee_percentage) , 2)
self.discounted_amount = amount_to_dis + fee_fixed + low_order_fee
self.amount_total = self.amount_untaxed + val + amount_to_dis + fee_fixed + low_order_fee
elif price_subtotal_excluding_shipping < minimum_order_amt and not self.minimum_order_fee_exempt:
self.discounted_amount = low_order_fee
self.amount_total = self.amount_untaxed + val + low_order_fee
else:
self.discounted_amount = 0
self.amount_total = self.amount_untaxed + val
print "Fees: $" + str(self.discounted_amount)
print "Amount Total: $" + str(self.amount_total)
Simple Module
please post your code here
I created an answer with relevant code (unable to edit original question). Thanks.