[ADD]purchase_requisition: add a button in tree view to generate PO after bidding, need a one line patch in server in order to work

bzr revid: csn@openerp.com-20130529122833-ocz3lyhqv8y8cr1o
This commit is contained in:
Cedric Snauwaert 2013-05-29 14:28:33 +02:00
parent 74220665a4
commit f3ccaf688a
4 changed files with 50 additions and 3 deletions

View File

@ -33,6 +33,9 @@ related requisition. This new object will regroup and will allow you to easily
keep track and order all your purchase orders.
""",
'depends' : ['purchase'],
'js': [
'static/src/js/web_addons.js',
],
'demo': ['purchase_requisition_demo.xml'],
'data': ['security/purchase_tender.xml',
'wizard/purchase_requisition_partner_view.xml',

View File

@ -203,16 +203,30 @@ class purchase_requisition(osv.osv):
"""
Generate all purchase order based on selected lines, should only be called on one tender at a time
"""
po = self.pool.get('purchase.order')
poline = self.pool.get('purchase.order.line')
id_per_supplier = {}
for po_line in self.browse(cr, uid, id, context=context)[0].po_line_ids:
tender = self.browse(cr, uid, id, context=context)[0]
for po_line in tender.po_line_ids:
if po_line.state == 'confirmed':
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.id]
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
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)
#use workflow to set new PO state to confirm
#TODO set previous line to cancel
class purchase_requisition_line(osv.osv):

View File

@ -216,7 +216,7 @@
<field name="name">purchase.order.line.tree.tender</field>
<field name="model">purchase.order.line</field>
<field name="arch" type="xml">
<tree string="Purchase Order Lines" create="false" colors="blue:state == 'confirmed';gray:state == 'cancel'">
<tree string="Purchase Order Lines" create="false" colors="blue:state == 'confirmed';gray:state == 'cancel'" options="{'generate_po': True}">
<field name="name"/>
<field name="partner_id" string="Supplier" />
<field name="product_id"/>

View File

@ -0,0 +1,30 @@
openerp.purchase_requisition = function(instance) {
var QWeb = instance.web.qweb,
_t = instance.web._t;
instance.web.ListView.include({
init: function() {
var self = this;
this._super.apply(this, arguments);
this.on('list_view_loaded', this, function() {
if (!!self.fields_view.arch.attrs.options) {
_.extend(self.options, py.eval(self.fields_view.arch.attrs.options));
}
if (!!self.options.generate_po) {
if(self.__parentedParent.$el.find('.oe_generate_po').length == 0){
var button = $("<button type='button' class='oe_button oe_highlight oe_generate_po'>Generate PO</button>")
.click(this.proxy('generate_purchase_order'));
self.__parentedParent.$el.find('.oe_list_buttons').append(button);
}
}
});
},
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();
},
});
}