~vauxoo/addons-vauxoo/7.0-add_project_followers_rule-dev-ernesto

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/python
# -*- encoding: utf-8 -*-
###########################################################################
#    Module Writen to OpenERP, Open Source Management Solution
#    Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
#    All Rights Reserved
# Credits######################################################
#    Coded by: Vauxoo C.A.
#    Planified by: Nhomar Hernandez
#    Audited by: Vauxoo C.A.
#############################################################################
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published
#    by the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
##########################################################################
from openerp.osv import fields, osv
from openerp.tools.translate import _

import decimal_precision as dp
import pooler
import time
import math


class product_historical(osv.Model):
    """
    product_historical
    """
    def _get_historical_price(self, cr, uid, ids, field_name, field_value,
                              arg, context={}):
        res = {}
        product_hist = self.pool.get('product.historic.price')
        for id in ids:
            if self.browse(cr, uid, id).list_price != self.browse(cr, uid,
                                                                  id).\
                                                         list_price_historical:
                res[id] = self.browse(cr, uid, id).list_price
                product_hist.create(cr, uid, {
                    'product_id': id,
                    'name': time.strftime('%Y-%m-%d %H:%M:%S'),
                    'price': self.browse(cr, uid, id).list_price,
                }, context)
        return res

    def _get_historical_cost(self, cr, uid, ids, field_name, field_value,
                             arg, context={}):
        res = {}
        product_hist = self.pool.get('product.historic.cost')
        for id in ids:
            if self.browse(cr, uid, id).standard_price != self.browse(cr,
                                                  uid, id).cost_historical:
                res[id] = self.browse(cr, uid, id).standard_price
                product_hist.create(cr, uid, {
                    'product_id': id,
                    'name': time.strftime('%Y-%m-%d %H:%M:%S'),
                    'price': self.browse(cr, uid, id).standard_price,
                }, context)
        return res

    _inherit = 'product.product'
    _columns = {
        'list_price_historical':
           fields.function(_get_historical_price,
                                         method=True, string='Latest Price',
                                         type='float',
                                         digits_compute=dp.get_precision(
                                             'List_Price_Historical'),
                                         store={'product.product': ( lambda
                                             self, cr, uid, ids, c={}: ids, [
                                                 'list_price'], 50), },
                                             help="""Latest Recorded Historical
                                             Value"""),
        'cost_historical': fields.function(_get_historical_cost, method=True,
                                           string=' Latest Cost', type='float',
                                           digits_compute=dp.get_precision(
                                               'Cost_Historical'),
                                           store={'product.product': ( lambda
                                               self, cr, uid, ids, c={}: ids, [
                                                   'standard_price'], 50), },
                                               help="""Latest Recorded
                                               Historical Cost"""),
        'list_price_historical_ids': fields.one2many('product.historic.price',
                                                     'product_id',
                                                     'Historical Prices'),
        'cost_historical_ids': fields.one2many('product.historic.cost',
                                               'product_id',
                                               'Historical Prices'),

    }


class product_historic_price(osv.Model):
    _order = "name desc"
    _name = "product.historic.price"
    _description = "Historical Price List"

    _columns = {
        'product_id': fields.many2one('product.product',
                                      string='Product related to this Price',
                                      required=True),
        'name': fields.datetime(string='Date',  required=True),
        'price': fields.float(string='Price',
                              digits_compute=dp.get_precision('Price')),
        'product_uom': fields.many2one('product.uom', string="Supplier UoM",
                                       help="""Choose here the Unit of Measure
                                               in which the prices and
                                               quantities are expressed
                                               below.""")

    }
    _defaults = {'name': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
                 }


class product_historic_cost(osv.Model):
    _order = "name desc"
    _name = "product.historic.cost"
    _description = "Historical Price List"

    _columns = {
        'product_id': fields.many2one('product.product',
                                      string='Product related to this Cost',
                                      required=True),
        'name': fields.datetime(string='Date', required=True),
        'price': fields.float(string='Cost',
                              digits_compute=dp.get_precision('Price2')),
        'product_uom': fields.many2one('product.uom', string="Supplier UoM",
                                       help="""Choose here the Unit of Measure
                                               in which the prices and
                                               quantities are expressed
                                               below.""")

    }
    _defaults = {'name': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
                 }