summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMehul Patel <mep@odoo.com>2017-11-21 16:30:18 +0530
committerjem-odoo <jem@openerp.com>2017-11-28 11:45:42 +0100
commit3680e099a69cbefad7c5afb5b4e049f6f0b3fc39 (patch)
treed813bde8bf5a96ac3fa77af3fb469e9ab203eae9
parentbf6894c5b133f9e50458b4c70a37db2a2edd3734 (diff)
[FIX] project, sale_timesheet: analytic account and project creation
When we create an analytic account, a project is automatically generate, and it should not. This is a bug coming from the removal of 'use_tasks' field. See eb4ad335137de7831902e760e3fc375eeb81f326. We can now remove all the 'project_create' and 'project_creation_in_progress' context key.
-rw-r--r--addons/project/models/project.py40
-rw-r--r--addons/sale_timesheet/models/sale_order.py4
2 files changed, 3 insertions, 41 deletions
diff --git a/addons/project/models/project.py b/addons/project/models/project.py
index 6907edf4543..178ab8b5c66 100644
--- a/addons/project/models/project.py
+++ b/addons/project/models/project.py
@@ -251,7 +251,7 @@ class Project(models.Model):
@api.model
def create(self, vals):
# Prevent double project creation
- self = self.with_context(project_creation_in_progress=True, mail_create_nosubscribe=True)
+ self = self.with_context(mail_create_nosubscribe=True)
project = super(Project, self).create(vals)
if not vals.get('subtask_project_id'):
project.subtask_project_id = project.id
@@ -879,44 +879,6 @@ class AccountAnalyticAccount(models.Model):
for account in self:
account.project_count = len(account.with_context(active_test=False).project_ids)
- @api.model
- def _trigger_project_creation(self, vals):
- '''
- This function is used to decide if a project needs to be automatically created or not when an analytic account is created. It returns True if it needs to be so, False otherwise.
- '''
- return 'project_creation_in_progress' not in self.env.context
-
- @api.multi
- def project_create(self, vals):
- '''
- This function is called at the time of analytic account creation and is used to create a project automatically linked to it if the conditions are meet.
- '''
- self.ensure_one()
- Project = self.env['project.project']
- project = Project.with_context(active_test=False).search([('analytic_account_id', '=', self.id)])
- if not project and self._trigger_project_creation(vals):
- project_values = {
- 'name': vals.get('name'),
- 'analytic_account_id': self.id,
- }
- return Project.create(project_values).id
- return False
-
- @api.model
- def create(self, vals):
- analytic_account = super(AccountAnalyticAccount, self).create(vals)
- analytic_account.project_create(vals)
- return analytic_account
-
- @api.multi
- def write(self, vals):
- vals_for_project = vals.copy()
- for account in self:
- if not vals.get('name'):
- vals_for_project['name'] = account.name
- account.project_create(vals_for_project)
- return super(AccountAnalyticAccount, self).write(vals)
-
@api.multi
def unlink(self):
projects = self.env['project.project'].search([('analytic_account_id', 'in', self.ids)])
diff --git a/addons/sale_timesheet/models/sale_order.py b/addons/sale_timesheet/models/sale_order.py
index 379a5a483a2..c6665d0272f 100644
--- a/addons/sale_timesheet/models/sale_order.py
+++ b/addons/sale_timesheet/models/sale_order.py
@@ -200,11 +200,11 @@ class SaleOrderLine(models.Model):
project = Project.search([('analytic_account_id', '=', account.id)], limit=1)
if not project:
project_name = '%s (%s)' % (account.name, self.order_partner_id.ref) if self.order_partner_id.ref else account.name
- project_id = account.sudo().project_create({
+ project = Project.create({
'name': project_name,
'allow_timesheets': self.product_id.service_type == 'timesheet',
+ 'analytic_account_id': account.id,
})
- project = Project.sudo().browse(project_id)
# set the SO line origin if product should create project
if not project.sale_line_id and self.product_id.service_tracking in ['task_new_project', 'project_only']:
project.write({'sale_line_id': self.id})