Skip to content

Commit

Permalink
Merge pull request #51 from Daniel-CA/sales_team_analytic_tag
Browse files Browse the repository at this point in the history
[IMP] sales_team_analytic_tag:  Tags added on create function
  • Loading branch information
Daniel authored Aug 2, 2019
2 parents 8cfaa23 + 1b77af6 commit 5da47b2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion sales_team_analytic_tag/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
'name': 'Sales Team Analytic Tag',
'version': '12.0.1.0.0',
'version': '12.0.1.1.0',
'depends': [
'sale',
'sales_team',
Expand Down
25 changes: 11 additions & 14 deletions sales_team_analytic_tag/models/sale_order.py
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
7 changes: 1 addition & 6 deletions sales_team_analytic_tag/tests/test_sale_analytic_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ def test_add_analytic_tags(self):
'price_unit': 100,
'order_id': self.sale_order.id
}
line = self.env['sale.order.line'].with_context(
params={'model': 'sale.order',
'id': self.sale_order.id}).create(line_vals)
line = self.env['sale.order.line'].create(line_vals)
self.assertEqual(line.analytic_tag_ids.ids,
self.team.analytic_tag_ids.ids)
self.sale_order.team_id = self.default_team.id
line2 = self.env['sale.order.line'].with_context({}).create(line_vals)
self.assertEqual(line2.analytic_tag_ids.ids,
self.default_team.analytic_tag_ids.ids)

0 comments on commit 5da47b2

Please sign in to comment.