Lead data transfer, valdiation added
This commit is contained in:
parent
39954327aa
commit
878b213f8d
|
@ -6,4 +6,3 @@ from . import project
|
|||
from . import project_overview
|
||||
from . import analytic
|
||||
from . import product
|
||||
#from . import sale
|
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo import api, exceptions, fields, models, _
|
||||
from odoo.exceptions import UserError, AccessError, ValidationError
|
||||
from odoo.osv import expression
|
||||
|
||||
|
@ -11,6 +11,22 @@ class AccountAnalyticLine(models.Model):
|
|||
start_time = fields.Float('Start Time', digits=(16, 2))
|
||||
end_time = fields.Float('End Time', digits=(16, 2))
|
||||
|
||||
@api.constrains('start_time', 'end_time')
|
||||
def _check_validity_start_time_end_time(self):
|
||||
for rec in self:
|
||||
if rec.start_time and rec.end_time:
|
||||
if rec.end_time < rec.start_time:
|
||||
raise exceptions.ValidationError(_('End time cannot be earlier than Start time'))
|
||||
|
||||
@api.onchange('start_time', 'end_time')
|
||||
def _onchange_start_end_time(self):
|
||||
if self.start_time > 0 and self.end_time > 0:
|
||||
res = self.end_time - self.start_time
|
||||
if res <= 0:
|
||||
raise ValidationError(_("End time cannot be earlier than Start time"))
|
||||
self.unit_amount = res
|
||||
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
if vals.get('unit_amount') == 0.0:
|
||||
|
|
|
@ -6,14 +6,14 @@ class ProjectMainenenceType(models.Model):
|
|||
_name = 'project.maintenance.type'
|
||||
_description = "project Maintenance Type"
|
||||
|
||||
name = fields.Char('Maintenance Type', required=True, ondelete="restrict")
|
||||
name = fields.Char('Maintenance Type', required=True)
|
||||
maintenance_ids = fields.One2many('project.maintenance', 'maintenance_type_id', string='Maintenance', copy=False)
|
||||
|
||||
class ProjectMainenence(models.Model):
|
||||
_name = 'project.maintenance'
|
||||
_description = "project Maintenance"
|
||||
|
||||
name = fields.Char('Maintenance', required=True, ondelete="restrict")
|
||||
name = fields.Char('Maintenance', required=True)
|
||||
maintenance_type_id = fields.Many2one('project.maintenance.type', 'Manintenance Type', required=True, readonly=True, ondelete='cascade')
|
||||
|
||||
|
||||
|
|
|
@ -23,9 +23,9 @@ class ProjectMainenenceDetails(models.Model):
|
|||
val.total_amount = total_cost
|
||||
|
||||
project_id = fields.Many2one('project.project', 'Project', required=True, ondelete='cascade')
|
||||
maintenance_type_id = fields.Many2one('project.maintenance.type', 'Maintenance Type', required=True)
|
||||
maintenance_type_id = fields.Many2one('project.maintenance.type', 'Maintenance Type', required=True, ondelete="restrict")
|
||||
currency_id = fields.Many2one('res.currency', string='Currency', readonly=True, default=lambda self: self.env.company.currency_id)
|
||||
total_amount = fields.Float("Total Amount", digits=(16, 2), compute='_compute_amount', store=True, currency_field='currency_id')
|
||||
total_amount = fields.Monetary("Total Amount", compute='_compute_amount', store=True, currency_field='currency_id')
|
||||
line_ids = fields.One2many('project.maintenance.lines', 'details_id', string='Maintenance Details', copy=False)
|
||||
|
||||
class ProjectMainenencelines(models.Model):
|
||||
|
@ -33,6 +33,6 @@ class ProjectMainenencelines(models.Model):
|
|||
_description = "project Maintenance Lines"
|
||||
|
||||
details_id = fields.Many2one('project.maintenance.details', 'Details', required=True, ondelete='cascade')
|
||||
maintenance_id = fields.Many2one('project.maintenance', 'Maintenance', required=True)
|
||||
maintenance_id = fields.Many2one('project.maintenance', 'Maintenance', required=True, ondelete="restrict")
|
||||
currency_id = fields.Many2one('res.currency', string='Currency', readonly=True, default=lambda self: self.env.company.currency_id)
|
||||
cost = fields.Float("Cost", digits=(16, 2), currency_field='currency_id')
|
||||
cost = fields.Monetary("Cost", currency_field='currency_id')
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import project
|
||||
|
||||
from . import sale
|
||||
|
|
|
@ -6,7 +6,7 @@ from odoo import api, fields, models, _
|
|||
class Project(models.Model):
|
||||
_inherit = 'project.project'
|
||||
|
||||
budgeted_hours = fields.Float(string='Budgeted Hours')
|
||||
budgeted_revenue = fields.Float(string='Budgeted Revenue')
|
||||
budgeted_hours = fields.Float(string='Budgeted Hours', digits=(16, 2))
|
||||
budgeted_revenue = fields.Float(string='Budgeted Revenue', digits=(16, 2))
|
||||
|
||||
|
||||
|
|
|
@ -10,10 +10,13 @@ class SaleOrderLine(models.Model):
|
|||
"""Generate project values"""
|
||||
values = super()._timesheet_create_project_prepare_values()
|
||||
name = False
|
||||
project_mangager_id = False
|
||||
if self.order_id.opportunity_id:
|
||||
budgeted_hours = 0
|
||||
budgeted_revenue = 0
|
||||
project_manager_id = False
|
||||
if self.order_id and self.order_id.opportunity_id:
|
||||
name = self.order_id.opportunity_id.project_name
|
||||
project_mangager_id = self.order_id.opportunity_id.project_manager_id.id if self.order_id.opportunity_id.project_manager_id else False
|
||||
project_manager_id = self.order_id.opportunity_id.project_manager_id.id if self.order_id.opportunity_id.project_manager_id else False
|
||||
budgeted_revenue = self.order_id.opportunity_id.expected_revenue
|
||||
elif self.order_id.client_order_ref:
|
||||
name = self.order_id.client_order_ref
|
||||
if name:
|
||||
|
@ -21,8 +24,13 @@ class SaleOrderLine(models.Model):
|
|||
else:
|
||||
name = self.order_id.name
|
||||
values['name'] = name
|
||||
if project_mangager_id:
|
||||
values['user_id'] = project_mangager_id
|
||||
if project_manager_id:
|
||||
values['user_id'] = project_manager_id
|
||||
if self.order_id:
|
||||
for line in self.order_id.order_line.filtered(lambda line: line.product_id.type == 'service'):
|
||||
budgeted_hours += line.product_uom_qty
|
||||
values['budgeted_hours'] = budgeted_hours
|
||||
values['budgeted_revenue'] = budgeted_revenue
|
||||
values['allow_billable'] = True
|
||||
values['bill_type'] = 'customer_project'
|
||||
values['pricing_type'] = 'fixed_rate'
|
|
@ -27,16 +27,16 @@ class BudgetAmtAnalysis(models.Model):
|
|||
PRO.id AS project_id,
|
||||
PRO.partner_id AS partner_id,
|
||||
AAL.employee_id AS employee_id,
|
||||
--PRO.budgeted_hours AS budgeted_revenue,
|
||||
PRO.budgeted_revenue AS budgeted_revenue,
|
||||
SO.amount_total AS actual_revenue
|
||||
--sum(AAL.amount) AS budgeted_revenue
|
||||
SO.amount_total AS budgeted_revenue,
|
||||
sum(-1 * AAL.amount) AS actual_revenue
|
||||
--sum(-1 * AAL.amount) AS actual_revenue
|
||||
FROM project_project PRO
|
||||
LEFT JOIN sale_order SO ON PRO.sale_order_id = SO.id
|
||||
LEFT JOIN account_analytic_account AA ON PRO.analytic_account_id = AA.id
|
||||
LEFT JOIN account_analytic_line AAL ON AAL.account_id = AA.id
|
||||
WHERE AAL.amount < 0.0 AND AAL.project_id IS NOT NULL AND PRO.active = 't' AND PRO.allow_timesheets = 't'
|
||||
group by Pro.id, PRO.partner_id, AAL.employee_id, Pro.budgeted_hours, AAL.unit_amount, so.amount_total
|
||||
group by Pro.id, PRO.partner_id, AAL.employee_id, Pro.budgeted_revenue, so.amount_total
|
||||
)""" % (self._table,))
|
||||
|
||||
|
||||
|
|
|
@ -27,16 +27,16 @@ class BudgetHrsAnalysis(models.Model):
|
|||
PRO.id AS project_id,
|
||||
PRO.partner_id AS partner_id,
|
||||
AAL.employee_id AS employee_id,
|
||||
sum(SOL.product_uom_qty) As budgeted_hours,
|
||||
--PRO.budgeted_hours AS budgeted_hours,
|
||||
--sum(SOL.product_uom_qty) As budgeted_hours,
|
||||
PRO.budgeted_hours AS budgeted_hours,
|
||||
sum(AAL.unit_amount) AS actual_hours
|
||||
FROM project_project PRO
|
||||
LEFT JOIN sale_order_line SOL ON PRO.sale_line_id = SOL.id
|
||||
LEFT JOIN sale_order SO ON PRO.sale_order_id = SO.id
|
||||
--LEFT JOIN sale_order_line SOL ON PRO.sale_line_id = SOL.id
|
||||
--LEFT JOIN sale_order SO ON PRO.sale_order_id = SO.id
|
||||
LEFT JOIN account_analytic_account AA ON PRO.analytic_account_id = AA.id
|
||||
LEFT JOIN account_analytic_line AAL ON AAL.account_id = AA.id
|
||||
WHERE AAL.amount < 0.0 AND AAL.project_id IS NOT NULL AND PRO.active = 't' AND PRO.allow_timesheets = 't'
|
||||
group by Pro.id, PRO.partner_id, AAL.employee_id, AAL.unit_amount,SOL.product_uom_qty
|
||||
group by Pro.id, PRO.partner_id, AAL.employee_id, AAL.unit_amount,PRO.budgeted_hours
|
||||
)""" % (self._table,))
|
||||
|
||||
|
||||
|
|
|
@ -12,10 +12,10 @@
|
|||
attrs="{'invisible': [('allow_billable','=',False)]}" string="Create Expense" widget="statinfo">
|
||||
</button>
|
||||
</div>
|
||||
<!-- <xpath expr="//field[@name='analytic_account_id']" position="after">
|
||||
<xpath expr="//field[@name='analytic_account_id']" position="after">
|
||||
<field name="budgeted_hours"/>
|
||||
<field name="budgeted_revenue"/>
|
||||
</xpath> -->
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
|
Loading…
Reference in New Issue