[IMP] purchase_tender:Add the wizard purchase_requisition_partner ,search view ,on_changed

bzr revid: sbh@tinyerp.com-20100409135728-ndwu1vvtgv6j5asl
This commit is contained in:
sbh (Open ERP) 2010-04-09 19:27:28 +05:30
parent 0d19598a2b
commit fcbe3cb239
7 changed files with 282 additions and 8 deletions

View File

@ -18,5 +18,6 @@
#
##############################################################################
import purchase_tender
import wizard
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -31,7 +31,10 @@
"depends" : ["purchase","mrp"],
"init_xml" : [],
"demo_xml" : [],
"update_xml" : ["purchase_tender_view.xml","security/ir.model.access.csv","purchase_tender_sequence.xml"],
"update_xml" : ["wizard/purchase_requisition_partner.xml",
"purchase_tender_view.xml","security/ir.model.access.csv","purchase_tender_sequence.xml",
],
"active": False,
"installable": True
}

View File

@ -37,13 +37,32 @@ class purchase_tender(osv.osv):
'description': fields.text('Description'),
'purchase_ids' : fields.one2many('purchase.order','tender_id','Purchase Orders'),
'line_ids' : fields.one2many('purchase.tender.line','tender_id','Products to Purchase'),
'state': fields.selection([('draft','Draft'),('open','Open'),('close','Close')], 'State', required=True)
'state': fields.selection([('draft','Draft'),('open','Open'),('cancel','Cancel'),('close','Close'),('in_progress','In progress'),('done','Done')], 'State', required=True)
}
_defaults = {
'date_start': lambda *args: time.strftime('%Y-%m-%d %H:%M:%S'),
'state': lambda *args: 'open',
'name': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'purchase.order.tender'),
}
def tender_close(self, cr, uid, ids, context={}):
self.write(cr, uid, ids, {'state': 'done', 'date_end': time.strftime('%Y-%m-%d %H:%M:%S')})
return True
def tender_open(self, cr, uid, ids, context={}):
self.write(cr, uid, ids, {'state':'open'}, context=context)
return True
def tender_cancel(self, cr, uid, ids, context={}):
self.write(cr, uid, ids, {'state': 'cancel'})
return True
def tender_confirm(self, cr, uid, ids, context={}):
self.write(cr, uid, ids, {'state':'done'}, context=context)
return True
def tender_reset(self, cr, uid, ids, context={}):
self.write(cr, uid, ids, {'state': 'draft'})
return True
def tender_done(self, cr, uid, ids, context={}):
self.write(cr, uid, ids, {'state':'done'}, context=context)
return True
purchase_tender()
class purchase_tender_line(osv.osv):
@ -56,6 +75,22 @@ class purchase_tender_line(osv.osv):
'product_qty': fields.float('Date End', digits=(16,2)),
'tender_id' : fields.many2one('purchase.tender','Purchase Tender', ondelete='cascade')
}
def onchange_product_id(self, cr, uid, ids, product_id, context={}):
""" Changes UoM and name if product_id changes.
@param name: Name of the field
@param product_id: Changed product_id
@return: Dictionary of changed values
"""
value = {}
if product_id:
prod = self.pool.get('product.product').browse(cr, uid, [product_id])[0]
value = {'product_uom_id': prod.uom_id.id}
return {'value': value}
purchase_tender_line()
class purchase_order(osv.osv):
@ -91,12 +126,13 @@ product_product()
class mrp_procurement(osv.osv):
_inherit = 'mrp.procurement'
def make_po(self, cr, uid, ids, context={}):
sequence_obj=self.pool.get('ir.sequence')
res = super(mrp_procurement, self).make_po(cr, uid, ids, context)
for proc_id,po_id in res.items():
procurement = self.browse(cr, uid, proc_id)
if procurement.product_id.purchase_tender:
self.pool.get('purchase.tender').create(cr, uid, {
'name': procurement.name,
'name': sequence_obj.get(cr, uid, 'purchase.order.tender'),
'lines_ids': [(0,0,{
'product_id': procurement.product_id.id,
'product_uom_id': procurement.product_uom.id,

View File

@ -40,7 +40,7 @@
<page string="Products">
<field name="line_ids" colspan="4" nolabel="1">
<tree string="Products" editable="bottom">
<field name="product_id"/>
<field name="product_id" on_change="onchange_product_id(product_id)"/>
<field name="product_uom_id"/>
<field name="product_qty"/>
</tree>
@ -55,17 +55,30 @@
<field name="description" colspan="4" nolabel="1"/>
</page>
<page string="Quotations">
<field name="purchase_ids" nolabel="1" colspan="4"/>
</page>
<group col="8" colspan="4">
<button name="%(action_purchase_requisition_partner)d" string="New RfQr" type="action" />
<label colspan="6" string=""/>
</group>
<field name="purchase_ids" nolabel="1" colspan="4"/>
</page>
</notebook>
<field name="state" select="1"/>
<separator colspan="4"/>
<group col="8" colspan="4">
<field name="state" select="1" readonly ="1"/>
<button name="tender_close" states="open,draft,in_progress" string="Close" type="object" icon="gtk-close" />
<button name="tender_open" states="draft,in_progress" string="Open" type="object" icon="gtk-go-forward" />
<button name="tender_cancel" states="draft,open,in_progress" string="Cancel" type="object" icon="gtk-cancel" />
<button name="tender_confirm" states="open,in_progress" string="Confirm" type="object" icon="gtk-go-up" />
<button name="tender_reset" states="done,cancel" string="Reset to Draft" type="object" icon="gtk-convert" />
</group>
</form>
</field>
</record>
<record model="ir.ui.view" id="view_purchase_tender_tree">
<field name="name">purchase.tender.tree</field>
<field name="type">tree</field>
<field name="model">purchase.tender</field>
<field name="arch" type="xml">
<tree string="Purchase Tender">
<field name="name"/>
@ -76,11 +89,39 @@
</tree>
</field>
</record>
<record id="view_purchase_tender_filter" model="ir.ui.view">
<field name="name">purchase.tender.list.select</field>
<field name="model">purchase.tender</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Search Purchase Tender">
<group col='10' colspan='4'>
<filter icon="terp-purchase" string="Quotations" domain="[('state','=','draft')]" separator="1"/>
<filter icon="terp-purchase" string="Approved" domain="[('state','=','confirmed')]" separator="1"/>
<separator orientation="vertical"/>
<field name="name" select="1" string="Tender Reference"/>
<field name="purchase_ids" select="1"/>
<field name="user_id" select="1" widget="selection">
<filter icon="terp-partner" domain="[('create_uid','=',uid)]" help="My Tender "/>
</field>
</group>
<newline/>
<group expand="1" string="Group By..." colspan="4" col="10">
<filter string="State" icon="terp-sale" domain="[]" context="{'group_by':'state'}"/>
<filter string="Date " icon="terp-purchase" domain="[]" context="{'group_by':'date_start'}"/>
<filter string="Date End" icon="terp-purchase" domain="[]" context="{'group_by':'date_end'}"/>
</group>
</search>
</field>
</record>
<record model="ir.actions.act_window" id="action_purchase_tender">
<field name="name">Purchase Tenders</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">purchase.tender</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="search_view_id" ref="view_purchase_tender_filter"/>
</record>
<menuitem id="menu_purchase_Tender_pro_mgt" parent="purchase.menu_procurement_management" action="action_purchase_tender"/>

View File

@ -0,0 +1,25 @@
# -*- 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/>.
#
##############################################################################
import purchase_requisition_partner
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,136 @@
# -*- 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 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):
_name = "purchase.requisition.partner"
_description = "Purchase Requisition"
_columns = {
'partner_id': fields.many2one('res.partner', 'Partner', required=True),
'pruchase_requisitions': fields.many2one('mrp.procurement', 'Requisitions',required=True, domain=[('state', '=', 'confirmed')]),
}
_defaults = {
'parnter_id': lambda *a: 1,
}
def create_order(self, cr, uid, ids, context):
"""
To merge similar type of 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
@return: purchase order view
"""
record_id = context and context.get('active_id', False)
if record_id:
data = self.read(cr, uid, ids)
company = self.pool.get('res.users').browse(cr, uid, uid, context).company_id
order_obj = self.pool.get('purchase.order')
partner_obj = self.pool.get('res.partner')
procurement_obj = self.pool.get('mrp.procurement')
purchase_id=[]
partner_obj = self.pool.get('res.partner')
uom_obj = self.pool.get('product.uom')
pricelist_obj = self.pool.get('product.pricelist')
prod_obj = self.pool.get('product.product')
acc_pos_obj = self.pool.get('account.fiscal.position')
record_id = context and context.get('active_id', False)
procurement_id=data[0]['pruchase_requisitions']
for procurement in procurement_obj.browse(cr, uid,[procurement_id]):
#Todo need to check
# partner = procurement.product_id.seller_ids[0].name
partner_id = data[0]['partner_id']
address_id = partner_obj.address_get(cr, uid, [partner_id], ['delivery'])['delivery']
res_id = procurement.move_id.id
partner = procurement.product_id.seller_ids[0].name
pricelist_id = partner.property_product_pricelist_purchase.id
uom_id = procurement.product_id.uom_po_id.id
newdate = DateTime.strptime(procurement.date_planned, '%Y-%m-%d %H:%M:%S')
newdate = newdate - DateTime.RelativeDateTime(days=company.po_lead)
newdate = newdate - procurement.product_id.seller_ids[0].delay
qty = uom_obj._compute_qty(cr, uid, procurement.product_uom.id, procurement.product_qty, uom_id)
if procurement.product_id.seller_ids[0].qty:
qty = max(qty,procurement.product_id.seller_ids[0].qty)
price = pricelist_obj.price_get(cr, uid, [pricelist_id], procurement.product_id.id, qty, False, {'uom': uom_id})[pricelist_id]
product = prod_obj.browse(cr, uid, procurement.product_id.id, context=context)
line = {
'name': product.partner_ref,
'product_qty': qty,
'product_id': procurement.product_id.id,
'product_uom': uom_id,
'price_unit': price,
'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'),
'move_dest_id': res_id,
'notes': product.description_purchase,
}
taxes_ids = procurement.product_id.product_tmpl_id.supplier_taxes_id
taxes = acc_pos_obj.map_tax(cr, uid, partner.property_account_position, taxes_ids)
line.update({
'taxes_id': [(6,0,taxes)]
})
purchase_id = order_obj.create(cr, uid, {
'origin': procurement.name,
'partner_id': partner_id,
'partner_address_id': address_id,
'location_id': procurement.location_id.id,
'pricelist_id': pricelist_id,
'order_line': [(0,0,line)],
'company_id': procurement.company_id.id,
'fiscal_position': partner.property_account_position and partner.property_account_position.id or False,
'tender_id':record_id,
})
procurement_obj.write(cr, uid, [procurement.id], {'state': 'running', 'purchase_id': purchase_id})
return {
'domain': "[('id','in', [" + ','.join(map(str, [purchase_id])) + "])]",
'name': 'Purchase Orders',
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'purchase.order',
'view_id': False,
'type': 'ir.actions.act_window',
}
purchase_requisition_partner()

View File

@ -0,0 +1,32 @@
<openerp>
<data>
<record id="view_purchase_requisition_partner" model="ir.ui.view">
<field name="name">Purchase Requisition</field>
<field name="model">purchase.requisition.partner</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Purchase Requisition">
<field name="partner_id"/>
<field name="pruchase_requisitions"/>
<group colspan="4" col="6">
<button icon="gtk-cancel" special="cancel" string="_Cancel"/>
<button icon="gtk-ok" name="create_order" string="Create Orders" type="object"/>
</group>
</form>
</field>
</record>
<record id="action_purchase_requisition_partner" model="ir.actions.act_window">
<field name="name">Purchase Requisition</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">purchase.requisition.partner</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="context">{'record_id' : active_id}</field>
<field name="target">new</field>
</record>
</data>
</openerp>