[REF] purchase requeistion
bzr revid: mra@mra-laptop-20100623115320-i0k2kio6el47id6z
This commit is contained in:
parent
69525bf302
commit
64d7e5faa6
|
@ -20,10 +20,11 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
|
||||
from osv import fields,osv
|
||||
from osv import orm
|
||||
import netsvc
|
||||
import time
|
||||
from tools.translate import _
|
||||
|
||||
class purchase_requisition(osv.osv):
|
||||
|
@ -43,16 +44,16 @@ class purchase_requisition(osv.osv):
|
|||
'state': fields.selection([('draft','Draft'),('in_progress','In Progress'),('cancel','Cancelled'),('done','Done')], 'State', required=True)
|
||||
}
|
||||
_defaults = {
|
||||
'date_start': lambda *args: time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'state': lambda *args: 'draft',
|
||||
'exclusive': lambda *args: 'multiple',
|
||||
'date_start': time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'state': 'draft',
|
||||
'exclusive': 'multiple',
|
||||
'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
|
||||
'user_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).id ,
|
||||
'name': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'purchase.order.requisition'),
|
||||
}
|
||||
|
||||
|
||||
def tender_cancel(self, cr, uid, ids, context={}):
|
||||
def tender_cancel(self, cr, uid, ids, context=None):
|
||||
purchase_order_obj = self.pool.get('purchase.order')
|
||||
for purchase in self.browse(cr, uid, ids):
|
||||
for purchase_id in purchase.purchase_ids:
|
||||
|
@ -61,32 +62,30 @@ class purchase_requisition(osv.osv):
|
|||
self.write(cr, uid, ids, {'state': 'cancel'})
|
||||
for (id,name) in self.name_get(cr, uid, ids):
|
||||
message = _('Tender') + " '" + name + "' "+ _("is cancelled")
|
||||
self.log(cr, uid, id, message)
|
||||
self.log(cr, uid, id, message)
|
||||
return True
|
||||
def tender_in_progress(self, cr, uid, ids, context={}):
|
||||
def tender_in_progress(self, cr, uid, ids, context=None):
|
||||
for quotations in self.browse(cr, uid, ids):
|
||||
if not quotations.purchase_ids:
|
||||
raise osv.except_osv(_('Purchase order required'),('You should have atleast one purchase order line defined for this tender'))
|
||||
self.write(cr, uid, ids, {'state':'in_progress'} ,context=context)
|
||||
for (id,name) in self.name_get(cr, uid, ids):
|
||||
message = _('Tender') + " '" + name + "' "+ _(" is In Progress")
|
||||
self.log(cr, uid, id, message)
|
||||
self.log(cr, uid, id, message)
|
||||
return True
|
||||
def tender_reset(self, cr, uid, ids, context={}):
|
||||
def tender_reset(self, cr, uid, ids, context=None):
|
||||
self.write(cr, uid, ids, {'state': 'draft'})
|
||||
for (id,name) in self.name_get(cr, uid, ids):
|
||||
message = _('Tender') + " '" + name + "' "+ _("is in draft state")
|
||||
self.log(cr, uid, id, message)
|
||||
self.log(cr, uid, id, message)
|
||||
return True
|
||||
def tender_done(self, cr, uid, ids, context={}):
|
||||
def tender_done(self, cr, uid, ids, context=None):
|
||||
self.write(cr, uid, ids, {'state':'done', 'date_end':time.strftime('%Y-%m-%d %H:%M:%S')}, context=context)
|
||||
for (id,name) in self.name_get(cr, uid, ids):
|
||||
message = _('Tender') + " '" + name + "' "+ _("is done")
|
||||
self.log(cr, uid, id, message)
|
||||
self.log(cr, uid, id, message)
|
||||
return True
|
||||
|
||||
|
||||
|
||||
purchase_requisition()
|
||||
|
||||
class purchase_requisition_line(osv.osv):
|
||||
|
@ -102,7 +101,7 @@ class purchase_requisition_line(osv.osv):
|
|||
'requisition_id' : fields.many2one('purchase.requisition','Purchase Requisition', ondelete='cascade')
|
||||
}
|
||||
|
||||
def onchange_product_id(self, cr, uid, ids, product_id,product_uom_id, context={}):
|
||||
def onchange_product_id(self, cr, uid, ids, product_id,product_uom_id, context=None):
|
||||
|
||||
""" Changes UoM and name if product_id changes.
|
||||
@param name: Name of the field
|
||||
|
@ -147,7 +146,7 @@ class product_product(osv.osv):
|
|||
'purchase_requisition': fields.boolean('Purchase Requisition', help="Check this box so that requisitions generates purchase requisitions instead of directly requests for quotations.")
|
||||
}
|
||||
_defaults = {
|
||||
'purchase_requisition': lambda *args: False
|
||||
'purchase_requisition': False
|
||||
}
|
||||
product_product()
|
||||
|
||||
|
@ -174,3 +173,5 @@ class procurement_order(osv.osv):
|
|||
})
|
||||
return res
|
||||
procurement_order()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
|
@ -15,16 +15,17 @@
|
|||
# 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/>.
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
from mx import DateTime
|
||||
|
||||
from osv import fields, osv
|
||||
from service import web_services
|
||||
import netsvc
|
||||
import pooler
|
||||
import time
|
||||
from mx import DateTime
|
||||
from osv.orm import browse_record, browse_null
|
||||
|
||||
class purchase_requisition_partner(osv.osv_memory):
|
||||
|
@ -33,38 +34,37 @@ class purchase_requisition_partner(osv.osv_memory):
|
|||
_columns = {
|
||||
'partner_id': fields.many2one('res.partner', 'Partner', required=True,domain=[('supplier', '=', True)]),
|
||||
'partner_address_id':fields.many2one('res.partner.address', 'Address', required=True),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def view_init(self, cr, uid, fields_list, context=None):
|
||||
res = super(purchase_requisition_partner, self).view_init(cr, uid, fields_list, context=context)
|
||||
record_id = context and context.get('active_id', False) or False
|
||||
record_id = context and context.get('active_id', False) or False
|
||||
tender = self.pool.get('purchase.requisition').browse(cr, uid, record_id)
|
||||
if not tender.line_ids:
|
||||
raise osv.except_osv('Error!','No Product in Tender')
|
||||
raise osv.except_osv('Error!','No Product in Tender')
|
||||
True
|
||||
|
||||
def onchange_partner_id(self, cr, uid, ids, partner_id):
|
||||
addr = self.pool.get('res.partner').address_get(cr, uid, [partner_id], ['default'])
|
||||
part = self.pool.get('res.partner').browse(cr, uid, partner_id)
|
||||
return {'value':{'partner_address_id': addr['default']}}
|
||||
|
||||
|
||||
def create_order(self, cr, uid, ids, context):
|
||||
"""
|
||||
"""
|
||||
To Create a purchase orders .
|
||||
|
||||
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@param uid: ID of the user currently logged in
|
||||
@param ids: the ID or list of IDs
|
||||
@param context: A standard dictionary
|
||||
@param ids: the ID or list of IDs
|
||||
@param context: A standard dictionary
|
||||
@return: {}
|
||||
|
||||
"""
|
||||
|
||||
"""
|
||||
record_ids = context and context.get('active_ids', False)
|
||||
if record_ids:
|
||||
data = self.read(cr, uid, ids)
|
||||
company = self.pool.get('res.users').browse(cr, uid, uid, context).company_id
|
||||
company = self.pool.get('res.users').browse(cr, uid, uid, context).company_id
|
||||
order_obj = self.pool.get('purchase.order')
|
||||
order_line_obj = self.pool.get('purchase.order.line')
|
||||
partner_obj = self.pool.get('res.partner')
|
||||
|
@ -72,29 +72,29 @@ class purchase_requisition_partner(osv.osv_memory):
|
|||
pricelist_obj = self.pool.get('product.pricelist')
|
||||
prod_obj = self.pool.get('product.product')
|
||||
tender_obj = self.pool.get('purchase.requisition')
|
||||
acc_pos_obj = self.pool.get('account.fiscal.position')
|
||||
acc_pos_obj = self.pool.get('account.fiscal.position')
|
||||
partner_id = data[0]['partner_id']
|
||||
|
||||
|
||||
supplier_data = partner_obj.browse(cr, uid,[ partner_id])[0]
|
||||
|
||||
address_id = partner_obj.address_get(cr, uid, [partner_id], ['delivery'])['delivery']
|
||||
list_line=[]
|
||||
purchase_order_line={}
|
||||
for tender in tender_obj.browse(cr, uid, record_ids):
|
||||
for line in tender.line_ids:
|
||||
for line in tender.line_ids:
|
||||
partner_list = sorted([(partner.sequence, partner) for partner in line.product_id.seller_ids if partner])
|
||||
partner_rec = partner_list and partner_list[0] and partner_list[0][1] or False
|
||||
uom_id = line.product_id.uom_po_id and line.product_id.uom_po_id.id or False
|
||||
uom_id = line.product_id.uom_po_id and line.product_id.uom_po_id.id or False
|
||||
newdate = DateTime.strptime(tender.date_start, '%Y-%m-%d %H:%M:%S')
|
||||
newdate = newdate - DateTime.RelativeDateTime(days=company.po_lead)
|
||||
delay = partner_rec and partner_rec.delay or False
|
||||
newdate = newdate -(delay or DateTime.strptime(tender.date_start, '%Y-%m-%d %H:%M:%S') )
|
||||
partner = partner_rec and partner_rec.name or supplier_data
|
||||
pricelist_id = partner.property_product_pricelist_purchase and partner.property_product_pricelist_purchase.id or False
|
||||
pricelist_id = partner.property_product_pricelist_purchase and partner.property_product_pricelist_purchase.id or False
|
||||
price = pricelist_obj.price_get(cr, uid, [pricelist_id], line.product_id.id, line.product_qty, False, {'uom': uom_id})[pricelist_id]
|
||||
product = prod_obj.browse(cr, uid, line.product_id.id, context=context)
|
||||
|
||||
|
||||
|
||||
|
||||
purchase_order_line= {
|
||||
'name': product.partner_ref,
|
||||
'product_qty': line.product_qty,
|
||||
|
@ -108,14 +108,14 @@ class purchase_requisition_partner(osv.osv_memory):
|
|||
taxes = acc_pos_obj.map_tax(cr, uid, partner.property_account_position, taxes_ids)
|
||||
purchase_order_line.update({
|
||||
'taxes_id': [(6,0,taxes)]
|
||||
})
|
||||
})
|
||||
list_line.append(purchase_order_line)
|
||||
purchase_id = order_obj.create(cr, uid, {
|
||||
'origin': tender.purchase_ids and tender.purchase_ids[0].origin or tender.name,
|
||||
'partner_id': partner_id,
|
||||
'partner_address_id': address_id,
|
||||
'pricelist_id': pricelist_id,
|
||||
'location_id': tender.purchase_ids and tender.purchase_ids[0].location_id.id or line.product_id.product_tmpl_id.property_stock_production.id,
|
||||
'location_id': tender.purchase_ids and tender.purchase_ids[0].location_id.id or line.product_id.product_tmpl_id.property_stock_production.id,
|
||||
'company_id': tender.company_id.id,
|
||||
'fiscal_position': partner.property_account_position and partner.property_account_position.id or False,
|
||||
'requisition_id':tender.id,
|
||||
|
@ -124,9 +124,11 @@ class purchase_requisition_partner(osv.osv_memory):
|
|||
for order_line in list_line:
|
||||
order_line.update({
|
||||
'order_id': purchase_id
|
||||
})
|
||||
})
|
||||
order_line_obj.create(cr,uid,order_line)
|
||||
return {}
|
||||
return {}
|
||||
|
||||
purchase_requisition_partner()
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
Loading…
Reference in New Issue