[MERGE] trunk-improve-purchase-requisition-view-atp (purchase requisition form view, and chatter)
bzr revid: rco@openerp.com-20120627145858-mt086phe9kl65q1q
This commit is contained in:
@@ -31,6 +31,7 @@ import decimal_precision as dp
|
||||
class purchase_requisition(osv.osv):
|
||||
_name = "purchase.requisition"
|
||||
_description="Purchase Requisition"
|
||||
_inherit = ['ir.needaction_mixin', 'mail.thread']
|
||||
_columns = {
|
||||
'name': fields.char('Requisition Reference', size=32,required=True),
|
||||
'origin': fields.char('Source', size=32),
|
||||
@@ -43,10 +44,10 @@ class purchase_requisition(osv.osv):
|
||||
'purchase_ids' : fields.one2many('purchase.order','requisition_id','Purchase Orders',states={'done': [('readonly', True)]}),
|
||||
'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','In Progress'),('cancel','Cancelled'),('done','Done')], 'Status', required=True)
|
||||
'state': fields.selection([('draft','New'),('in_progress','Sent to Suppliers'),('cancel','Cancelled'),('done','Purchase Done')], 'Status', required=True)
|
||||
}
|
||||
_defaults = {
|
||||
'date_start': time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'date_start': lambda *args: time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'state': 'draft',
|
||||
'exclusive': 'multiple',
|
||||
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'purchase.requisition', context=c),
|
||||
@@ -63,6 +64,7 @@ class purchase_requisition(osv.osv):
|
||||
'name': self.pool.get('ir.sequence').get(cr, uid, 'purchase.order.requisition'),
|
||||
})
|
||||
return super(purchase_requisition, self).copy(cr, uid, id, default, context)
|
||||
|
||||
def tender_cancel(self, cr, uid, ids, context=None):
|
||||
purchase_order_obj = self.pool.get('purchase.order')
|
||||
for purchase in self.browse(cr, uid, ids, context=context):
|
||||
@@ -70,20 +72,36 @@ class purchase_requisition(osv.osv):
|
||||
if str(purchase_id.state) in('draft','wait'):
|
||||
purchase_order_obj.action_cancel(cr,uid,[purchase_id.id])
|
||||
self.write(cr, uid, ids, {'state': 'cancel'})
|
||||
self.cancel_send_note(cr, uid, ids, context=context)
|
||||
return True
|
||||
|
||||
def tender_in_progress(self, cr, uid, ids, context=None):
|
||||
self.write(cr, uid, ids, {'state':'in_progress'} ,context=context)
|
||||
self.in_progress_send_note(cr, uid, ids, context=context)
|
||||
return True
|
||||
|
||||
def tender_reset(self, cr, uid, ids, context=None):
|
||||
self.write(cr, uid, ids, {'state': 'draft'})
|
||||
self.reset_send_note(cr, uid, ids, context=context)
|
||||
return True
|
||||
|
||||
def tender_done(self, cr, uid, ids, context=None):
|
||||
self.write(cr, uid, ids, {'state':'done', 'date_end':time.strftime('%Y-%m-%d %H:%M:%S')}, context=context)
|
||||
self.done_to_send_note(cr, uid, ids, context=context)
|
||||
return True
|
||||
|
||||
def in_progress_send_note(self, cr, uid, ids, context=None):
|
||||
self.message_append_note(cr, uid, ids, body=_("Draft Requisition has been <b>sent to suppliers</b>."), context=context)
|
||||
|
||||
def reset_send_note(self, cr, uid, ids, context=None):
|
||||
self.message_append_note(cr, uid, ids, body=_("Purchase Requisition has been set to <b>draft</b>."), context=context)
|
||||
|
||||
def done_to_send_note(self, cr, uid, ids, context=None):
|
||||
self.message_append_note(cr, uid, ids, body=_("Purchase Requisition has been <b>done</b>."), context=context)
|
||||
|
||||
def cancel_send_note(self, cr, uid, ids, context=None):
|
||||
self.message_append_note(cr, uid, ids, body=_("Purchase Requisition has been <b>cancelled</b>."), context=context)
|
||||
|
||||
def _planned_date(self, requisition, delay=0.0):
|
||||
company = requisition.company_id
|
||||
date_planned = False
|
||||
@@ -164,9 +182,45 @@ class purchase_requisition(osv.osv):
|
||||
}, context=context)
|
||||
|
||||
return res
|
||||
|
||||
def get_needaction_user_ids(self, cr, uid, ids, context=None):
|
||||
result = dict.fromkeys(ids, [])
|
||||
for obj in self.browse(cr, uid, ids, context=context):
|
||||
if (obj.state == 'draft') and obj.user_id:
|
||||
result[obj.id] = [obj.user_id.id]
|
||||
return result
|
||||
|
||||
def create_send_note(self, cr, uid, ids, context=None):
|
||||
return self.message_append_note(cr, uid, ids, body=_("Purchase Requisition has been <b>created</b>."), context=context)
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
requisition = super(purchase_requisition, self).create(cr, uid, vals, context=context)
|
||||
if requisition:
|
||||
self.create_send_note(cr, uid, [requisition], context=context)
|
||||
return requisition
|
||||
|
||||
purchase_requisition()
|
||||
|
||||
class mail_message(osv.osv):
|
||||
_inherit = 'mail.message'
|
||||
|
||||
def schedule_with_attach(self, cr, uid, email_from, email_to, subject, body, model=False, email_cc=None,
|
||||
email_bcc=None, reply_to=False, attachments=None, message_id=False, references=False,
|
||||
res_id=False, subtype='plain', headers=None, mail_server_id=False, auto_delete=False,
|
||||
context=None):
|
||||
purchase_order_obj = self.pool.get('purchase.order')
|
||||
requisition_id = purchase_order_obj.browse(cr, uid, res_id, context=context).requisition_id.id
|
||||
result = super(mail_message, self).schedule_with_attach(cr, uid, email_from, email_to, subject, body, model=model, email_cc=email_cc,
|
||||
email_bcc=email_bcc, reply_to=reply_to, attachments=attachments, message_id=message_id, references=references,
|
||||
res_id=res_id, subtype='plain', headers=headers, mail_server_id=mail_server_id, auto_delete=auto_delete,
|
||||
context=context)
|
||||
if requisition_id:
|
||||
result = self.schedule_with_attach(cr, uid, email_from, email_to, subject, body, 'purchase.requisition', email_cc=email_cc,
|
||||
email_bcc=email_bcc, reply_to=reply_to, attachments=attachments, message_id=message_id, references=references,
|
||||
res_id=requisition_id, subtype='plain', headers=headers, mail_server_id=mail_server_id, auto_delete=auto_delete,
|
||||
context=context)
|
||||
return result
|
||||
|
||||
class purchase_requisition_line(osv.osv):
|
||||
|
||||
_name = "purchase.requisition.line"
|
||||
@@ -203,13 +257,14 @@ class purchase_order(osv.osv):
|
||||
_columns = {
|
||||
'requisition_id' : fields.many2one('purchase.requisition','Purchase Requisition')
|
||||
}
|
||||
|
||||
def wkf_confirm_order(self, cr, uid, ids, context=None):
|
||||
res = super(purchase_order, self).wkf_confirm_order(cr, uid, ids, context=context)
|
||||
proc_obj = self.pool.get('procurement.order')
|
||||
for po in self.browse(cr, uid, ids, context=context):
|
||||
if po.requisition_id and (po.requisition_id.exclusive=='exclusive'):
|
||||
for order in po.requisition_id.purchase_ids:
|
||||
if order.id<>po.id:
|
||||
if order.id != po.id:
|
||||
proc_ids = proc_obj.search(cr, uid, [('purchase_id', '=', order.id)])
|
||||
if proc_ids and po.state=='confirmed':
|
||||
proc_obj.write(cr, uid, proc_ids, {'purchase_id': po.id})
|
||||
@@ -224,7 +279,7 @@ class product_product(osv.osv):
|
||||
_inherit = 'product.product'
|
||||
|
||||
_columns = {
|
||||
'purchase_requisition': fields.boolean('Purchase Requisition', help="Check this box so that requisitions generates purchase requisitions instead of directly requests for quotations.")
|
||||
'purchase_requisition': fields.boolean('Purchase Requisition', help="Check this box to generates purchase requisition instead of generating requests for quotation from procurement.")
|
||||
}
|
||||
_defaults = {
|
||||
'purchase_requisition': False
|
||||
@@ -239,27 +294,31 @@ class procurement_order(osv.osv):
|
||||
'requisition_id' : fields.many2one('purchase.requisition','Latest Requisition')
|
||||
}
|
||||
def make_po(self, cr, uid, ids, context=None):
|
||||
res = {}
|
||||
sequence_obj = self.pool.get('ir.sequence')
|
||||
res = super(procurement_order, self).make_po(cr, uid, ids, context=context)
|
||||
for proc_id, po_id in res.items():
|
||||
procurement = self.browse(cr, uid, proc_id, context=context)
|
||||
requisition_id=False
|
||||
if procurement.product_id.purchase_requisition:
|
||||
requisition_id=self.pool.get('purchase.requisition').create(cr, uid, {
|
||||
'name': sequence_obj.get(cr, uid, 'purchase.order.requisition'),
|
||||
requisition_obj = self.pool.get('purchase.requisition')
|
||||
warehouse_obj = self.pool.get('stock.warehouse')
|
||||
procurement = self.browse(cr, uid, ids, context=context)[0]
|
||||
if procurement.product_id.purchase_requisition:
|
||||
seq_name = sequence_obj.get(cr, uid, 'purchase.order.requisition')
|
||||
warehouse_id = warehouse_obj.search(cr, uid, [('company_id', '=', procurement.company_id.id or company.id)], context=context)
|
||||
res[procurement.id] = requisition_obj.create(cr, uid,
|
||||
{
|
||||
'name': seq_name,
|
||||
'origin': procurement.origin,
|
||||
'date_end': procurement.date_planned,
|
||||
'warehouse_id':procurement.purchase_id and procurement.purchase_id.warehouse_id.id,
|
||||
'warehouse_id':warehouse_id and warehouse_id[0] or False,
|
||||
'company_id':procurement.company_id.id,
|
||||
'line_ids': [(0,0,{
|
||||
'product_id': procurement.product_id.id,
|
||||
'product_uom_id': procurement.product_uom.id,
|
||||
'product_qty': procurement.product_qty
|
||||
|
||||
})],
|
||||
'purchase_ids': [(6,0,[po_id])]
|
||||
})],
|
||||
})
|
||||
self.write(cr,uid,[proc_id],{'requisition_id':requisition_id},context=context)
|
||||
self.write(cr,uid,[procurement.id],{'state': 'running','requisition_id': res[procurement.id]},context=context)
|
||||
else:
|
||||
res = super(procurement_order, self).make_po(cr, uid, ids, context=context)
|
||||
return res
|
||||
|
||||
procurement_order()
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<!--Resource: purchase.requisition-->
|
||||
|
||||
<record id="requisition1" model="purchase.requisition">
|
||||
<field name="user_id" model="res.users"/>
|
||||
<field name="user_id" ref="base.user_root"/>
|
||||
<field name="exclusive">exclusive</field>
|
||||
<field name="date_start" eval="time.strftime('%Y/%m/%d %H:%M:%S')"/>
|
||||
<field name="warehouse_id" ref="stock.stock_warehouse_shop0"/>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
|
||||
<record model="ir.ui.view" id="purchase_order_form_inherit">
|
||||
<field name="name">purchase.order.form.inherit</field>
|
||||
<field name="type">form</field>
|
||||
@@ -34,14 +33,17 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Purchase Requisition" version="7.0">
|
||||
<header>
|
||||
<button name="tender_in_progress" states="draft" string="Start" type="object" />
|
||||
<button name="tender_in_progress" states="draft" string="Send to Suppliers" type="object" />
|
||||
<button name="tender_reset" states="done,cancel" string="Reset to Draft" type="object" />
|
||||
<button name="tender_done" states="in_progress" string="Done" type="object" />
|
||||
<button name="tender_done" states="in_progress" string=" Purchase Done" type="object" />
|
||||
<button name="tender_cancel" states="draft,in_progress" string="Cancel" type="object" />
|
||||
<field name="state" widget="statusbar" statusbar_visible="draft,in_progress,done" statusbar_colors='{"in_progress":"blue"}'/>
|
||||
</header>
|
||||
<sheet>
|
||||
<label for="name" class="oe_edit_only"/>
|
||||
<div class="oe_edit_only">
|
||||
<label for="name" class="oe_inline"/>,
|
||||
<label for="origin" class="oe_inline"/>
|
||||
</div>
|
||||
<h1>
|
||||
<field name="name" class="oe_inline"/>,
|
||||
<field name="origin" class="oe_inline"/>
|
||||
@@ -50,23 +52,24 @@
|
||||
<group>
|
||||
<field name="user_id"/>
|
||||
<field name="exclusive"/>
|
||||
</group><group>
|
||||
</group>
|
||||
<group>
|
||||
<field name="date_start"/>
|
||||
<field name="date_end"/>
|
||||
<field name="warehouse_id" widget="selection"/>
|
||||
<field name="warehouse_id" widget="selection" groups="stock.group_locations"/>
|
||||
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
|
||||
</group>
|
||||
</group>
|
||||
<notebook colspan="4">
|
||||
<notebook>
|
||||
<page string="Products">
|
||||
<field name="line_ids">
|
||||
<tree string="Products" editable="bottom">
|
||||
<field name="product_id" on_change="onchange_product_id(product_id,product_uom_id)"/>
|
||||
<field name="product_qty"/>
|
||||
<field name="product_uom_id"/>
|
||||
<field name="product_uom_id" groups="product.group_uom"/>
|
||||
</tree>
|
||||
<form string="Products" version="7.0">
|
||||
<group col="4">
|
||||
<group>
|
||||
<field name="product_id" />
|
||||
<field name="product_qty"/>
|
||||
<field name="product_uom_id" />
|
||||
@@ -74,17 +77,19 @@
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
<separator string="Terms and Conditions"/>
|
||||
<field name="description"/>
|
||||
</page>
|
||||
<page string="Quotations">
|
||||
<field name="purchase_ids">
|
||||
<div class="oe_right oe_button_box" style="margin-top: 10px">
|
||||
<button name="%(action_purchase_requisition_partner)d" type="action"
|
||||
string="Request a Quotation" icon="gtk-execute"
|
||||
attrs="{'invisible': [('line_ids','=',False),('state', 'not in', ('in_progress'))]}"/>
|
||||
</div>
|
||||
<separator string="Quotations"/>
|
||||
<field name="purchase_ids" readonly="1">
|
||||
<tree string="Purchase Order">
|
||||
<field name="name" string="Reference"/>
|
||||
<field name="date_order" string="Order Date"/>
|
||||
<field name="partner_id"/>
|
||||
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
|
||||
<field name="location_id"/>
|
||||
<field name="location_id" groups="stock.group_locations"/>
|
||||
<field name="minimum_planned_date"/>
|
||||
<field name="origin"/>
|
||||
<field name="state"/>
|
||||
@@ -92,12 +97,15 @@
|
||||
<button name="purchase_confirm" states="draft" string="Confirm Purchase Order" icon="gtk-apply"/>
|
||||
<button name="purchase_approve" states="confirmed" string="Approved by Supplier" icon="gtk-ok"/>
|
||||
</tree>
|
||||
</field>
|
||||
<button name="%(action_purchase_requisition_partner)d" string="Request a Quotation" type="action" icon="gtk-execute"
|
||||
attrs="{'readonly': [('state', '=', 'done')]}" />
|
||||
</page>
|
||||
</field>
|
||||
<separator string="Terms and Conditions"/>
|
||||
<field name="description"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</sheet>
|
||||
<footer>
|
||||
<field name="message_ids" widget="ThreadView"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
@@ -106,15 +114,17 @@
|
||||
<field name="type">tree</field>
|
||||
<field name="model">purchase.requisition</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree colors="grey:state == 'done';red:date_end<current_date and state not in ('done','cancel');black:date_end>=current_date;" string="Purchase Requisition">
|
||||
<tree fonts="bold:needaction_pending==True" colors="grey:state == 'cancel';red:date_end and date_end<current_date;black:date_end>current_date;" string="Purchase Requisition">
|
||||
<field name="needaction_pending" invisible="1"/>
|
||||
<field name="name"/>
|
||||
<field name="user_id"/>
|
||||
<field name="date_start"/>
|
||||
<field name="user_id"/>
|
||||
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
|
||||
<field name="date_end"/>
|
||||
<field name="origin"/>
|
||||
<field name="state"/>
|
||||
</tree>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_purchase_requisition_filter" model="ir.ui.view">
|
||||
@@ -123,19 +133,20 @@
|
||||
<field name="type">search</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search Purchase Requisition">
|
||||
<group>
|
||||
<group>
|
||||
<field name="name" string="Purchase Requisition"/>
|
||||
<separator orientation="vertical"/>
|
||||
<filter icon="terp-document-new" name="draft" string="New" domain="[('state','=','draft')]" help="New Purchase Requisition"/>
|
||||
<filter icon="terp-camera_test" string="In Progress" domain="[('state','=','in_progress')]" help="Purchase Requisition in negociation"/>
|
||||
<filter icon="terp-dialog-close" string="Done" domain="[('state','=','done')]" help="Current Purchase Requisition"/>
|
||||
<filter icon="terp-camera_test" string="Sent to Suppliers" domain="[('state','=','in_progress')]" help="Purchase Requisition in negociation"/>
|
||||
<filter icon="terp-dialog-close" string="Purchase Done" domain="[('state','=','done')]" help="Current Purchase Requisition"/>
|
||||
<separator orientation="vertical"/>
|
||||
<filter icon="terp-personal-" string="Unassigned" domain="[('user_id','=', False)]" help="Unassigned Requisition"/>
|
||||
<separator orientation="vertical"/>
|
||||
<field name="user_id" />
|
||||
<field name="exclusive" />
|
||||
</group>
|
||||
<newline/>
|
||||
<group expand="0" string="Group By...">
|
||||
<group expand="0" string="Group By...">
|
||||
<filter string="Responsible" icon="terp-personal" domain="[]" context="{'group_by':'user_id'}"/>
|
||||
<separator orientation="vertical"/>
|
||||
<filter string="Source" icon="terp-gtk-jump-to-rtl" domain="[]" context="{'group_by':'origin'}"/>
|
||||
@@ -144,7 +155,7 @@
|
||||
<filter string="Start Date" icon="terp-go-month" domain="[]" context="{'group_by':'date_start'}"/>
|
||||
<filter string="End Date" icon="terp-go-month" domain="[]" context="{'group_by':'date_end'}"/>
|
||||
</group>
|
||||
</search>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -186,7 +197,7 @@
|
||||
<field name="model">procurement.order</field>
|
||||
<field name="inherit_id" ref="procurement.procurement_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='close_move']" position="after">
|
||||
<xpath expr="//field[@name='close_move']" position="after">
|
||||
<field name="requisition_id"/>
|
||||
</xpath>
|
||||
</field>
|
||||
|
||||
@@ -28,7 +28,7 @@ class purchase_requisition_partner(osv.osv_memory):
|
||||
_name = "purchase.requisition.partner"
|
||||
_description = "Purchase Requisition Partner"
|
||||
_columns = {
|
||||
'partner_id': fields.many2one('res.partner', 'Partner', required=True,domain=[('supplier', '=', True)]),
|
||||
'partner_id': fields.many2one('res.partner', 'Supplier', required=True,domain=[('supplier', '=', True)]),
|
||||
}
|
||||
|
||||
def view_init(self, cr, uid, fields_list, context=None):
|
||||
|
||||
Reference in New Issue
Block a user