mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-27 17:31:59 +02:00
19.0 vanilla
This commit is contained in:
parent
79f83631d5
commit
73afc09215
6267 changed files with 1534193 additions and 1130106 deletions
|
|
@ -3,5 +3,4 @@
|
|||
|
||||
from . import crm_lead
|
||||
from . import crm_team
|
||||
from . import res_users
|
||||
from . import sale_order
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.osv import expression
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.fields import Domain
|
||||
|
||||
|
||||
class CrmLead(models.Model):
|
||||
|
|
@ -46,8 +43,8 @@ class CrmLead(models.Model):
|
|||
action = self.env["ir.actions.actions"]._for_xml_id("sale.action_quotations_with_onboarding")
|
||||
action['context'] = self._prepare_opportunity_quotation_context()
|
||||
action['context']['search_default_draft'] = 1
|
||||
action['domain'] = expression.AND([[('opportunity_id', '=', self.id)], self._get_lead_quotation_domain()])
|
||||
quotations = self.order_ids.filtered_domain(self._get_lead_quotation_domain())
|
||||
action['domain'] = Domain.AND([[('opportunity_id', '=', self.id)], self._get_action_view_sale_quotation_domain()])
|
||||
quotations = self.order_ids.filtered_domain(self._get_action_view_sale_quotation_domain())
|
||||
if len(quotations) == 1:
|
||||
action['views'] = [(self.env.ref('sale.view_order_form').id, 'form')]
|
||||
action['res_id'] = quotations.id
|
||||
|
|
@ -61,13 +58,16 @@ class CrmLead(models.Model):
|
|||
'default_partner_id': self.partner_id.id,
|
||||
'default_opportunity_id': self.id,
|
||||
}
|
||||
action['domain'] = expression.AND([[('opportunity_id', '=', self.id)], self._get_lead_sale_order_domain()])
|
||||
action['domain'] = Domain.AND([[('opportunity_id', '=', self.id)], self._get_lead_sale_order_domain()])
|
||||
orders = self.order_ids.filtered_domain(self._get_lead_sale_order_domain())
|
||||
if len(orders) == 1:
|
||||
action['views'] = [(self.env.ref('sale.view_order_form').id, 'form')]
|
||||
action['res_id'] = orders.id
|
||||
return action
|
||||
|
||||
def _get_action_view_sale_quotation_domain(self):
|
||||
return [('state', 'in', ('draft', 'sent', 'cancel'))]
|
||||
|
||||
def _get_lead_quotation_domain(self):
|
||||
return [('state', 'in', ('draft', 'sent'))]
|
||||
|
||||
|
|
@ -98,3 +98,12 @@ class CrmLead(models.Model):
|
|||
# add all the orders from all lead to merge
|
||||
fields_info['order_ids'] = lambda fname, leads: [(4, order.id) for order in leads.order_ids]
|
||||
return fields_info
|
||||
|
||||
def _update_revenues_from_so(self, order):
|
||||
for opportunity in self:
|
||||
if (
|
||||
(opportunity.expected_revenue or 0) < order.amount_untaxed
|
||||
and order.currency_id == opportunity.company_id.currency_id
|
||||
):
|
||||
opportunity.expected_revenue = order.amount_untaxed
|
||||
opportunity._track_set_log_message(_('Expected revenue has been updated based on the linked Sales Orders.'))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models,fields, api, _
|
||||
from odoo import _, models
|
||||
|
||||
|
||||
class CrmTeam(models.Model):
|
||||
|
|
@ -10,35 +9,10 @@ class CrmTeam(models.Model):
|
|||
def _compute_dashboard_button_name(self):
|
||||
super(CrmTeam, self)._compute_dashboard_button_name()
|
||||
teams_with_opp = self.filtered(lambda team: team.use_opportunities)
|
||||
if self._context.get('in_sales_app'):
|
||||
if self.env.context.get('in_sales_app'):
|
||||
teams_with_opp.update({'dashboard_button_name': _("Sales Analysis")})
|
||||
|
||||
def action_primary_channel_button(self):
|
||||
if self._context.get('in_sales_app') and self.use_opportunities:
|
||||
if self.env.context.get('in_sales_app') and self.use_opportunities:
|
||||
return self.env["ir.actions.actions"]._for_xml_id("sale.action_order_report_so_salesteam")
|
||||
return super(CrmTeam,self).action_primary_channel_button()
|
||||
|
||||
def _graph_get_model(self):
|
||||
if self.use_opportunities and self._context.get('in_sales_app') :
|
||||
return 'sale.report'
|
||||
return super(CrmTeam,self)._graph_get_model()
|
||||
|
||||
def _graph_date_column(self):
|
||||
if self.use_opportunities and self._context.get('in_sales_app'):
|
||||
return 'date'
|
||||
return super(CrmTeam,self)._graph_date_column()
|
||||
|
||||
def _graph_y_query(self):
|
||||
if self.use_opportunities and self._context.get('in_sales_app'):
|
||||
return 'SUM(price_subtotal)'
|
||||
return super(CrmTeam,self)._graph_y_query()
|
||||
|
||||
def _graph_title_and_key(self):
|
||||
if self.use_opportunities and self._context.get('in_sales_app'):
|
||||
return ['', _('Sales: Untaxed Total')]
|
||||
return super(CrmTeam,self)._graph_title_and_key()
|
||||
|
||||
def _extra_sql_conditions(self):
|
||||
if self.use_opportunities and self._context.get('in_sales_app'):
|
||||
return "AND state in ('sale', 'done', 'pos_done')"
|
||||
return super(CrmTeam,self)._extra_sql_conditions()
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResUsers(models.Model):
|
||||
_inherit = 'res.users'
|
||||
|
||||
target_sales_invoiced = fields.Integer('Invoiced in Sales Orders Target')
|
||||
|
|
@ -8,8 +8,11 @@ class SaleOrder(models.Model):
|
|||
_inherit = 'sale.order'
|
||||
|
||||
opportunity_id = fields.Many2one(
|
||||
'crm.lead', string='Opportunity', check_company=True,
|
||||
'crm.lead', string='Opportunity', check_company=True, index='btree_not_null',
|
||||
domain="[('type', '=', 'opportunity'), '|', ('company_id', '=', False), ('company_id', '=', company_id)]")
|
||||
|
||||
def action_confirm(self):
|
||||
return super(SaleOrder, self.with_context({k:v for k,v in self._context.items() if k != 'default_tag_ids'})).action_confirm()
|
||||
res = super(SaleOrder, self.with_context({k: v for k, v in self.env.context.items() if k != 'default_tag_ids'})).action_confirm()
|
||||
for order in self:
|
||||
order.opportunity_id._update_revenues_from_so(order)
|
||||
return res
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue