1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6
# Copyright (C) 2013 Agile Business Group sagl (<http://www.agilebg.com>)
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU Affero General Public License as
10
# published by the Free Software Foundation, either version 3 of the
11
# License, or (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU Affero General Public License for more details.
18
# You should have received a copy of the GNU Affero General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
23
from openerp.osv import fields, orm
24
from openerp.tools.translate import _
25
import openerp.addons.decimal_precision as dp
28
class change_standard_price(orm.TransientModel):
29
_name = "lot.change.standard.price"
30
_description = "Change Standard Price"
32
'new_price': fields.float(
33
'Price', required=True,
34
digits_compute=dp.get_precision('Account'),
35
help="If cost price is increased, stock variation account will be "
36
"debited and stock output account will be credited with the "
37
"value = (difference of amount * quantity available).\n"
38
"If cost price is decreased, stock variation account will be "
39
"creadited and stock input account will be debited."
41
'stock_account_input': fields.many2one(
42
'account.account', 'Stock Input Account'),
43
'stock_account_output': fields.many2one(
44
'account.account', 'Stock Output Account'),
45
'stock_journal': fields.many2one(
46
'account.journal', 'Stock journal', required=True),
47
'enable_stock_in_out_acc': fields.boolean('Enable Related Account',),
50
def default_get(self, cr, uid, fields, context=None):
51
""" To get default values for the object.
52
@param self: The object pointer.
53
@param cr: A database cursor
54
@param uid: ID of the user currently logged in
55
@param fields: List of fields for which we want default values
56
@param context: A standard dictionary
57
@return: A dictionary which of fields with values.
61
lot_pool = self.pool.get('stock.production.lot')
62
product_pool = self.pool.get('product.product')
63
lot_obj = lot_pool.browse(cr, uid, context.get('active_id', False))
64
res = super(change_standard_price, self).default_get(
65
cr, uid, fields, context=context)
67
accounts = product_pool.get_product_accounts(
68
cr, uid, lot_obj.product_id.id, context={})
70
price = lot_obj.standard_price
72
if 'new_price' in fields:
73
res.update({'new_price': price})
74
if 'stock_account_input' in fields:
76
{'stock_account_input': accounts['stock_account_input']})
77
if 'stock_account_output' in fields:
79
{'stock_account_output': accounts['stock_account_output']})
80
if 'stock_journal' in fields:
81
res.update({'stock_journal': accounts['stock_journal']})
82
if 'enable_stock_in_out_acc' in fields:
83
res.update({'enable_stock_in_out_acc': True})
87
def change_price(self, cr, uid, ids, context=None):
88
""" Changes the Standard Price of Product.
89
And creates an account move accordingly.
90
@param self: The object pointer.
91
@param cr: A database cursor
92
@param uid: ID of the user currently logged in
93
@param ids: List of IDs selected
94
@param context: A standard dictionary
99
rec_id = context and context.get('active_id', False)
100
assert rec_id, _('Active ID is not set in Context.')
101
lot_pool = self.pool.get('stock.production.lot')
102
res = self.browse(cr, uid, ids, context=context)
104
'new_price': res[0].new_price,
105
'stock_output_account': res[0].stock_account_output.id,
106
'stock_input_account': res[0].stock_account_input.id,
107
'stock_journal': res[0].stock_journal.id
109
lot_pool.do_change_standard_price(cr, uid, [rec_id], datas, context)
110
return {'type': 'ir.actions.act_window_close'}