1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from osv import osv, fields
23 from tools.translate import _
26 class pos_discount(osv.osv_memory):
27 _name = 'pos.discount'
28 _description = 'Add Discount'
31 'discount': fields.float('Discount ', required=True),
32 'discount_notes': fields.char('Discount Notes', size= 128, required=True),
35 'discount': lambda *a: 5,
38 def apply_discount(self, cr, uid, ids, context):
40 To give the discount of product and check the.
42 @param self: The object pointer.
43 @param cr: A database cursor
44 @param uid: ID of the user currently logged in
45 @param context: A standard dictionary
48 this = self.browse(cr, uid, ids[0], context=context)
49 record_id = context and context.get('active_id', False)
50 if isinstance(record_id, (int, long)):
51 record_id = [record_id]
53 order_ref = self.pool.get('pos.order')
54 order_line_ref = self.pool.get('pos.order.line')
56 for order in order_ref.browse(cr, uid, record_id, context=context):
58 for line in order.lines:
59 company_discount = order.company_id.company_discount
60 applied_discount = this.discount
62 if applied_discount == 0.00:
63 notice = 'No Discount'
64 elif company_discount >= applied_discount:
65 notice = 'Minimum Discount'
67 notice = this.discount_notes
72 if this.discount <= company_discount:
74 'discount': this.discount,
76 'price_ded': line.price_unit * line.qty * (this.discount or 0) * 0.01 or 0.0
80 'discount': this.discount,
82 'price_ded': line.price_unit * line.qty * (this.discount or 0) * 0.01 or 0.0
85 order_line_ref.write(cr, uid, [line.id], res_new, context=context)
88 # def check_discount(self, cr, uid, record_id, discount, context):
90 # Check the discount of define by company .
91 # @param self: The object pointer.
92 # @param cr: A database cursor
93 # @param uid: ID of the user currently logged in
94 # @param record_id:Current Order id
95 # @param discount:Select Discount
96 # @param context: A standard dictionary
97 # @return : retrun to apply and used the company discount base on condition
100 # order_ref = self.pool.get('pos.order')
102 # for order in order_ref.browse(cr, uid, record_id, context=context):
103 # company_disc = order.company_id.company_discount
104 # for line in order.lines :
105 # prod_disc = discount
106 # if prod_disc <= company_disc :
107 # return 'apply_discount'
109 # return 'disc_discount'
113 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: