2013-06-30 22:26:46 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
|
|
|
#
|
|
|
|
# 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
|
2013-07-10 15:59:11 +00:00
|
|
|
from openerp.tools.translate import _
|
2013-06-30 22:26:46 +00:00
|
|
|
|
|
|
|
class procurement_group(osv.osv):
|
|
|
|
_inherit = 'procurement.group'
|
|
|
|
_columns = {
|
|
|
|
'partner_id': fields.many2one('res.partner', 'Partner')
|
|
|
|
}
|
|
|
|
|
|
|
|
class procurement_rule(osv.osv):
|
|
|
|
_inherit = 'procurement.rule'
|
2013-07-10 15:59:11 +00:00
|
|
|
|
2013-07-01 19:13:08 +00:00
|
|
|
def _get_action(self, cr, uid, context=None):
|
2013-06-30 22:26:46 +00:00
|
|
|
result = super(procurement_rule, self)._get_action(cr, uid, context=context)
|
2013-07-10 15:59:11 +00:00
|
|
|
return result + [('move', 'Move From Another Location')]
|
|
|
|
|
2013-06-30 23:00:28 +00:00
|
|
|
_columns = {
|
2013-07-10 15:59:11 +00:00
|
|
|
'location_id': fields.many2one('stock.location', 'Destination Location'),
|
2013-06-30 23:00:28 +00:00
|
|
|
'location_src_id': fields.many2one('stock.location', 'Source Location',
|
|
|
|
help="Source location is action=move")
|
|
|
|
}
|
2013-06-30 22:26:46 +00:00
|
|
|
|
|
|
|
class procurement_order(osv.osv):
|
|
|
|
_inherit = "procurement.order"
|
|
|
|
_columns = {
|
2013-07-10 15:59:11 +00:00
|
|
|
'location_id': fields.many2one('stock.location', 'Destination Location'),
|
|
|
|
'move_id': fields.many2one('stock.move', 'Move', help="Move created by the procurement"),
|
2013-07-09 13:25:06 +00:00
|
|
|
'move_dest_id': fields.many2one('stock.move', 'Destination Move', help="Move which caused (created) the procurement")
|
2013-06-30 22:26:46 +00:00
|
|
|
}
|
2013-07-09 13:25:06 +00:00
|
|
|
|
2013-07-10 15:59:11 +00:00
|
|
|
def _find_suitable_rule(self, cr, uid, procurement, context=None):
|
|
|
|
res = super(procurement_order, self)._find_suitable_rule(cr, uid, procurement, context=context)
|
2013-07-01 06:30:34 +00:00
|
|
|
if not res:
|
2013-07-10 15:59:11 +00:00
|
|
|
rule_obj = self.pool.get('procurement.rule')
|
|
|
|
res = rule_obj.search(cr, uid, [('location_id', '=', procurement.location_id.id)], context=context)
|
|
|
|
res = res and res[0] or False
|
|
|
|
return res
|
2013-07-01 06:30:34 +00:00
|
|
|
|
2013-07-10 15:59:11 +00:00
|
|
|
def _run_move_create(self, cr, uid, procurement, context=None):
|
2013-07-01 06:30:34 +00:00
|
|
|
return {
|
|
|
|
'name': procurement.name,
|
2013-07-10 15:59:11 +00:00
|
|
|
'company_id': procurement.company_id.id,
|
2013-07-01 06:30:34 +00:00
|
|
|
'product_id': procurement.product_id.id,
|
|
|
|
'date': procurement.date_planned,
|
|
|
|
'product_qty': procurement.product_qty,
|
|
|
|
'product_uom': procurement.product_uom.id,
|
2013-07-10 15:59:11 +00:00
|
|
|
'product_uom_qty': procurement.product_qty,
|
2013-07-01 06:30:34 +00:00
|
|
|
'product_uos_qty': (procurement.product_uos and procurement.product_uos_qty)\
|
|
|
|
or procurement.product_qty,
|
|
|
|
'product_uos': (procurement.product_uos and procurement.product_uos.id)\
|
|
|
|
or procurement.product_uom.id,
|
|
|
|
'partner_id': procurement.group_id and procurement.group_id.partner_id and \
|
|
|
|
procurement.group_id.partner_id.id or False,
|
|
|
|
'location_id': procurement.rule_id.location_src_id.id,
|
|
|
|
'location_dest_id': procurement.rule_id.location_id.id,
|
|
|
|
'move_dest_id': procurement.move_dest_id and procurement.move_dest_id.id or False,
|
2013-07-09 12:06:59 +00:00
|
|
|
#'cancel_cascade': procurement.rule_id and procurement.rule_id.cancel_cascade or False,
|
2013-07-10 15:59:11 +00:00
|
|
|
'group_id': procurement.group_id and procurement.group_id.id or False,
|
2013-07-01 06:30:34 +00:00
|
|
|
}
|
2013-06-30 22:26:46 +00:00
|
|
|
|
|
|
|
def _run(self, cr, uid, procurement, context=None):
|
|
|
|
if procurement.rule_id and procurement.rule_id.action == 'move':
|
2013-06-30 23:00:28 +00:00
|
|
|
if not procurement.rule_id.location_src_id:
|
2013-06-30 22:26:46 +00:00
|
|
|
self.message_post(cr, uid, [procurement.id], body=_('No source location defined!'), context=context)
|
|
|
|
return False
|
|
|
|
move_obj = self.pool.get('stock.move')
|
2013-07-01 06:30:34 +00:00
|
|
|
move_dict = self._run_move_create(cr, uid, procurement, context=context)
|
2013-07-10 15:59:11 +00:00
|
|
|
|
2013-07-01 06:30:34 +00:00
|
|
|
move_id = move_obj.create(cr, uid, move_dict, context=context)
|
2013-07-10 15:59:11 +00:00
|
|
|
move_obj.action_confirm(cr, uid, [move_id], context=context)
|
2013-06-30 22:26:46 +00:00
|
|
|
self.write(cr, uid, [procurement.id], {'move_id': move_id}, context=context)
|
2013-07-01 06:30:34 +00:00
|
|
|
return move_id
|
2013-06-30 22:26:46 +00:00
|
|
|
return super(procurement_order, self)._run(cr, uid, procurement, context)
|
|
|
|
|
|
|
|
def _check(self, cr, uid, procurement, context=None):
|
|
|
|
if procurement.rule_id and procurement.rule_id.action == 'move':
|
2013-07-10 15:59:11 +00:00
|
|
|
return procurement.move_id.state == 'done'
|
2013-06-30 22:26:46 +00:00
|
|
|
return super(procurement_order, self)._check(cr, uid, procurement, context)
|
|
|
|
|
2013-07-10 15:59:11 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|