1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Affero General Public License as
8
# published by the Free Software Foundation, either version 3 of the
9
# License, or (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Affero General Public License for more details.
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
##############################################################################
21
from datetime import datetime
22
from dateutil.relativedelta import relativedelta
23
from datetime import datetime, timedelta
24
from osv import osv, fields
27
from tools.translate import _
28
import decimal_precision as dp
29
from osv.orm import browse_record, browse_null
31
class stock_move(osv.osv):
32
_inherit = 'stock.move'
34
def _compute_pieces(self, cr, uid, ids, name, arg, context=None):
35
move = self.browse(cr, uid, ids)
38
if m.product_id.stock_driver in ('tile','slab','block'):
39
uom = self.pool.get('product.uom')
40
pieces = uom._compute_pieces(cr, uid, m.product_id.stock_driver, m.product_qty, m.prodlot_id.lot_factor, context)
47
'pieces_qty': fields.integer('Pieces'),
48
'length': fields.float('Length (m)',digits_compute=dp.get_precision('Product UoM')),
49
'width': fields.float('Width (m)',digits_compute=dp.get_precision('Product UoM')),
50
'heigth': fields.float('Heigth (m)',digits_compute=dp.get_precision('Product UoM')),
51
'company_id': fields.many2one('res.company','Company'),
59
class stock_inventory_line(osv.osv):
64
def _compute_pieces(self, cr, uid, ids, name, arg, context=None):
65
line = self.browse(cr, uid, ids)
68
if l.product_id.stock_driver in ('tile','slab','block'):
69
uom = self.pool.get('product.uom')
70
pieces = uom._compute_pieces(cr, uid, l.product_id.stock_driver, l.product_qty, l.prod_lot_id.lot_factor, context)
76
_inherit = 'stock.inventory.line'
79
'pieces_qty': fields.function(_compute_pieces, method=True, type="integer", string='Pieces'),
82
stock_inventory_line()
84
class stock_picking(osv.osv):
87
def _invoice_line_hook(self, cr, uid, move_line, invoice_line_id):
88
ail_obj = self.pool.get('account.invoice.line')
89
ail_obj.write(cr,uid,invoice_line_id,{'prod_lot_id':move_line.prodlot_id and move_line.prodlot_id.id,'pieces':move_line.pieces_qty},context=None)
90
return super(stock_picking,self)._invoice_line_hook(cr, uid, move_line, invoice_line_id)
93
_inherit = 'stock.picking'
95
'pieces_qty':fields.integer('Pieces'),
96
'state_rw':fields.integer('State'),
97
'company_id': fields.many2one('res.company','Company'),
98
'picking_origin_ids':fields.many2many('stock.picking','picking_intercompany_rel','picking_origin_id','picking_sale_id','Picking'),
99
'picking_sale_ids':fields.many2many('stock.picking','picking_intercompany_rel','picking_sale_id','picking_origin_id','Picking'),
107
def draft_validate(self, cr, uid, ids, context=None):
109
Added the state chage to can do changes in the picking(INVOICE)
113
self.write(cr,uid,ids,{'state_rw':0},context=context)
114
res = super(stock_picking, self).draft_validate(cr, uid, ids, context)
119
def action_invoice_create(self, cr, uid, ids, journal_id=False,group=False, type='out_invoice', context=None):
121
Method that generate invoices in the companies related with this transaction
123
#~ TODO: Revisar los impuestos en las facturas generadas
126
stock_partial_picking_obj = self.pool.get('stock.partial.picking')
127
stock_invoice_onshiping_obj = self.pool.get('stock.invoice.onshipping')
128
self.write(cr,uid,ids,{'state_rw':0},context=context)
129
pickng_brw = self.browse(cr,uid,ids,context=context)
130
res = super(stock_picking, self).action_invoice_create(cr, uid, ids,journal_id=journal_id,
131
group=group, type=type, context=context)
134
if context.get('inter',False):
137
for i in pickng_brw[0].picking_sale_ids:
141
self.draft_validate(cr,i.company_id.user_in_id.id,[i.id],context)
142
context.update({'inter':True})
143
journal_ids = self.pool.get('account.journal').search(cr,uid,[('company_id','=',i.company_id.id),('type','=','purchase')],context=context)
144
pickng_brw = self.browse(cr,uid,i.id,context=context)
145
if pickng_brw.type == 'in':
149
self.action_invoice_create(cr, i.company_id.user_in_id.id, [i.id],journal_id=journal_ids[0],group=False, type=type, context=context)
153
def write(self, cr, uid, ids, vals, context=None):
155
Chages for not write in a picking intercompany
159
picking_brw = self.browse(cr,uid,ids,context=context)
160
for val in vals.keys():
161
if val == 'state_rw':
164
for i in picking_brw:
165
if i.state_rw !=0 and i.state == 'done':
166
raise osv.except_osv(_('Invalid action !'),_('Cannot write this picking because they are a transactions intercompany !'))
168
return super(stock_picking, self).write(cr, uid, ids, vals, context=context)
170
def unlink(self, cr, uid, ids, context=None):
172
Modified to avoid delete a line of a picking intercompany
175
picking_brw = self.browse(cr, uid, ids,context=context)
177
for s in picking_brw:
178
if s.state_rw !=0 or s.state == 'done' :
179
raise osv.except_osv(_('Invalid action !'),_('Cannot delete this picking because they are a transactions intercompany !'))
181
unlink_ids.append((s.id))
183
return osv.osv.unlink(self, cr, uid, unlink_ids, context=context)
185
def copy(self, cr, uid, id, default=None, context=None):
187
Modified to avoid doubling a picking intercompany
193
picking_brw = self.browse(cr,uid,id,context=context)
194
if picking_brw.state_rw != 0:
202
return super(stock_picking, self).copy(cr, uid, id, default, context=context)