Skip to content

Instantly share code, notes, and snippets.

@aadimator
Last active August 12, 2017 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aadimator/a944b368b4187914ee70ed183c61c3a5 to your computer and use it in GitHub Desktop.
Save aadimator/a944b368b4187914ee70ed183c61c3a5 to your computer and use it in GitHub Desktop.
Student Discount
def create(self, cr, uid, vals, context=None, check=True):
# Calculate the acutal_fee and discounts again as readonly fields aren't
# stored in the database.
std_id = vals.get('student_id')
res = self.onchange_get_actual_fee(cr, uid, std_id, std_id, vals.get('fee_type'), context)
acutal_fee = res.get('value').get('actual_fee')
discounted_fee = acutal_fee - (vals.get('discount') * acutal_fee/100)
vals.update({'actual_fee':acutal_fee})
vals.update({'discounted_fee':discounted_fee})
result = super(osv.osv, self).create(cr, uid, vals, context)
return result
def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
# Calculate the acutal_fee and discounts again as readonly fields aren't
# stored in the database.
std_id = vals.get('student_id')
res = self.onchange_get_actual_fee(cr, uid, std_id, std_id, vals.get('fee_type'), context)
acutal_fee = res.get('value').get('actual_fee')
discounted_fee = acutal_fee - (vals.get('discount') * acutal_fee/100)
vals.update({'actual_fee':acutal_fee})
vals.update({'discounted_fee':discounted_fee})
result = super(osv.osv, self).write(cr, uid, ids, vals, context)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment