From 12ddb8041773ddefcc67d4da741d97d0ae571d8e Mon Sep 17 00:00:00 2001 From: "pawan.sharma" Date: Tue, 23 Aug 2022 13:17:27 +0530 Subject: [PATCH] add edit feature --- .../models/custom_project.py | 33 ++++++++++++++++++- .../security/ir.model.access.csv | 4 +-- .../views/custom_project.xml | 25 ++++++++++++++ .../wizard/project_revenue_wizard.xml | 9 ++--- 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/project_revenue_amount/models/custom_project.py b/project_revenue_amount/models/custom_project.py index be8e21c..f1e9b48 100755 --- a/project_revenue_amount/models/custom_project.py +++ b/project_revenue_amount/models/custom_project.py @@ -9,6 +9,7 @@ class CustomProject(models.Model): revenue_amount_lines = fields.One2many('project.revenue.lines' , 'project_id') + class ProjectRevenueLines(models.Model): _name = 'project.revenue.lines' @@ -17,7 +18,37 @@ class ProjectRevenueLines(models.Model): end_date = fields.Date(required=True) fixed_amount = fields.Float() - + def edit_revenue_history_record(self): + context = dict(self.env.context) + context['form_view_initial_mode'] = 'edit' + return { + 'name': ('Edit Revenue History'), + 'type': 'ir.actions.act_window', + 'view_type': 'form', + 'view_mode': 'form', + 'target': 'new', + 'res_model': 'project.revenue.lines', + 'res_id': self.id, + 'context': context, + # 'view_id': view_id + } + + @api.onchange('start_date') + def _onchange_start_date(self): + if self.project_id: + records = self.env['project.revenue.lines'].sudo().search([('project_id', '=', self.project_id.id)]) + if self.start_date: + if self.start_date.day != 1: + raise AccessError('Please select first date of month') + else: + pass + for line in records: + if self.start_date >= line.start_date and self.start_date <= line.end_date: + raise AccessError('Date already exist') + + def update_record(self): + return { + 'type': 'ir.actions.act_window_close'} diff --git a/project_revenue_amount/security/ir.model.access.csv b/project_revenue_amount/security/ir.model.access.csv index d3f1176..ccb2421 100755 --- a/project_revenue_amount/security/ir.model.access.csv +++ b/project_revenue_amount/security/ir.model.access.csv @@ -1,3 +1,3 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_project_revenue_lines,access.project.revenue.lines,model_project_revenue_lines,,1,1,1,0 -access_project_revenue_wizard,access.project.revenue.wizard,model_project_revenue_wizard,,1,1,1,0 +access_project_revenue_lines,access.project.revenue.lines,model_project_revenue_lines,project.group_project_manager,1,1,1,1 +access_project_revenue_wizard,access.project.revenue.wizard,model_project_revenue_wizard,project.group_project_manager,1,1,1,1 diff --git a/project_revenue_amount/views/custom_project.xml b/project_revenue_amount/views/custom_project.xml index 008a1d2..0334e5f 100755 --- a/project_revenue_amount/views/custom_project.xml +++ b/project_revenue_amount/views/custom_project.xml @@ -13,6 +13,10 @@ +