1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (c) 2011 NaN Projectes de Programari Lliure S.L. (http://nan-tic.com)
6
# Copyright (c) 2008 ACYSOS S.L. (http://acysos.com) All Rights Reserved.
7
# Pedro Tarrafeta <pedro@acysos.com>
8
# Copyright (c) 2008 Pablo Rocandio. All Rights Reserved.
11
# This program is free software: you can redistribute it and/or modify
12
# it under the terms of the GNU General Public License as published by
13
# the Free Software Foundation, either version 3 of the License, or
14
# (at your option) any later version.
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU General Public License for more details.
21
# You should have received a copy of the GNU General Public License
22
# along with this program. If not, see <http://www.gnu.org/licenses/>.
24
##############################################################################
26
from osv import fields, osv
27
import decimal_precision as dp
29
#----------------------------------------------------------
31
#----------------------------------------------------------
32
class partner_new(osv.osv):
33
_inherit = 'res.partner'
35
'alb_val': fields.boolean('Albarán valorado'), # Enviar albarán valorado
36
#'parent_id': fields.many2one('res.partner','Partner', select=True), # ???
39
'alb_val' : lambda *a: 1,
44
#----------------------------------------------------------
46
#----------------------------------------------------------
47
class stock_picking(osv.osv):
49
##Esto es para que el picking salga valorado
51
def _amount_untaxed(self, cr, uid, ids, prop, unknow_none,unknow_dict):
53
id_set=",".join(map(str,map(int, ids)))
56
COALESCE(sum( sm.product_qty*sol.price_unit*(100-sol.discount))/100.0,0)::decimal(16,2) as amount
59
left join stock_move sm on sp.id=sm.picking_id
60
left join sale_order_line sol on sm.sale_line_id=sol.id
64
group by sp.id"""%id_set)
65
res=dict(cr.fetchall())
69
def _amount_tax(self, cr, uid, ids, field_name, arg, context):
70
id_set = ",".join(map(str, map(int,ids)))
74
COALESCE(sum( at.amount*sm.product_qty*sol.price_unit*(100-sol.discount))/100.0,0)::decimal(16,2) as amount
76
left join stock_move sm on sp.id=sm.picking_id
77
left join sale_order_line sol on sm.sale_line_id=sol.id
78
left join sale_order_tax sot on sol.id=sot.order_line_id
79
left join account_tax at on at.id=sot.tax_id
82
and sm.state != 'cancel'
83
group by sp.id"""%id_set )
84
res = dict(cr.fetchall())
87
def _amount_total(self, cr, uid, ids, field_name, arg, context):
89
untax = self._amount_untaxed(cr, uid, ids, field_name, arg, context)
90
tax = self._amount_tax(cr, uid, ids, field_name, arg, context)
92
res[id] = untax.get(id, 0.0) + tax.get(id, 0.0)
95
_name = "stock.picking"
96
_description = "Picking list"
97
_inherit = "stock.picking"
99
'amount_untaxed': fields.function(_amount_untaxed, method=True, digits_compute=dp.get_precision('Account'),string='Untaxed Amount'),
100
'amount_tax': fields.function(_amount_tax,digits_compute=dp.get_precision('Account'), method=True, string='Taxes'),
101
'amount_total': fields.function(_amount_total,digits_compute=dp.get_precision('Account'), method=True, string='Total'),
102
'tracking': fields.char('Tracking', size=64),
107
#----------------------------------------------------------
109
#----------------------------------------------------------
110
class stock_move(osv.osv):
112
def _price_subtotal(self, cr, uid, ids, prop, unknow_none,unknow_dict):
114
cur_obj = self.pool.get('res.currency')
115
for line in self.browse(cr, uid, ids):
116
if line.sale_line_id:
117
res[line.id] = line.sale_line_id.price_unit * line.product_qty * (1 - (line.sale_line_id.discount or 0.0) / 100.0)
118
cur = line.sale_line_id.order_id.pricelist_id.currency_id
119
res[line.id] = cur_obj.round(cr, uid, cur, res[line.id])
120
# res[line.id] = line.sale_line_id.price_subtotal
125
def _price_net(self, cr, uid, ids, field_name, arg, context):
128
cur_obj = self.pool.get('res.currency')
129
for line in self.browse(cr, uid, ids):
130
if line.sale_line_id:
131
res[line.id] = line.sale_line_id.price_unit
136
def _price_unit(self, cr, uid, ids, field_name, arg, context):
138
for line in self.browse(cr, uid, ids):
139
if line.sale_line_id:
140
res[line.id] = line.sale_line_id.price_unit
145
def _discount(self, cr, uid, ids, field_name, arg, context):
147
for line in self.browse(cr, uid, ids):
148
if line.sale_line_id:
149
res[line.id] = line.sale_line_id.discount
154
_inherit = "stock.move"
156
'sale_line_id': fields.many2one('sale.order.line', 'Sale Order Line'),
157
'price_subtotal': fields.function(_price_subtotal, method=True, digits=(16,2),string='Subtotal', select=True),
158
'price_net': fields.function(_price_net, method=True, digits=(16,2),string='Net', select=True), # Con descuento aplicado
159
'price_unit': fields.function(_price_unit, method=True, digits=(16,2),string='Price', select=True),
160
'discount': fields.function(_discount, method=True, digits=(16,2),string='Discount (%)', select=True),