~openerp-spain-team/openerp-spain/6.0-git

« back to all changes in this revision

Viewing changes to extra_addons/stock_valued/stock_valued.py

  • Committer: Borja L.S.
  • Date: 2010-10-18 10:04:25 UTC
  • Revision ID: git-v1:271c47a993616dbba60585d48b8b98d603199d93
[REF] *: Refactorización para portar a 6.0 - Paso 1.

- Se han renombrado los módulos para usar la nomenclatura propuesta
  por OpenERP: l10n_es para el módulo base de localización (plan de 
  cuentas), l10n_es_* para el resto de módulos.

- Se eliminan los módulos extra_addons/* que deberían moverse a 
  los extra-addons genéricos (no son específicos de España).

- Se renombran los __terp__.py por __openerp__.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- encoding: utf-8 -*-
2
 
##############################################################################
3
 
#
4
 
#    OpenERP, Open Source Management Solution
5
 
#    Copyright (c) 2008 ACYSOS S.L. (http://acysos.com) All Rights Reserved.
6
 
#                       Pedro Tarrafeta <pedro@acysos.com>
7
 
#    Copyright (c) 2008 Pablo Rocandio. All Rights Reserved.
8
 
#    $Id$
9
 
#
10
 
#    This program is free software: you can redistribute it and/or modify
11
 
#    it under the terms of the GNU General Public License as published by
12
 
#    the Free Software Foundation, either version 3 of the License, or
13
 
#    (at your option) any later version.
14
 
#
15
 
#    This program is distributed in the hope that it will be useful,
16
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
#    GNU General Public License for more details.
19
 
#
20
 
#    You should have received a copy of the GNU General Public License
21
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 
#
23
 
##############################################################################
24
 
 
25
 
from osv import fields, osv
26
 
 
27
 
#----------------------------------------------------------
28
 
# Partner
29
 
#----------------------------------------------------------
30
 
class partner_new(osv.osv):
31
 
    _inherit = 'res.partner'
32
 
    _columns = {
33
 
        'alb_val': fields.boolean('Albarán valorado'), # Enviar albarán valorado
34
 
        #'parent_id': fields.many2one('res.partner','Partner', select=True), # ???
35
 
               }
36
 
    _defaults = {
37
 
        'alb_val' : lambda *a: 1,
38
 
    }
39
 
partner_new()
40
 
 
41
 
 
42
 
#----------------------------------------------------------
43
 
# Stock Picking
44
 
#----------------------------------------------------------
45
 
class stock_picking(osv.osv):
46
 
 
47
 
##Esto es para que el picking salga valorado
48
 
 
49
 
    def _amount_untaxed(self, cr, uid, ids, prop, unknow_none,unknow_dict):
50
 
 
51
 
        id_set=",".join(map(str,map(int, ids)))
52
 
        cr.execute("select sp.id, COALESCE(sum( sm.product_qty*sol.price_unit*(100-sol.discount))/100.0,0)::decimal(16,2) as amount from stock_picking sp left join stock_move sm on sp.id=sm.picking_id left join sale_order_line sol on sm.sale_line_id=sol.id where sp.id in ("+id_set+") group by sp.id")
53
 
        res=dict(cr.fetchall())
54
 
 
55
 
        return res
56
 
 
57
 
    def _amount_tax(self, cr, uid, ids, field_name, arg, context):
58
 
        id_set = ",".join(map(str, map(int,ids)))
59
 
        cr.execute("select sp.id, COALESCE(sum( at.amount*sm.product_qty*sol.price_unit*(100-sol.discount))/100.0,0)::decimal(16,2) as amount from stock_picking sp left join stock_move sm on sp.id=sm.picking_id left join sale_order_line sol on sm.sale_line_id=sol.id left join sale_order_tax sot on sol.id=sot.order_line_id left join account_tax at on at.id=sot.tax_id where sp.id in ("+id_set+") group by sp.id")
60
 
        res = dict(cr.fetchall())
61
 
        return res
62
 
 
63
 
    def _amount_total(self, cr, uid, ids, field_name, arg, context):
64
 
        res = {}
65
 
        untax = self._amount_untaxed(cr, uid, ids, field_name, arg, context)
66
 
        tax = self._amount_tax(cr, uid, ids, field_name, arg, context)
67
 
        for id in ids:
68
 
            res[id] = untax.get(id, 0.0) + tax.get(id, 0.0)
69
 
        return res
70
 
 
71
 
    _name = "stock.picking"
72
 
    _description = "Picking list"
73
 
    _inherit = "stock.picking"
74
 
    _columns = {
75
 
        'partner_id':fields.many2one('res.partner', 'Partner', change_default=True, select=True),
76
 
        'amount_untaxed': fields.function(_amount_untaxed, method=True, digits=(16,2),string='Untaxed Amount'),
77
 
        'amount_tax': fields.function(_amount_tax, method=True, string='Taxes'),
78
 
        'amount_total': fields.function(_amount_total, method=True, string='Total'),
79
 
        'tracking': fields.char('Tracking', size=64),
80
 
            }
81
 
 
82
 
stock_picking()
83
 
 
84
 
#----------------------------------------------------------
85
 
# Stock Move
86
 
#----------------------------------------------------------
87
 
class stock_move(osv.osv):
88
 
 
89
 
    def _price_subtotal(self, cr, uid, ids, prop, unknow_none,unknow_dict):
90
 
        res = {}
91
 
        for line in self.browse(cr, uid, ids):
92
 
            if line.sale_line_id:
93
 
                res[line.id] = line.sale_line_id.price_subtotal
94
 
            else:
95
 
                res[line.id] = 0
96
 
        return res
97
 
 
98
 
    def _price_net(self, cr, uid, ids, field_name, arg, context):
99
 
        res = {}
100
 
        for line in self.browse(cr, uid, ids):
101
 
            if line.sale_line_id:
102
 
                res[line.id] = line.sale_line_id.price_net
103
 
            else:
104
 
                res[line.id] = 0
105
 
        return res
106
 
 
107
 
    def _price_unit(self, cr, uid, ids, field_name, arg, context):
108
 
        res = {}
109
 
        for line in self.browse(cr, uid, ids):
110
 
            if line.sale_line_id:
111
 
                res[line.id] = line.sale_line_id.price_unit
112
 
            else:
113
 
                res[line.id] = 0
114
 
        return res
115
 
 
116
 
    def _discount(self, cr, uid, ids, field_name, arg, context):
117
 
        res = {}
118
 
        for line in self.browse(cr, uid, ids):
119
 
            if line.sale_line_id:
120
 
                res[line.id] = line.sale_line_id.discount
121
 
            else:
122
 
                res[line.id] = 0
123
 
        return res
124
 
 
125
 
    _inherit = "stock.move"
126
 
    _columns = {
127
 
        'sale_line_id': fields.many2one('sale.order.line', 'Sale Order Line'), 
128
 
        'price_subtotal': fields.function(_price_subtotal, method=True, digits=(16,2),string='Subtotal', select=True),
129
 
        'price_net': fields.function(_price_net, method=True, digits=(16,2),string='Net', select=True), # Con descuento aplicado
130
 
        'price_unit': fields.function(_price_unit, method=True, digits=(16,2),string='Price', select=True),
131
 
        'discount': fields.function(_discount, method=True, digits=(16,2),string='Discount (%)', select=True),
132
 
               }
133
 
stock_move()
134