1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 TeMPO Consulting, MSF
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
##############################################################################
23
from osv import fields
25
from tools.translate import _
28
class sale_price_setup(osv.osv_memory):
29
_name = 'sale.price.setup'
30
_inherit = 'res.config'
33
'sale_price': fields.float(digits=(16,2), string='Fields price percentage', required=True,
34
help='This percentage will be applied on field price from product form view.'),
37
def _check_sale_price_negative_value(self, cr, uid, ids, context=None):
39
Check if the entered value is more than 0.00%
41
for price in self.browse(cr, uid, ids, context=context):
48
(_check_sale_price_negative_value, 'You cannot have a negative field price percentage !', ['sale_price']),
51
def sale_price_change(self, cr, uid, ids, sale_price, context=None):
53
Check if the entered value is more than 0.00%
58
res.update({'value': {'sale_price': 0.00},
59
'warning': {'title': 'Wrong value !',
60
'message': 'You cannot have a negative field price percentage !'}})
64
def default_get(self, cr, uid, fields, context=None):
66
Display the default value for sale price
68
setup_id = self.pool.get('unifield.setup.configuration').get_config(cr, uid)
70
res = super(sale_price_setup, self).default_get(cr, uid, fields, context=context)
72
res['sale_price'] = setup_id.sale_price
76
def execute(self, cr, uid, ids, context=None):
78
Fill the delivery process field in company
80
assert len(ids) == 1, "We should only get one object from the form"
81
payload = self.browse(cr, uid, ids[0], context=context)
83
setup_obj = self.pool.get('unifield.setup.configuration')
84
pricelist_obj = self.pool.get('product.pricelist')
85
version_obj = self.pool.get('product.pricelist.version')
86
item_obj = self.pool.get('product.pricelist.item')
88
setup_id = setup_obj.get_config(cr, uid)
90
# Update all sale pricelists
91
pricelist_ids = pricelist_obj.search(cr, uid, [('type', '=', 'sale')], context=context)
92
version_ids = version_obj.search(cr, uid, [('pricelist_id', 'in', pricelist_ids)], context=context)
93
item_ids = item_obj.search(cr, uid, [('price_version_id', 'in', version_ids)], context=context)
94
item_obj.write(cr, uid, item_ids, {'price_discount': payload.sale_price/100}, context=context)
96
setup_obj.write(cr, uid, [setup_id.id], {'sale_price': payload.sale_price}, context=context)
101
class product_pricelist_item(osv.osv):
102
_name = 'product.pricelist.item'
103
_inherit = 'product.pricelist.item'
105
def create(self, cr, uid, vals, context=None):
107
if the item is related to a sale price list, get the Unifield
108
configuration value for price_discount
110
setup_id = self.pool.get('unifield.setup.configuration').get_config(cr, uid)
111
version_obj = self.pool.get('product.pricelist.version')
113
if 'price_version_id' in vals:
114
price_type = version_obj.browse(cr, uid, vals['price_version_id'], context=context).pricelist_id.type
115
if price_type == 'sale':
116
# Get the price from Unifield configuration
118
price_discount = setup_id.sale_price
119
vals.update({'price_discount': price_discount/100})
121
return super(product_pricelist_item, self).create(cr, uid, vals, context=context)
123
product_pricelist_item()
b'\\ No newline at end of file'