Skip to content
Extraits de code Groupes Projets
Valider e50cb30f rédigé par Juliana's avatar Juliana
Parcourir les fichiers

Correction sur les feuilles de temps

parent 82d987b2
Branches 16.0
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import product import product
import procurement
import sale_config_settings import sale_config_settings
import res_config import res_config
import project_task_type import project_task_type
......
# -*- coding: utf-8 -*-
# © 2017 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models, _
class LeFilamentProcurementOrder(models.Model):
_inherit = 'procurement.order'
def _is_procurement_task(self):
return self.product_id.type == 'service' and self.product_id.track_service == 'task'
def _get_stage_id(self):
Stage = self.env['project.task.type']
stage = self.product_id.with_context(force_company=self.company_id.id).project_task_type_id
if not stage:
stage_id = self.env['ir.values'].get_default('sale.config.settings', 'project_task_type_id')
stage = self.env['project.task.type'].browse(stage_id)
return stage
def _get_project(self):
Project = self.env['project.project']
project = self.product_id.with_context(force_company=self.company_id.id).project_id
if not project and self.sale_line_id:
# find the project corresponding to the analytic account of the sales order
account = self.sale_line_id.order_id.project_id
if not account:
self.sale_line_id.order_id._create_analytic_account()
account = self.sale_line_id.order_id.project_id
project = Project.search([('analytic_account_id', '=', account.id)], limit=1)
if not project:
project_id = account.project_create({'name': self.sale_line_id.order_id.partner_id.name, 'use_tasks': True})
project = Project.browse(project_id)
return project
def _update_project_data(self, project):
project.lf_total_budget = project.lf_total_budget + self.sale_line_id.price_subtotal
def _create_service_task(self):
project = self._get_project()
planned_hours = self._convert_qty_company_hours()
task = self.env['project.task'].create({
'name': '%s:%s' % (self.origin or '', self.product_id.name),
'date_deadline': self.date_planned,
'planned_hours': planned_hours,
'remaining_hours': planned_hours,
'partner_id': self.sale_line_id.order_id.partner_id.id or self.partner_dest_id.id,
'user_id': self.env.uid,
'procurement_id': self.id,
'description': self.name + '<br/>',
'project_id': project.id,
'company_id': self.company_id.id,
})
self.write({'task_id': task.id})
msg_body = _("Task Created (%s): <a href=# data-oe-model=project.task data-oe-id=%d>%s</a>") % (self.product_id.name, task.id, task.name)
self.message_post(body=msg_body)
if self.sale_line_id.order_id:
self.sale_line_id.order_id.message_post(body=msg_body)
task_msg = _("This task has been created from: <a href=# data-oe-model=sale.order data-oe-id=%d>%s</a> (%s)") % (self.sale_line_id.order_id.id, self.sale_line_id.order_id.name, self.product_id.name)
task.message_post(body=task_msg)
return task
\ No newline at end of file
...@@ -81,44 +81,17 @@ class SaleOrder(models.Model): ...@@ -81,44 +81,17 @@ class SaleOrder(models.Model):
project_date.lf_tarif_jour = lf_tarif_jour project_date.lf_tarif_jour = lf_tarif_jour
project_date.lf_total_budget = project_total_budget project_date.lf_total_budget = project_total_budget
order.tasks_ids = self.env['project.task'].search([('sale_line_id', 'in', order.order_line.ids)]) order.tasks_ids = self.env['project.task'].search([('sale_line_id', 'in', order.order_line.ids)])
order.tasks_count = len(order.tasks_ids) order.tasks_unt = len(order.tasks_ids)
class LeFilamentSaleOrderLine(models.Model): class LeFilamentSaleOrderLine(models.Model):
_inherit = "sale.order.line" _inherit = "sale.order.line"
@api.multi @api.multi
def _compute_analytic(self, domain=None): def _compute_analytic(self, domain=None):
lines = {}
force_so_lines = self.env.context.get("force_so_lines")
if not domain and self.ids: if not domain and self.ids:
# To filter on analyic lines linked to an expense # To filter on analyic lines linked to an expense
expense_type_id = self.env.ref('account.data_account_type_expenses', raise_if_not_found=False) expense_type_id = self.env.ref('account.data_account_type_expenses', raise_if_not_found=False)
expense_type_id = expense_type_id and expense_type_id.id expense_type_id = expense_type_id and expense_type_id.id
domain = [('so_line', 'in', self.ids), '|', ('amount', '<=', 0.0), ('project_id', '!=', False)] prod_list = self.env['product.template'].search([('track_service','in', ['task','timesheet'])])
domain = [('product_id', 'in', prod_list.ids), ('so_line', 'in', self.ids), '|', ('amount', '<=', 0.0), ('project_id', '!=', False)]
data = self.env['account.analytic.line'].read_group( return super(LeFilamentSaleOrderLine, self)._compute_analytic(domain=domain)
domain, \ No newline at end of file
['so_line', 'unit_amount', 'product_uom_id'], ['product_uom_id', 'so_line'], lazy=False
)
# If the unlinked analytic line was the last one on the SO line, the qty was not updated.
if force_so_lines:
for line in force_so_lines:
lines.setdefault(line, 0.0)
for d in data:
if not d['product_uom_id']:
continue
line = self.browse(d['so_line'][0])
lines.setdefault(line, 0.0)
uom = self.env['product.uom'].browse(d['product_uom_id'][0])
if line.product_uom.category_id == uom.category_id:
qty = uom._compute_quantity(d['unit_amount'], line.product_uom)
else:
qty = d['unit_amount']
lines[line] += qty
for line, qty in lines.items():
if line.product_id.track_service == 'project':
line.qty_delivered = 0
else:
line.qty_delivered = qty
return True
...@@ -65,9 +65,15 @@ class LeFilamentSaleWizard(models.TransientModel): ...@@ -65,9 +65,15 @@ class LeFilamentSaleWizard(models.TransientModel):
date_deadline = (date_plan.date() + relativedelta(years=int(line.product_uom_qty))).strftime('%Y-%m-%d') date_deadline = (date_plan.date() + relativedelta(years=int(line.product_uom_qty))).strftime('%Y-%m-%d')
stage = line.product_id.project_task_type_id stage = line.product_id.project_task_type_id
if sale_id.partner_id.is_company == True: if sale_id.partner_id.is_company == True:
if stage.name:
name_task = sale_id.partner_id.name + " - " + stage.name name_task = sale_id.partner_id.name + " - " + stage.name
else: else:
name_task = sale_id.partner_id.name
else:
if stage.name:
name_task = sale_id.partner_id.parent_id.name + " - " + stage.name name_task = sale_id.partner_id.parent_id.name + " - " + stage.name
else:
name_task = sale_id.partner_id.parent_id.name
else: else:
stage = stage_new stage = stage_new
project_id = project_id_new project_id = project_id_new
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter