[FIX] sale_timesheet: fix domain of project on product
Currently, create a service product and select a project or a project template from the 'sales' tab, it is not possible to select projects with allow_timesheets = false So in this commit, the domain of the project_id and the project_template_id fields should include projects for which allow_timesheets is false except if the 'Timesheets on tasks' option is selected as a service_policy Also if onchage of service_policy, the project field will be empty. TaskID-2522084 closes odoo/odoo#71099 X-original-commit: 0769a148f731188f53f1b2b3af881d88e40feb35 Signed-off-by: LTU-Odoo <IT-Ideas@users.noreply.github.com>
This commit is contained in:
@@ -19,8 +19,8 @@ class ProductTemplate(models.Model):
|
||||
('timesheet', 'Timesheets on project (one fare per SO/Project)'),
|
||||
], ondelete={'timesheet': 'set default'})
|
||||
# override domain
|
||||
project_id = fields.Many2one(domain="[('company_id', '=', current_company_id), ('allow_billable', '=', True), ('pricing_type', '=', 'task_rate'), ('allow_timesheets', 'in', [service_policy == 'delivered_timesheet' or '', True])]")
|
||||
project_template_id = fields.Many2one(domain="[('company_id', '=', current_company_id), ('allow_billable', '=', True), ('pricing_type', '!=', 'task_rate'), ('allow_timesheets', 'in', [service_policy == 'delivered_timesheet' or '', True])]")
|
||||
project_id = fields.Many2one(domain="[('company_id', '=', current_company_id), ('allow_billable', '=', True), ('pricing_type', '=', 'task_rate'), ('allow_timesheets', 'in', [service_policy == 'delivered_timesheet', True])]")
|
||||
project_template_id = fields.Many2one(domain="[('company_id', '=', current_company_id), ('allow_billable', '=', True), ('pricing_type', '!=', 'task_rate'), ('allow_timesheets', 'in', [service_policy == 'delivered_timesheet', True])]")
|
||||
service_upsell_warning = fields.Boolean('Upsell Warning', help="The salesperson in charge will be assigned an activity informing him of an upselling opportunity once the selected threshold is reached.")
|
||||
service_upsell_threshold = fields.Float('Threshold', help="Percentage of time delivered compared to the prepaid amount that must be reached for the upselling opportunity activity to be triggered.")
|
||||
|
||||
@@ -70,6 +70,25 @@ class ProductTemplate(models.Model):
|
||||
self.invoice_policy = 'order'
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def _get_onchange_service_policy_updates(self, service_tracking, service_policy, project_id, project_template_id):
|
||||
vals = {}
|
||||
if service_tracking != 'no' and service_policy == 'delivered_timesheet':
|
||||
if project_id and not project_id.allow_timesheets:
|
||||
vals['project_id'] = False
|
||||
elif project_template_id and not project_template_id.allow_timesheets:
|
||||
vals['project_template_id'] = False
|
||||
return vals
|
||||
|
||||
@api.onchange('service_policy')
|
||||
def _onchange_service_policy(self):
|
||||
vals = self._get_onchange_service_policy_updates(self.service_tracking,
|
||||
self.service_policy,
|
||||
self.project_id,
|
||||
self.project_template_id)
|
||||
if vals:
|
||||
self.update(vals)
|
||||
|
||||
@api.ondelete(at_uninstall=False)
|
||||
def _unlink_except_master_data(self):
|
||||
time_product = self.env.ref('sale_timesheet.time_product')
|
||||
@@ -94,6 +113,15 @@ class ProductProduct(models.Model):
|
||||
self.ensure_one()
|
||||
return self.type == 'service' and self.service_policy == 'delivered_timesheet'
|
||||
|
||||
@api.onchange('service_policy')
|
||||
def _onchange_service_policy(self):
|
||||
vals = self.product_tmpl_id._get_onchange_service_policy_updates(self.service_tracking,
|
||||
self.service_policy,
|
||||
self.project_id,
|
||||
self.project_template_id)
|
||||
if vals:
|
||||
self.update(vals)
|
||||
|
||||
@api.ondelete(at_uninstall=False)
|
||||
def _unlink_except_master_data(self):
|
||||
time_product = self.env.ref('sale_timesheet.time_product')
|
||||
|
||||
Reference in New Issue
Block a user