It is currently Wed May 23, 2012 4:10 pm

All times are UTC + 2 hours




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Automatic merge of purchase orders + Put same products toget
PostPosted: Thu Jan 12, 2012 11:20 am 
Offline

Joined: Wed Sep 07, 2011 9:25 am
Posts: 11
Location: Belgium
Hi,

I'm commissioning the automatic purchase system when creating a new manufacturing order.

The problem is, i have BOMs with 100+ items, so now it creates 100+ purchase orders. I know i can merge them manually, but is there a way to make openerp do this automatically?

Secondly, when I merge 2 purchase orders and they contain the same product, it keeps them seperate instead of joining them. Is there a way to solve this?

Thanks!
jan


Top
 Profile  
 
 Post subject: Re: Automatic merge of purchase orders + Put same products t
PostPosted: Sun Jan 15, 2012 3:09 pm 
Offline

Joined: Thu Apr 07, 2011 3:39 pm
Posts: 12
Im looking for the same thing exactly!


Top
 Profile  
 
 Post subject: Re: Automatic merge of purchase orders + Put same products t
PostPosted: Sun Jan 15, 2012 9:31 pm 
Offline

Joined: Mon Jul 04, 2011 6:23 am
Posts: 372
Location: Auckland, New Zealand
I don't have a module but here is the code we use to do this:

# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2011- Solnet Solutions (<http://www.solnetsolutions.co.nz>).
# Copyright (C) 2010 OpenERP S.A. http://www.openerp.com
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from datetime import datetime
from dateutil.relativedelta import relativedelta
from osv import osv

class PurchaseQuoteMergeProcurement(osv.osv):
""" Used to over-ride the procurement order make purchase order to add to an existing PO if possible. """

_inherit = "procurement.order"

def make_po(self, cr, uid, ids, context=None):
""" Make purchase order from procurement
This is a copy-paste over-ride of the method from purchasing.
The key difference is this will look for an existing PO and if found,
add the line to it.

@return: New created Purchase Orders procurement wise
"""
res = {}
if context is None:
context = {}
company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_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')
po_obj = self.pool.get('purchase.order')
po_line_obj = self.pool.get('purchase.order.line')
for procurement in self.browse(cr, uid, ids, context=context):
res_id = procurement.move_id.id
partner = procurement.product_id.seller_id # Taken Main Supplier of Product of Procurement.
seller_qty = procurement.product_id.seller_qty
seller_delay = int(procurement.product_id.seller_delay)
partner_id = partner.id
address_id = partner_obj.address_get(cr, uid, [partner_id], ['delivery'])['delivery']
pricelist_id = partner.property_product_pricelist_purchase.id

uom_id = procurement.product_id.uom_po_id.id

qty = uom_obj._compute_qty(cr, uid, procurement.product_uom.id, procurement.product_qty, uom_id)
if seller_qty:
qty = max(qty,seller_qty)

price = pricelist_obj.price_get(cr, uid, [pricelist_id], procurement.product_id.id, qty, partner_id, {'uom': uom_id})[pricelist_id]

newdate = datetime.strptime(procurement.date_planned, '%Y-%m-%d %H:%M:%S')
newdate = (newdate - relativedelta(days=company.po_lead)) - relativedelta(days=seller_delay)

#Passing partner_id to context for purchase order line integrity of Line name
context.update({'lang': partner.lang, 'partner_id': partner_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)]
})

# Code from Graeme Gellatley
# Search for an existing matching PO and add the line to it if found, otherwise create a new PO.
# Changed matching PO search.
user_class = self.pool.get('res.users')
user_company_id = user_class.browse(cr, uid, uid, context = context).company_id.id
po_exists = po_obj.search(cr, uid, [('company_id','=', user_company_id),
('partner_id', '=', partner_id),
('state', '=', 'draft')])

if po_exists:
purchase_id = po_exists[0]
else:
purchase_id = po_obj.create(cr, uid, {
'origin': procurement.origin,
'partner_id': partner_id,
'partner_address_id': address_id,
'location_id': procurement.location_id.id,
'pricelist_id': pricelist_id,

'company_id': procurement.company_id.id,
'fiscal_position': partner.property_account_position and partner.property_account_position.id or False
})
line.update({'order_id': purchase_id})
purchase_line_id = po_line_obj.create(cr, uid, line)

res[procurement.id] = purchase_id
self.write(cr, uid, [procurement.id], {'state': 'running', 'purchase_id': purchase_id, 'purchase_line_id': purchase_line_id})
return res



PurchaseQuoteMergeProcurement()

_________________
Kevin
Solnet Solutions Limited
Auckland, New Zealand


Top
 Profile  
 
 Post subject: Re: Automatic merge of purchase orders + Put same products t
PostPosted: Sun Jan 15, 2012 9:35 pm 
Offline

Joined: Thu Apr 07, 2011 3:39 pm
Posts: 12
great thanks a lot.

But where do i place it? in the purchase module?

Or should i create a module?

Thanks again


Top
 Profile  
 
 Post subject: Re: Automatic merge of purchase orders + Put same products t
PostPosted: Tue Jan 17, 2012 12:26 am 
Offline

Joined: Mon Jul 04, 2011 6:23 am
Posts: 372
Location: Auckland, New Zealand
we created a new module

_________________
Kevin
Solnet Solutions Limited
Auckland, New Zealand


Top
 Profile  
 
 Post subject: Re: Automatic merge of purchase orders + Put same products t
PostPosted: Mon Jan 23, 2012 7:03 am 
Offline

Joined: Tue Nov 02, 2010 4:33 pm
Posts: 114
Location: United States
Hi,
I am very eager to have this feature working. I tried your code and it did not appear to have any effect. I had to indent the code properly first, then I put it in a module and it did not auto merge the purchase orders during the scheduler run.

Do you have any ideas? What im looking for,

*Purchase orders are generated based on min/max rules set. When the scheduler runs it generates the purchase orders, one per product. (current functionality.)

Proposed functionality,
Purchase orders are generated based on mix/max rules set. When the scheduler runs it first checks to see if any products in the procurement list already have draft state purchase orders that could be appended.
(product supplier = draft po supplier) If no purchase order in draft state has that supplier, it will create a new purchase order.

I understand this could potentially append manually created purchase orders, like for a normal purchase, but this can be dealt with later if it presents an issue.

_________________
Enterprise software Specialist
http://www.gcotech.com


Top
 Profile  
 
 Post subject: Re: Automatic merge of purchase orders + Put same products t
PostPosted: Mon Jan 23, 2012 10:05 am 
Offline

Joined: Wed Jan 27, 2010 6:21 pm
Posts: 797
Location: Auckland, NZ
Well I wrote the code about 18 months ago and it has worked fine since then. And I just refactored it for 6.1 and it still works just fine.

But to write yourself the concept is simple.

Find a match, and add it, instead of creating a new document/line whatever. Very, very simple, was one of the first modules I ever wrote and only took me half a day or so.

_________________
Graeme


Top
 Profile  
 
 Post subject: Re: Automatic merge of purchase orders + Put same products t
PostPosted: Mon Jan 23, 2012 4:16 pm 
Offline

Joined: Tue Nov 02, 2010 4:33 pm
Posts: 114
Location: United States
Hi,

Thanks for the response. Ill check again and see if I made some mistake.

_________________
Enterprise software Specialist
http://www.gcotech.com


Top
 Profile  
 
 Post subject: Re: Automatic merge of purchase orders + Put same products t
PostPosted: Mon Jan 23, 2012 4:17 pm 
Offline

Joined: Thu Apr 07, 2011 3:39 pm
Posts: 12
I have been trying it, but its not actually overriding the make_po function
Hope this helps


Top
 Profile  
 
 Post subject: Re: Automatic merge of purchase orders + Put same products t
PostPosted: Mon Jan 23, 2012 11:06 pm 
Offline

Joined: Tue Nov 02, 2010 4:33 pm
Posts: 114
Location: United States
gdaddy wrote:
Well I wrote the code about 18 months ago and it has worked fine since then. And I just refactored it for 6.1 and it still works just fine.

But to write yourself the concept is simple.

Find a match, and add it, instead of creating a new document/line whatever. Very, very simple, was one of the first modules I ever wrote and only took me half a day or so.


You say it is working,
In your code for the update
if po_exists:
purchase_id = po_exists[0]

It does not write the updated lines. So it creates a unique order if no match is found, but when found it does not write the change.

_________________
Enterprise software Specialist
http://www.gcotech.com


Top
 Profile  
 
 Post subject: Re: Automatic merge of purchase orders + Put same products t
PostPosted: Tue Jan 24, 2012 12:54 pm 
Offline

Joined: Wed Jan 27, 2010 6:21 pm
Posts: 797
Location: Auckland, NZ
read the code again and remember that a purchase_order is NOT a purchase_order_line

_________________
Graeme


Top
 Profile  
 
 Post subject: Re: Automatic merge of purchase orders + Put same products t
PostPosted: Thu Jan 26, 2012 4:33 pm 
Offline

Joined: Mon Jan 09, 2012 12:48 pm
Posts: 19
Location: Awans
Thanks, it seems to works

do not forget :
import unicodedata
from dateutil.relativedelta import relativedelta


Top
 Profile  
 
 Post subject: Re: Automatic merge of purchase orders + Put same products t
PostPosted: Thu Jan 26, 2012 9:32 pm 
Offline

Joined: Wed Jan 27, 2010 6:21 pm
Posts: 797
Location: Auckland, NZ
not sure why you need unicodedata import, I've never used it ever.

_________________
Graeme


Top
 Profile  
 
 Post subject: Re: Automatic merge of purchase orders + Put same products t
PostPosted: Fri Jan 27, 2012 1:56 am 
Offline

Joined: Thu Apr 07, 2011 3:39 pm
Posts: 12
I still can't get it to work..


Top
 Profile  
 
 Post subject: Re: Automatic merge of purchase orders + Put same products t
PostPosted: Tue Jan 31, 2012 4:23 pm 
Offline

Joined: Mon Jan 09, 2012 12:48 pm
Posts: 19
Location: Awans
what is the error ? syntax error ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC + 2 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:

Protected by Anti-Spam ACP