-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from Daniel-CA/sales_team_analytic_tag
[IMP] sales_team_analytic_tag: Tags added on create function
- Loading branch information
Showing
3 changed files
with
13 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,21 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
# Copyright (c) 2019 Daniel Campos <[email protected]> - Avanzosc S.L. | ||
|
||
from odoo import fields, models | ||
from odoo import api, fields, models | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
_inherit = 'sale.order.line' | ||
|
||
def _get_default_tag(self): | ||
sale_obj = self.env['sale.order'] | ||
context_data = self.env.context.get('params', {}) | ||
tag_ids = {} | ||
if not context_data: | ||
tag_ids = self.env['crm.team']._get_default_team_id().\ | ||
analytic_tag_ids.ids | ||
if 'model' in context_data and context_data['model'] == 'sale.order': | ||
sale = sale_obj.browse(context_data['id']) | ||
tag_ids = sale.team_id.analytic_tag_ids.ids | ||
return tag_ids | ||
|
||
analytic_tag_ids = fields.Many2many( | ||
comodel_name='account.analytic.tag', | ||
default=lambda self: self._get_default_tag()) | ||
) | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
lines = super(SaleOrderLine, self).create(vals_list) | ||
for line in lines: | ||
line.analytic_tag_ids = list( | ||
dict.fromkeys(line.analytic_tag_ids.ids + | ||
line.order_id.team_id.analytic_tag_ids.ids)) | ||
return lines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters