~initos.com/initos.com-openerp-addons/7.0

« back to all changes in this revision

Viewing changes to pricelist_discount/product.py

  • Committer: Thomas Rehn
  • Date: 2014-01-14 09:26:00 UTC
  • Revision ID: thomas.rehn@initos.com-20140114092600-luhqdulgnh7bf7ib
migrated *pricelist_discount modules from lp:~syleam/syleam-modules/6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    pricelist_discount module for OpenERP, Pricelist Discount
 
5
#    Copyright (C) 2009 SYLEAM Info Services (<http://www.syleam.fr/>)
 
6
#              Jean-Sébastien SUZANNE <jean-sebastien.suzanne@syleam.fr>
 
7
#    Copyright (C) 2012 SYLEAM Info Services (<http://www.syleam.fr/>)
 
8
#              Benoît MOTTIN <benoit.mottin@syleam.fr>
 
9
#              Sebastien LANGE <sebastien.lange@syleam.fr>
 
10
#    Copyright (C) 2013 initOS GmbH & Co. KG <http://www.initos.com>
 
11
#
 
12
#    This file is a part of pricelist_discount
 
13
#
 
14
#    pricelist_discount is free software: you can redistribute it and/or modify
 
15
#    it under the terms of the GNU Affero General Public License as published
 
16
#    by the Free Software Foundation, either version 3 of the License, or
 
17
#    (at your option) any later version.
 
18
#
 
19
#    pricelist_discount is distributed in the hope that it will be useful,
 
20
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
#    GNU Affero General Public License for more details.
 
23
#
 
24
#    You should have received a copy of the GNU Affero General Public License
 
25
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
26
#
 
27
##############################################################################
 
28
 
 
29
from osv import osv, fields
 
30
 
 
31
 
 
32
class product_pricelist(osv.Model):
 
33
    _inherit = "product.pricelist"
 
34
 
 
35
    def price_get(self, cr, uid, ids, prod_id, qty, partner=None,
 
36
                  context=None):
 
37
        """
 
38
        Add discount if set in result
 
39
        """
 
40
        context = context or {}
 
41
        result = super(product_pricelist, self)\
 
42
            .price_get(cr, uid, ids, prod_id, qty,
 
43
                       partner=partner, context=context)
 
44
        if 'discount' in context:
 
45
            discount = self.pool.get('product.pricelist.item')\
 
46
                           .browse(cr, uid, result['item_id'].values()[0],
 
47
                                   context=context)\
 
48
                           .discount or False
 
49
            if discount:
 
50
                result.update({'discount': discount})
 
51
        return result
 
52
 
 
53
 
 
54
class product_pricelist_item(osv.Model):
 
55
    _inherit = 'product.pricelist.item'
 
56
 
 
57
    _columns = {
 
58
        'discount': fields.float('Discount (%)', digits=(16, 2)),
 
59
    }
 
60
 
 
61
    _defaults = {
 
62
        'discount': 0.0,
 
63
    }
 
64
 
 
65
 
 
66
 
 
67
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: