From c32558e5e420215e2ed24c776c96800dc351f5df Mon Sep 17 00:00:00 2001 From: Gert Pellin Date: Thu, 29 Aug 2019 12:53:43 +0000 Subject: [PATCH] [FIX] pos_sale: traceback on installing sales If a pos session is started in the automatically created pos config and the sales app is installed afterwards, a traceback will be shown. This is because pos_sale tries to make changes to the config, which are not allowed. We removed the hardcoded team in data, and manage the default value in an onchange on the company_id to keep a consistant team. --- addons/pos_sale/data/pos_sale_data.xml | 3 --- addons/pos_sale/models/pos_config.py | 16 ++++++++++------ addons/sales_team/data/sales_team_data.xml | 1 + 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/addons/pos_sale/data/pos_sale_data.xml b/addons/pos_sale/data/pos_sale_data.xml index c57f8d7dccf..fc4c0dff1f1 100644 --- a/addons/pos_sale/data/pos_sale_data.xml +++ b/addons/pos_sale/data/pos_sale_data.xml @@ -4,9 +4,6 @@ - - - diff --git a/addons/pos_sale/models/pos_config.py b/addons/pos_sale/models/pos_config.py index e34a805b271..c6a8dd7cc90 100644 --- a/addons/pos_sale/models/pos_config.py +++ b/addons/pos_sale/models/pos_config.py @@ -1,18 +1,22 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import fields, models +from odoo import fields, models, api from odoo.exceptions import AccessError class PosConfig(models.Model): _inherit = 'pos.config' - def _get_default_pos_team(self): - team = self.env['crm.team'].search(['|', ('company_id', '=', self.env.company.id), ('company_id', '=', False)], limit=1) - return team crm_team_id = fields.Many2one( 'crm.team', string="Sales Team", - help="This Point of sale's sales will be related to this Sales Team.", - default=_get_default_pos_team) + help="This Point of sale's sales will be related to this Sales Team.") + + @api.onchange('company_id') + def _get_default_pos_team(self): + default_sale_team = self.env.ref('sales_team.pos_sales_team', raise_if_not_found=False) + if default_sale_team and (not default_sale_team.company_id or default_sale_team.company_id == self.company_id): + self.crm_team_id = default_sale_team + else: + self.crm_team_id = self.env['crm.team'].search(['|', ('company_id', '=', self.company_id.id), ('company_id', '=', False)], limit=1) diff --git a/addons/sales_team/data/sales_team_data.xml b/addons/sales_team/data/sales_team_data.xml index cf007fd3f25..53d006f2324 100644 --- a/addons/sales_team/data/sales_team_data.xml +++ b/addons/sales_team/data/sales_team_data.xml @@ -16,6 +16,7 @@ Point of Sale +