[FIX]purchase_requisition: method to generate po from bid line and add a group as well as option in res_config for advance mode
bzr revid: csn@openerp.com-20130529154305-zhok6su2fmlet3x9
This commit is contained in:
parent
f3ccaf688a
commit
5593671ee4
|
@ -171,7 +171,7 @@
|
|||
<button name="picking_ok" states="except_picking" string="Manually Corrected"/>
|
||||
<button name="invoice_ok" states="except_invoice" string="Manually Corrected"/>
|
||||
<button name="purchase_approve" states="confirmed" string="Approve Order" class="oe_highlight" groups="purchase.group_purchase_manager"/>
|
||||
<button name="wkf_send_rfq" states="confirmed, approved" string="Send PO by Email" type="object" context="{'send_rfq':False}"/>
|
||||
<button name="wkf_send_rfq" states="approved" string="Send PO by Email" type="object" context="{'send_rfq':False}"/>
|
||||
<button name="view_picking" string="Receive Products" type="object" attrs="{'invisible': ['|', ('shipped','=',True), ('state','!=', 'approved')]}" class="oe_highlight"/>
|
||||
<button name="view_invoice" string="Receive Invoice" type="object" attrs="{'invisible': ['|', ('invoice_method','=','picking'), '|', ('state','!=', 'approved'), ('invoiced','=',True) ]}" class="oe_highlight"/>
|
||||
<button name="action_cancel_draft" states="cancel,sent,confirmed" string="Set to Draft" type="object" />
|
||||
|
|
|
@ -54,6 +54,10 @@ Example: Product: this product is deprecated, do not purchase more than 5.
|
|||
help="""Purchase Requisitions are used when you want to request quotations from several suppliers for a given set of products.
|
||||
You can configure per product if you directly do a Request for Quotation
|
||||
to one supplier or if you want a purchase requisition to negotiate with several suppliers."""),
|
||||
'group_advance_purchase_requisition': fields.boolean("Manage multiple bidding on purchase requisition",
|
||||
implied_group='purchase.group_advance_bidding',
|
||||
help="""In the process of a public bidding, You can analyse the bidding lines and choose for each product from
|
||||
where you want to buy it as well as the quantity"""),
|
||||
'module_purchase_analytic_plans': fields.boolean('Use multiple analytic accounts on purchase orders',
|
||||
help ="""Allows the user to maintain several analysis plans. These let you split lines on a purchase order between several accounts and analytic plans.
|
||||
This installs the module purchase_analytic_plans."""),
|
||||
|
|
|
@ -66,6 +66,10 @@
|
|||
<field name="module_purchase_requisition" class="oe_inline"/>
|
||||
<label for="module_purchase_requisition"/>
|
||||
</div>
|
||||
<div attrs="{'invisible': [('module_purchase_requisition', '=', False)]}">
|
||||
<field name="group_advance_purchase_requisition" class="oe_inline"/>
|
||||
<label for="group_advance_purchase_requisition"/>
|
||||
</div>
|
||||
<div>
|
||||
<field name="module_purchase_analytic_plans" on_change="onchange_purchase_analytic_plans(module_purchase_analytic_plans, context)" class="oe_inline"/>
|
||||
<label for="module_purchase_analytic_plans"/>
|
||||
|
|
|
@ -21,6 +21,11 @@
|
|||
<field name="implied_ids" eval="[(4, ref('analytic.group_analytic_accounting'))]"/>
|
||||
</record>
|
||||
|
||||
<record id="group_advance_bidding" model="res.groups">
|
||||
<field name="name">Advance bidding process</field>
|
||||
<field name="category_id" ref="base.module_category_hidden"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
<data noupdate="1">
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ class purchase_requisition(osv.osv):
|
|||
'po_line_ids': fields.function(_get_po_line, method=True, type='one2many', relation='purchase.order.line', string='Products by supplier'),
|
||||
'line_ids' : fields.one2many('purchase.requisition.line','requisition_id','Products to Purchase',states={'done': [('readonly', True)]}),
|
||||
'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse'),
|
||||
'state': fields.selection([('draft','New'),('in_progress','Sent to Suppliers'),('open','Choose Lines'),('cancel','Cancelled'),('done','Purchase Done')],
|
||||
'state': fields.selection([('draft','New'),('in_progress','Sent to Suppliers'),('open','Choose Lines'),('cancel','Cancelled'),('done','PO Created')],
|
||||
'Status', track_visibility='onchange', required=True)
|
||||
}
|
||||
_defaults = {
|
||||
|
@ -205,28 +205,38 @@ class purchase_requisition(osv.osv):
|
|||
"""
|
||||
po = self.pool.get('purchase.order')
|
||||
poline = self.pool.get('purchase.order.line')
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
id_per_supplier = {}
|
||||
tender = self.browse(cr, uid, id, context=context)[0]
|
||||
if tender.state == 'done':
|
||||
raise osv.except_osv(_('Warning!'), _('You have already generate the purchase order(s).'))
|
||||
for po_line in tender.po_line_ids:
|
||||
if po_line.state == 'confirmed':
|
||||
#only take into account confirmed line that does not belong to already confirmed purchase order
|
||||
if po_line.state == 'confirmed' and po_line.order_id.state in ['draft', 'sent', 'bid', 'cancel']:
|
||||
partner = po_line.partner_id.id
|
||||
if id_per_supplier.get(partner):
|
||||
id_per_supplier[partner].append(po_line.id)
|
||||
else:
|
||||
id_per_supplier[partner] = [po_line]
|
||||
|
||||
#TODO generate po based on supplier and check if a draft po is complete before creating a new one
|
||||
#generate po based on supplier and cancel all previous RFQ
|
||||
for supplier, product_line in id_per_supplier.items():
|
||||
#duplicate po_line and change product_qty if needed
|
||||
line_ids = []
|
||||
for line in product_line:
|
||||
line_ids.append(poline.copy(cr, uid, line.id, default = {'product_qty': line.quantity_bid}, context=context))
|
||||
#copy a quotation for this supplier and change order_line then validate it
|
||||
quotation_copy_id = po.search(cr, uid, [('requisition_id', '=', tender.id), ('partner_id', '=', supplier)], limit=1)
|
||||
new_po = po.copy(cr, uid, quotation_copy_id, default = {'order_line': line_ids}, context=context)
|
||||
quotation_id = po.search(cr, uid, [('requisition_id', '=', tender.id), ('partner_id', '=', supplier)], limit=1)[0]
|
||||
new_po = po.copy(cr, uid, quotation_id, default = {'order_line': []}, context=context)
|
||||
#duplicate po_line and change product_qty if needed and associate them to newly created PO
|
||||
for line in product_line:
|
||||
poline.copy(cr, uid, line.id, default = {'product_qty': line.quantity_bid, 'order_id': new_po}, context=context)
|
||||
#set previous confirmed line to draft
|
||||
poline.action_draft(cr, uid, line.id, context=context)
|
||||
#use workflow to set new PO state to confirm
|
||||
|
||||
#TODO set previous line to cancel
|
||||
wf_service.trg_validate(uid, 'purchase.order', new_po, 'purchase_confirm', cr)
|
||||
|
||||
#cancel other orders
|
||||
for quotation in tender.purchase_ids:
|
||||
if quotation.state in ['draft', 'sent', 'bid']:
|
||||
wf_service.trg_validate(uid, 'purchase.order', quotation.id, 'purchase_cancel', cr)
|
||||
|
||||
|
||||
class purchase_requisition_line(osv.osv):
|
||||
|
||||
|
@ -302,6 +312,9 @@ class purchase_order_line(osv.osv):
|
|||
self.write(cr, uid, ids, {'quantity_bid': element.product_qty}, context=context)
|
||||
return True
|
||||
|
||||
def generate_po(self, cr, uid, id, context=None):
|
||||
print '-----------------------------------------'
|
||||
|
||||
class product_product(osv.osv):
|
||||
_inherit = 'product.product'
|
||||
|
||||
|
|
|
@ -228,7 +228,7 @@
|
|||
<field name="lead_time" />
|
||||
<field name="state" invisible="1"/>
|
||||
<field name="invoiced" invisible="1"/>
|
||||
<button name="action_draft" states="confirmed" type="object" string="Cancel Bid" icon="gtk-cancel"/>
|
||||
<button name="action_draft" states="confirmed" type="object" string="Cancel Choice" icon="gtk-cancel"/>
|
||||
<button name="%(action_bid_line_qty)d" type="action" states="draft" string="Change Quantity" icon="gtk-ok"/>
|
||||
<button name="action_confirm" states="draft" type="object" string="Confirm Order" icon="gtk-apply"/>
|
||||
</tree>
|
||||
|
|
|
@ -22,9 +22,7 @@ openerp.purchase_requisition = function(instance) {
|
|||
},
|
||||
generate_purchase_order: function () {
|
||||
var self = this;
|
||||
//self.dataset.model = current model (purchase or else)
|
||||
new instance.web.Model(self.dataset.model).call("generate_po",[""]);
|
||||
//self.dataset.parent_view.recursive_reload();
|
||||
},
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue