[REF] crm,sale,*: dashboard_graph_model values
rename values of selection field to actual model names. this prevents the need of a separate function to get the sql table and allows to get direct access to the model. (needed for the next commit)
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<field name="use_opportunities">True</field>
|
||||
<field name="use_leads">True</field>
|
||||
<field name="alias_name">sales</field>
|
||||
<field name="dashboard_graph_model">pipeline</field>
|
||||
<field name="dashboard_graph_model">crm.opportunity.report</field>
|
||||
</record>
|
||||
|
||||
<!--default alias for leads-->
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
<record id="sales_team.crm_team_1" model="crm.team">
|
||||
<field name="use_opportunities">True</field>
|
||||
<field name="dashboard_graph_model">pipeline</field>
|
||||
<field name="dashboard_graph_model">crm.opportunity.report</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
@@ -24,7 +24,7 @@ class Team(models.Model):
|
||||
opportunities_amount = fields.Integer(
|
||||
compute='_compute_opportunities',
|
||||
string='Amount of quotations to invoice', readonly=True)
|
||||
dashboard_graph_model = fields.Selection(selection_add=[('pipeline', 'Pipeline')])
|
||||
dashboard_graph_model = fields.Selection(selection_add=[('crm.opportunity.report', 'Pipeline')])
|
||||
dashboard_graph_period_pipeline = fields.Selection([
|
||||
('week', 'Within a Week'),
|
||||
('month', 'Within a Month'),
|
||||
@@ -66,7 +66,7 @@ class Team(models.Model):
|
||||
channel.dashboard_graph_period_pipeline = channel.dashboard_graph_period
|
||||
|
||||
def _inverse_dashboard_graph_period_pipeline(self):
|
||||
for channel in self.filtered(lambda ch: ch.dashboard_graph_model == 'pipeline'):
|
||||
for channel in self.filtered(lambda ch: ch.dashboard_graph_model == 'crm.opportunity.report'):
|
||||
channel.dashboard_graph_period = channel.dashboard_graph_period_pipeline
|
||||
|
||||
def get_alias_model_name(self, vals):
|
||||
@@ -92,7 +92,7 @@ class Team(models.Model):
|
||||
if self.team_type == 'sales':
|
||||
self.use_opportunities = True
|
||||
self.use_leads = lambda self: self.user_has_groups('crm.group_use_lead')
|
||||
self.dashboard_graph_model = 'pipeline'
|
||||
self.dashboard_graph_model = 'crm.opportunity.report'
|
||||
else:
|
||||
self.use_opportunities = False
|
||||
self.use_leads = False
|
||||
@@ -100,7 +100,7 @@ class Team(models.Model):
|
||||
|
||||
@api.onchange('dashboard_graph_model')
|
||||
def _onchange_dashboard_graph_model(self):
|
||||
if self.dashboard_graph_model == 'pipeline':
|
||||
if self.dashboard_graph_model == 'crm.opportunity.report':
|
||||
self.dashboard_graph_period_pipeline = self.dashboard_graph_period
|
||||
self.dashboard_graph_group_pipeline = self.dashboard_graph_group
|
||||
else:
|
||||
@@ -117,7 +117,7 @@ class Team(models.Model):
|
||||
|
||||
@api.constrains('dashboard_graph_model', 'use_opportunities')
|
||||
def _check_graph_model(self):
|
||||
if not self.use_opportunities and self.dashboard_graph_model == 'pipeline':
|
||||
if not self.use_opportunities and self.dashboard_graph_model == 'crm.opportunity.report':
|
||||
raise ValidationError(_("Dashboard graph content cannot be Pipeline if the sales channel doesn't use it. (Pipeline is unchecked.)"))
|
||||
|
||||
@api.model
|
||||
@@ -181,7 +181,7 @@ class Team(models.Model):
|
||||
def _graph_get_dates(self, today):
|
||||
""" return a coherent start and end date for the dashboard graph according to the graph settings.
|
||||
"""
|
||||
if self.dashboard_graph_model == 'pipeline':
|
||||
if self.dashboard_graph_model == 'crm.opportunity.report':
|
||||
if self.dashboard_graph_group == 'month':
|
||||
start_date = today.replace(day=1)
|
||||
elif self.dashboard_graph_group == 'week':
|
||||
@@ -210,7 +210,7 @@ class Team(models.Model):
|
||||
|
||||
def _get_graph(self):
|
||||
graph_datas = super(Team, self)._get_graph()
|
||||
if self.dashboard_graph_model == 'pipeline' and self.dashboard_graph_group_pipeline == 'stage':
|
||||
if self.dashboard_graph_model == 'crm.opportunity.report' and self.dashboard_graph_group_pipeline == 'stage':
|
||||
stage_data = self.env['crm.stage'].browse([d['label'] for d in graph_datas[0]['values']]).read(['sequence', 'name'])
|
||||
stage_data = {d['id']: {'name': d['name'], 'sequence': d['sequence']} for d in stage_data}
|
||||
graph_datas[0]['values'] = sorted(graph_datas[0]['values'], key=lambda el: stage_data[el['label']]['sequence'])
|
||||
@@ -219,26 +219,21 @@ class Team(models.Model):
|
||||
return graph_datas
|
||||
|
||||
def _graph_date_column(self):
|
||||
if self.dashboard_graph_model == 'pipeline':
|
||||
if self.dashboard_graph_model == 'crm.opportunity.report':
|
||||
return 'date_deadline'
|
||||
return super(Team, self)._graph_date_column()
|
||||
|
||||
def _graph_x_query(self):
|
||||
if self.dashboard_graph_model == 'pipeline' and self.dashboard_graph_group_pipeline == 'stage':
|
||||
if self.dashboard_graph_model == 'crm.opportunity.report' and self.dashboard_graph_group_pipeline == 'stage':
|
||||
return 'stage_id'
|
||||
return super(Team, self)._graph_x_query()
|
||||
|
||||
def _graph_y_query(self):
|
||||
if self.dashboard_graph_model == 'pipeline':
|
||||
if self.dashboard_graph_model == 'crm.opportunity.report':
|
||||
return 'SUM(expected_revenue)'
|
||||
return super(Team, self)._graph_y_query()
|
||||
|
||||
def _graph_sql_table(self):
|
||||
if self.dashboard_graph_model == 'pipeline':
|
||||
return 'crm_opportunity_report'
|
||||
return super(Team, self)._graph_sql_table()
|
||||
|
||||
def _graph_title_and_key(self):
|
||||
if self.dashboard_graph_model == 'pipeline':
|
||||
if self.dashboard_graph_model == 'crm.opportunity.report':
|
||||
return ['', _('Expected Revenue')] # no more title
|
||||
return super(Team, self)._graph_title_and_key()
|
||||
|
||||
@@ -109,16 +109,16 @@
|
||||
attrs="{'invisible': [('use_leads', '=', False), ('use_opportunities', '=', False)]}"/>
|
||||
</xpath>
|
||||
<field name="dashboard_graph_period" position="attributes">
|
||||
<attribute name="attrs">{'invisible': [('dashboard_graph_model', '=', 'pipeline')]}</attribute>
|
||||
<attribute name="attrs">{'invisible': [('dashboard_graph_model', '=', 'crm.opportunity.report')]}</attribute>
|
||||
</field>
|
||||
<field name="dashboard_graph_period" position="after">
|
||||
<field name="dashboard_graph_period_pipeline" attrs="{'invisible': [('dashboard_graph_model', '!=', 'pipeline')]}"/>
|
||||
<field name="dashboard_graph_period_pipeline" attrs="{'invisible': [('dashboard_graph_model', '!=', 'crm.opportunity.report')]}"/>
|
||||
</field>
|
||||
<field name="dashboard_graph_group" position="attributes">
|
||||
<attribute name="attrs">{'invisible': [('dashboard_graph_model', '=', 'pipeline')]}</attribute>
|
||||
<attribute name="attrs">{'invisible': [('dashboard_graph_model', '=', 'crm.opportunity.report')]}</attribute>
|
||||
</field>
|
||||
<field name="dashboard_graph_group" position="after">
|
||||
<field name="dashboard_graph_group_pipeline" attrs="{'invisible': [('dashboard_graph_model', '!=', 'pipeline')]}"/>
|
||||
<field name="dashboard_graph_group_pipeline" attrs="{'invisible': [('dashboard_graph_model', '!=', 'crm.opportunity.report')]}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<record id="pos_sales_team" model="crm.team">
|
||||
<field name="name">Point of Sale</field>
|
||||
<field name="team_type" eval="'pos'"/>
|
||||
<field name="dashboard_graph_model">sales</field>
|
||||
<field name="dashboard_graph_model">sale.report</field>
|
||||
</record>
|
||||
<record id="point_of_sale.pos_config_main" model="pos.config">
|
||||
<field name="crm_team_id" ref="pos_sales_team"/>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<attribute name="attrs">{'readonly': [('team_type', 'in', ['pos', 'ebay'])]}</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='dashboard_graph_group']" position="attributes">
|
||||
<attribute name="attrs">{'invisible': ['|', ('dashboard_graph_model', '=', 'pipeline'), ('team_type', '=', 'pos')]}</attribute>
|
||||
<attribute name="attrs">{'invisible': ['|', ('dashboard_graph_model', '=', 'crm.opportunity.report'), ('team_type', '=', 'pos')]}</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='dashboard_graph_group']" position="after">
|
||||
<field name="dashboard_graph_group_pos" attrs="{'invisible': [('team_type', '!=', 'pos')]}"/>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<record model="crm.team" id="sales_team.team_sales_department">
|
||||
<field name="use_quotations" eval="True"/>
|
||||
<field name="use_invoices" eval="True"/>
|
||||
<field name="dashboard_graph_model">sales</field>
|
||||
<field name="dashboard_graph_model">sale.report</field>
|
||||
</record>
|
||||
|
||||
<!-- Sale-related subtypes for messaging / Chatter -->
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<field name="use_quotations" eval="True"/>
|
||||
<field name="use_invoices" eval="True"/>
|
||||
<field name="invoiced_target">40000</field>
|
||||
<field name="dashboard_graph_model">sales</field>
|
||||
<field name="dashboard_graph_model">sale.report</field>
|
||||
</record>
|
||||
|
||||
<record id="sale_order_1" model="sale.order">
|
||||
|
||||
@@ -32,8 +32,8 @@ class CrmTeam(models.Model):
|
||||
compute='_compute_sales_to_invoice',
|
||||
string='Number of sales to invoice', readonly=True)
|
||||
dashboard_graph_model = fields.Selection(selection_add=[
|
||||
('sales', 'Sales'),
|
||||
('invoices', 'Invoices'),
|
||||
('sale.report', 'Sales'),
|
||||
('account.invoice.report', 'Invoices'),
|
||||
])
|
||||
|
||||
def _compute_quotations_to_invoice(self):
|
||||
@@ -69,37 +69,30 @@ class CrmTeam(models.Model):
|
||||
self.browse(datum['team_id'][0]).invoiced = datum['amount_untaxed_signed']
|
||||
|
||||
def _graph_date_column(self):
|
||||
if self.dashboard_graph_model == 'sales':
|
||||
if self.dashboard_graph_model == 'sale.report':
|
||||
return 'confirmation_date'
|
||||
elif self.dashboard_graph_model == 'invoices':
|
||||
elif self.dashboard_graph_model == 'account.invoice.report':
|
||||
return 'date'
|
||||
return super(CrmTeam, self)._graph_date_column()
|
||||
|
||||
def _graph_y_query(self):
|
||||
if self.dashboard_graph_model == 'sales':
|
||||
if self.dashboard_graph_model == 'sale.report':
|
||||
return 'SUM(price_subtotal)'
|
||||
elif self.dashboard_graph_model == 'invoices':
|
||||
elif self.dashboard_graph_model == 'account.invoice.report':
|
||||
return 'SUM(price_total)'
|
||||
return super(CrmTeam, self)._graph_y_query()
|
||||
|
||||
def _graph_sql_table(self):
|
||||
if self.dashboard_graph_model == 'sales':
|
||||
return 'sale_report'
|
||||
elif self.dashboard_graph_model == 'invoices':
|
||||
return 'account_invoice_report'
|
||||
return super(CrmTeam, self)._graph_sql_table()
|
||||
|
||||
def _extra_sql_conditions(self):
|
||||
if self.dashboard_graph_model == 'sales':
|
||||
if self.dashboard_graph_model == 'sale.report':
|
||||
return "AND state in ('sale', 'done')"
|
||||
elif self.dashboard_graph_model == 'invoices':
|
||||
elif self.dashboard_graph_model == 'account.invoice.report':
|
||||
return "AND state in ('open', 'paid')"
|
||||
return super(CrmTeam, self)._extra_sql_conditions()
|
||||
|
||||
def _graph_title_and_key(self):
|
||||
if self.dashboard_graph_model == 'sales':
|
||||
if self.dashboard_graph_model == 'sale.report':
|
||||
return ['', _('Untaxed Total')] # no more title
|
||||
elif self.dashboard_graph_model == 'invoices':
|
||||
elif self.dashboard_graph_model == 'account.invoice.report':
|
||||
return ['', _('Untaxed Total')]
|
||||
return super(CrmTeam, self)._graph_title_and_key()
|
||||
|
||||
@@ -125,13 +118,13 @@ class CrmTeam(models.Model):
|
||||
if self.team_type == 'sales':
|
||||
self.use_quotations = True
|
||||
self.use_invoices = True
|
||||
# do not override dashboard_graph_model 'pipeline' if crm is installed
|
||||
# do not override dashboard_graph_model 'crm.opportunity.report' if crm is installed
|
||||
if not self.dashboard_graph_model:
|
||||
self.dashboard_graph_model = 'sales'
|
||||
self.dashboard_graph_model = 'sale.report'
|
||||
else:
|
||||
self.use_quotations = False
|
||||
self.use_invoices = False
|
||||
self.dashboard_graph_model = 'sales'
|
||||
self.dashboard_graph_model = 'sale.report'
|
||||
return super(CrmTeam, self)._onchange_team_type()
|
||||
|
||||
@api.multi
|
||||
|
||||
@@ -123,9 +123,6 @@ class CrmTeam(models.Model):
|
||||
def _graph_y_query(self):
|
||||
raise UserError(_('Undefined graph model for Sales Channel: %s') % self.name)
|
||||
|
||||
def _graph_sql_table(self):
|
||||
raise UserError(_('Undefined graph model for Sales Channel: %s') % self.name)
|
||||
|
||||
def _extra_sql_conditions(self):
|
||||
return ''
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
<record model="crm.team" id="sales_team.salesteam_website_sales">
|
||||
<field name="active" eval="True"/>
|
||||
<field name="dashboard_graph_model">sales</field>
|
||||
<field name="dashboard_graph_model">sale.report</field>
|
||||
<field name="dashboard_graph_period">week</field>
|
||||
</record>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user