diff --git a/addons/purchase_tender/__init__.py b/addons/purchase_tender/__init__.py
index 68f1f7ae5bc..9fc02d11b87 100644
--- a/addons/purchase_tender/__init__.py
+++ b/addons/purchase_tender/__init__.py
@@ -18,5 +18,6 @@
#
##############################################################################
import purchase_tender
+import wizard
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/purchase_tender/__terp__.py b/addons/purchase_tender/__terp__.py
index a6b3543cbbb..031d4cca078 100644
--- a/addons/purchase_tender/__terp__.py
+++ b/addons/purchase_tender/__terp__.py
@@ -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
}
diff --git a/addons/purchase_tender/purchase_tender.py b/addons/purchase_tender/purchase_tender.py
index db3bec835fd..069a7bb8964 100644
--- a/addons/purchase_tender/purchase_tender.py
+++ b/addons/purchase_tender/purchase_tender.py
@@ -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,
diff --git a/addons/purchase_tender/purchase_tender_view.xml b/addons/purchase_tender/purchase_tender_view.xml
index b64d9c54ae6..47e4e4fe338 100644
--- a/addons/purchase_tender/purchase_tender_view.xml
+++ b/addons/purchase_tender/purchase_tender_view.xml
@@ -40,7 +40,7 @@
-
+
@@ -55,17 +55,30 @@
-
-
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
purchase.tender.tree
tree
- purchase.tender
@@ -76,11 +89,39 @@
+
+ purchase.tender.list.select
+ purchase.tender
+ search
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Purchase Tenders
ir.actions.act_window
purchase.tender
form
+ tree,form
+
diff --git a/addons/purchase_tender/wizard/__init__.py b/addons/purchase_tender/wizard/__init__.py
new file mode 100644
index 00000000000..a9691cb6e25
--- /dev/null
+++ b/addons/purchase_tender/wizard/__init__.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# 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 .
+#
+##############################################################################
+
+import purchase_requisition_partner
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+
diff --git a/addons/purchase_tender/wizard/purchase_requisition_partner.py b/addons/purchase_tender/wizard/purchase_requisition_partner.py
new file mode 100644
index 00000000000..f93d05b500b
--- /dev/null
+++ b/addons/purchase_tender/wizard/purchase_requisition_partner.py
@@ -0,0 +1,136 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# 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 .
+#
+##############################################################################
+
+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()
+
diff --git a/addons/purchase_tender/wizard/purchase_requisition_partner.xml b/addons/purchase_tender/wizard/purchase_requisition_partner.xml
new file mode 100644
index 00000000000..740d8ffe524
--- /dev/null
+++ b/addons/purchase_tender/wizard/purchase_requisition_partner.xml
@@ -0,0 +1,32 @@
+
+
+
+
+ Purchase Requisition
+ purchase.requisition.partner
+ form
+
+
+
+
+
+
+ Purchase Requisition
+ ir.actions.act_window
+ purchase.requisition.partner
+ form
+ form
+ {'record_id' : active_id}
+ new
+
+
+
+
+
\ No newline at end of file