[IMP] sale_crm: on opportunity form view, add a button linking to the
sales related to the current opportunity, using a stat button. Two fields are introduced: opportunity_id on sale.order (automatically set when using the make sale wizard), and sale_amount_total on the opportunity, function field computing the total amount for the not canceled quotations related to the opportunity.
This commit is contained in:
committed by
Thibault Delavallée
parent
d010062e0f
commit
4ea9c4f05d
@@ -379,7 +379,7 @@
|
||||
domain="['&', ('section_ids', '=', section_id), '|', ('type', '=', type), ('type', '=', 'both')]"/>
|
||||
</header>
|
||||
<sheet>
|
||||
<div class="oe_right oe_button_box">
|
||||
<div name="buttons" class="oe_right oe_button_box">
|
||||
<button class="oe_inline oe_stat_button" type="action"
|
||||
name="%(crm.crm_case_categ_phone_incoming0)d" icon="fa-phone"
|
||||
context="{'default_opportunity_id': active_id, 'search_default_opportunity_id': active_id, 'default_partner_id': partner_id, 'default_duration': 1.0}">
|
||||
|
||||
@@ -21,5 +21,6 @@
|
||||
|
||||
import wizard
|
||||
import sale_crm
|
||||
import crm_lead
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
from openerp.osv import osv, fields
|
||||
|
||||
|
||||
class crm_lead(osv.Model):
|
||||
_inherit = 'crm.lead'
|
||||
|
||||
def _get_sale_amount_total(self, cr, uid, ids, fields, args, context=None):
|
||||
res = dict.fromkeys(ids, False)
|
||||
sale_rec = self.pool['sale.order'].read_group(cr, uid, [('opportunity_id', 'in', ids), ('state', '!=', 'cancel')], ['opportunity_id', 'amount_total'], ['opportunity_id'], context=context)
|
||||
for key, value in dict(map(lambda x: (x['opportunity_id'] and x['opportunity_id'][0], x['amount_total']), sale_rec)).items():
|
||||
res[key] = value
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'sale_amount_total': fields.function(_get_sale_amount_total, string="Total Amount Of Quotations", type="float")
|
||||
}
|
||||
@@ -26,5 +26,6 @@ class sale_order(osv.osv):
|
||||
_inherit = ['sale.order', 'crm.tracking.mixin']
|
||||
_columns = {
|
||||
'categ_ids': fields.many2many('crm.case.categ', 'sale_order_category_rel', 'order_id', 'category_id', 'Tags', \
|
||||
domain="['|', ('section_id', '=', section_id), ('section_id', '=', False), ('object_id.model', '=', 'crm.lead')]", context="{'object_name': 'crm.lead'}")
|
||||
domain="['|', ('section_id', '=', section_id), ('section_id', '=', False), ('object_id.model', '=', 'crm.lead')]", context="{'object_name': 'crm.lead'}"),
|
||||
'opportunity_id': fields.many2one('crm.lead', 'Opportunity', domain="[('type', '=', 'opportunity')]")
|
||||
}
|
||||
|
||||
@@ -2,6 +2,13 @@
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<act_window name="Sale Orders"
|
||||
context="{'search_default_opportunity_id': [active_id], 'default_opportunity_id': active_id}"
|
||||
res_model="sale.order"
|
||||
src_model="crm.lead"
|
||||
domain="[('opportunity_id', 'in', [active_id])]"
|
||||
id="sale_action_quotations"/>
|
||||
|
||||
<record model="ir.ui.view" id="crm_case_form_view_oppor">
|
||||
<field name="name">CRM - Opportunities - Quote Inherit</field>
|
||||
<field name="model">crm.lead</field>
|
||||
@@ -12,6 +19,11 @@
|
||||
<button attrs="{'invisible': [('probability', '<', 100)]}" string="Create Quotation" name="%(action_crm_make_sale)d" type="action"/>
|
||||
<button attrs="{'invisible': [('probability', '=', 100)]}" string="Convert to Quotation" name="%(action_crm_make_sale)d" type="action" class="oe_highlight"/>
|
||||
</xpath>
|
||||
<xpath expr="//div[@name='buttons']" position="inside">
|
||||
<button class="oe_inline oe_stat_button" type="action" name="%(sale_action_quotations)d" icon="stat_button_icon fa fa-usd">
|
||||
<div><strong><field name="sale_amount_total" widget="monetary"/></strong><br/>Sales</div>
|
||||
</button>
|
||||
</xpath>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
@@ -34,7 +46,9 @@
|
||||
<field name="medium_id" />
|
||||
<field name="source_id" />
|
||||
</field>
|
||||
|
||||
<field name="origin" position="after">
|
||||
<field name="opportunity_id"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
<record id="base.res_partner_address_type" model="ir.ui.view">
|
||||
|
||||
@@ -101,6 +101,7 @@ class crm_make_sale(osv.osv_memory):
|
||||
'date_order': fields.date.context_today(self,cr,uid,context=context),
|
||||
'fiscal_position': fpos,
|
||||
'payment_term':payment_term,
|
||||
'opportunity_id': case.id
|
||||
}
|
||||
if partner.id:
|
||||
vals['user_id'] = partner.user_id and partner.user_id.id or uid
|
||||
|
||||
Reference in New Issue
Block a user