~therp-nl/openerp-product-attributes/7.0_lp1272282_fixed_price

« back to all changes in this revision

Viewing changes to product_pricelist_fixed_price/model/product_pricelist_version.py

  • Committer: Ronald Portier
  • Date: 2014-02-03 14:35:10 UTC
  • Revision ID: ronald@therp.nl-20140203143510-7a29aid9yeinjh45
[ENH] - Enable mixing of fixed and traditional prices in the same pricelists.
[ENH] - Add functionality for fixed prices to traditional views.
[FIX] - whitespace and convention issues.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#-*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2014 Therp BV        (<http://www.therp.nl>).
 
6
#
 
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.
 
11
#
 
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.
 
16
#
 
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/>.
 
19
#
 
20
##############################################################################
 
21
 
2
22
from openerp.osv import orm, fields
3
23
from openerp.tools.translate import _
4
24
 
7
27
    _inherit = 'product.pricelist.version'
8
28
 
9
29
    _columns = {
10
 
        'fixed_price': fields.boolean('Fixed price'),
 
30
        'fixed_price': fields.boolean(
 
31
            'Fixed price',
 
32
            help='Pricelist intended for fixed prices.',
 
33
        ),
11
34
    }
12
35
 
13
 
    def _check_fixed_price(self, cr, user, ids):                          
14
 
        '''Raise exception when error found, else return True'''
15
 
        for this_obj in self.browse(cr, user, ids):
16
 
            if not this_obj.fixed_price:
17
 
                if this_obj.pricelist_id.fixed_price:
18
 
                    raise orm.except_orm(
19
 
                        _('Validation error!'),
20
 
                        _('Fixed pricelist should have fixed price versions.')
21
 
                    )
22
 
                return True
23
 
            # Check values for fixed price item
24
 
            if not this_obj.price_version_id.fixed_price:
25
 
                raise orm.except_orm(
26
 
                    _('Validation error!'),
27
 
                    _('Fixed price version only valid on fixed pricelist.')
28
 
                )
29
 
        return True                                                            
30