1
# -*- encoding: utf-8 -*-
2
##############################################################################
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.
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.
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.
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/>.
23
##############################################################################
25
from osv import fields, osv
27
#----------------------------------------------------------
29
#----------------------------------------------------------
30
class partner_new(osv.osv):
31
_inherit = 'res.partner'
33
'alb_val': fields.boolean('Albarán valorado'), # Enviar albarán valorado
34
#'parent_id': fields.many2one('res.partner','Partner', select=True), # ???
37
'alb_val' : lambda *a: 1,
42
#----------------------------------------------------------
44
#----------------------------------------------------------
45
class stock_picking(osv.osv):
47
##Esto es para que el picking salga valorado
49
def _amount_untaxed(self, cr, uid, ids, prop, unknow_none,unknow_dict):
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())
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())
63
def _amount_total(self, cr, uid, ids, field_name, arg, context):
65
untax = self._amount_untaxed(cr, uid, ids, field_name, arg, context)
66
tax = self._amount_tax(cr, uid, ids, field_name, arg, context)
68
res[id] = untax.get(id, 0.0) + tax.get(id, 0.0)
71
_name = "stock.picking"
72
_description = "Picking list"
73
_inherit = "stock.picking"
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),
84
#----------------------------------------------------------
86
#----------------------------------------------------------
87
class stock_move(osv.osv):
89
def _price_subtotal(self, cr, uid, ids, prop, unknow_none,unknow_dict):
91
for line in self.browse(cr, uid, ids):
93
res[line.id] = line.sale_line_id.price_subtotal
98
def _price_net(self, cr, uid, ids, field_name, arg, context):
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
107
def _price_unit(self, cr, uid, ids, field_name, arg, context):
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
116
def _discount(self, cr, uid, ids, field_name, arg, context):
118
for line in self.browse(cr, uid, ids):
119
if line.sale_line_id:
120
res[line.id] = line.sale_line_id.discount
125
_inherit = "stock.move"
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),