~numerigraphe-team/stock-logistic-warehouse/7.0-add-stock-available

« back to all changes in this revision

Viewing changes to stock_lot_valuation/wizard/stock_change_standard_price.py

  • Committer: Joel Grand-Guillaume
  • Author(s): lorenzo.battistini at agilebg
  • Date: 2013-11-01 09:40:45 UTC
  • mfrom: (29.3.35 adding_stock_lot_costing)
  • Revision ID: joel.grandguillaume@camptocamp.com-20131101094045-2uac738fcfgfopb7
[MRG][ADD] stock_lot_valuation : Stock valuation (standard or average price, ...) based on lots.
This module extends standard stock valuation (based on products). Valuing lots allows to have different costs for different lots of the same product.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
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>)
 
7
#
 
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.
 
12
#
 
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.
 
17
#
 
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/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
from openerp.osv import fields, orm
 
24
from openerp.tools.translate import _
 
25
import openerp.addons.decimal_precision as dp
 
26
 
 
27
 
 
28
class change_standard_price(orm.TransientModel):
 
29
    _name = "lot.change.standard.price"
 
30
    _description = "Change Standard Price"
 
31
    _columns = {
 
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."
 
40
        ),
 
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',),
 
48
    }
 
49
 
 
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.
 
58
        """
 
59
        if context is None:
 
60
            context = {}
 
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)
 
66
 
 
67
        accounts = product_pool.get_product_accounts(
 
68
            cr, uid, lot_obj.product_id.id, context={})
 
69
 
 
70
        price = lot_obj.standard_price
 
71
 
 
72
        if 'new_price' in fields:
 
73
            res.update({'new_price': price})
 
74
        if 'stock_account_input' in fields:
 
75
            res.update(
 
76
                {'stock_account_input': accounts['stock_account_input']})
 
77
        if 'stock_account_output' in fields:
 
78
            res.update(
 
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})
 
84
 
 
85
        return res
 
86
 
 
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
 
95
        @return:
 
96
        """
 
97
        if context is None:
 
98
            context = {}
 
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)
 
103
        datas = {
 
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
 
108
        }
 
109
        lot_pool.do_change_standard_price(cr, uid, [rec_id], datas, context)
 
110
        return {'type': 'ir.actions.act_window_close'}