Odoo Help


How to add a reduction amount to the amount total in POS order

on 5/9/16, 5:32 AM 873 views


I'm currently trying to add my attribute "coupon_nb" (the amount of reduction given to a customer) to the amount total in pos.order.

My code is here :

class loyalty_reward(osv.osv):

_name = 'loyalty.reward'

_columns = {

'name': fields.char('Name', size=32, select=1, required=True, help='An internal identification for this loyalty reward'),

'loyalty_program_id': fields.many2one('loyalty.program', 'Loyalty Program', help='The Loyalty Program this reward belongs to'),

'minimum_points': fields.float('Minimum Points', help='The minimum amount of points the customer must have to qualify for this reward'),

'type': fields.selection((('gift','Gift'),('discount','Discount'),('resale','Resale')), 'Type', required=True, help='The type of the reward'),

'gift_product_id': fields.many2one('product.product','Gift Product', help='The product given as a reward'),

'point_cost': fields.float('Point Cost', help='The cost of the reward'),

'discount_product_id': fields.many2one('product.product','Discount Product', help='The product used to apply discounts'),

'discount': fields.float('Discount',help='The discount percentage'),

'point_product_id': fields.many2one('product.product', 'Point Product', help='The product that represents a point that is sold by the customer'),


def _check_gift_product(self, cr, uid, ids, context=None):

for reward in self.browse(cr, uid, ids, context=context):

if reward.type == 'gift':

return bool(reward.gift_product_id)


return True

def _check_discount_product(self, cr, uid, ids, context=None):

for reward in self.browse(cr, uid, ids, context=context):

if reward.type == 'discount':

return bool(reward.discount_product_id)


return True

def _check_point_product(self, cr, uid, ids, context=None):

for reward in self.browse(cr, uid, ids, context=context):

if reward.type == 'resale':

return bool(reward.point_product_id)


return True

_constraints = [

(_check_gift_product, "The gift product field is mandatory for gift rewards", ["type","gift_product_id"]),

(_check_discount_product, "The discount product field is mandatory for discount rewards", ["type","discount_product_id"]),

(_check_point_product, "The point product field is mandatory for point resale rewards", ["type","discount_product_id"]),


<record model="ir.ui.view" id="view_pos_pos_form">

<field name="name">pos.order.inherit</field>

<field name="model">pos.order</field>

<field name="inherit_id" ref="point_of_sale.view_pos_pos_form"/>

<field name="arch" type="xml">

<xpath expr="//page[@name='extra']" position="inside">

<group name="loyalty" string="Loyalty Programs">

<field name="loyalty_points" />

<field name="coupon_nb" />





 Here I have loyalty_points and coupon_nb that are visible.

But I want coupon_nb to be used to calculate the amount total.

Here you can see the result :


But as you can see here,  the amount total doesn't change at all :


Please, help me.

I failed, the right python code is this : class pos_order(osv.osv): _inherit = 'pos.order' _columns = { 'loyalty_points': fields.float('Loyalty Points', help='The amount of Loyalty points the customer won or lost with this order'), 'coupon_nb': fields.float('Coupon Reduction', help='Coupon amount reduction'), } def _order_fields(self, cr, uid, ui_order, context=None): fields = super(pos_order,self)._order_fields(cr,uid,ui_order,context) fields['loyalty_points'] = ui_order.get('loyalty_points',0) fields['coupon_nb'] = ui_order.get('coupon_nb',0) return fields def _amount_all(self, cr, uid, ids, field_name, arg, context=None): res = super(sale_order, self)._amount_all(cr, uid, ids, field_name, arg, context) for order in self.browse(cr, uid, ids, context=context): res[order.id]['amount_total'] += order.amount_total + order.coupon_nb return res def create_from_ui(self, cr, uid, orders, context=None): ids = super(pos_order,self).create_from_ui(cr,uid,orders,context=context) for order in orders: if order['data']['coupon_nb'] != 0: orderT = self.pool.get('pos.order').browse(cr, uid, ids, context=context) orderT.write({'coupon_nb': order['data']['coupon_nb']}) if order['data']['loyalty_points'] != 0 and order['data']['partner_id']: partner = self.pool.get('res.partner').browse(cr,uid,order['data']['partner_id'], context=context) partner.write({'loyalty_points': partner['loyalty_points'] + order['data']['loyalty_points']}) return ids

on 5/9/16, 5:43 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 5/9/16, 5:32 AM
Seen: 873 times
Last updated: 5/9/16, 5:41 AM