From 17385c0c3f1bc70a5716d0fb6ddb08cdb2513a2f Mon Sep 17 00:00:00 2001 From: AjmalCybro Date: Mon, 31 Jul 2023 18:20:22 +0530 Subject: [PATCH] Jul 31 [FIX] : Bug Fixed 'readonly_unit_price_cybrosys' --- .../doc/RELEASE_NOTES.md | 2 +- .../models/__init__.py | 1 - .../models/account_move.py | 20 +++++++++---------- .../models/res_users.py | 17 ++++++++-------- .../models/sale_order.py | 20 +++++++++---------- 5 files changed, 29 insertions(+), 31 deletions(-) diff --git a/readonly_unit_price_cybrosys/doc/RELEASE_NOTES.md b/readonly_unit_price_cybrosys/doc/RELEASE_NOTES.md index dd914e0ea..d7fff3b31 100644 --- a/readonly_unit_price_cybrosys/doc/RELEASE_NOTES.md +++ b/readonly_unit_price_cybrosys/doc/RELEASE_NOTES.md @@ -1,6 +1,6 @@ ## Module -#### 6.1.2023 +#### 31.07.2023 #### Version 16.0.1.0.0 #### ADD Initial Commit for Price Unit Readonly for Sale and Invoice. diff --git a/readonly_unit_price_cybrosys/models/__init__.py b/readonly_unit_price_cybrosys/models/__init__.py index 25f87bec6..53aa60382 100644 --- a/readonly_unit_price_cybrosys/models/__init__.py +++ b/readonly_unit_price_cybrosys/models/__init__.py @@ -19,7 +19,6 @@ # If not, see . # ############################################################################# - from . import res_users from . import sale_order from . import account_move diff --git a/readonly_unit_price_cybrosys/models/account_move.py b/readonly_unit_price_cybrosys/models/account_move.py index 15782adfa..ca918dbe7 100644 --- a/readonly_unit_price_cybrosys/models/account_move.py +++ b/readonly_unit_price_cybrosys/models/account_move.py @@ -20,22 +20,22 @@ # ############################################################################# -from odoo import api, fields, models, _ +from odoo import fields, models class AccountMoveLine(models.Model): _inherit = 'account.move.line' - price_unit_boolean = fields.Boolean(default=False, - compute='_compute_price_unit_boolean') + price_unit_boolean = fields.Boolean( + string="price unit boolean", + help="This field used to readonly for price unite", + default=lambda self: self.env.user.readonly_unit_price_invoicing, + compute='_compute_price_unit_boolean') def _compute_price_unit_boolean(self): """ Compute function for price_unit_boolean. - This function will check the boolean field of the currently logged user is true or false. - And it will pass the value to price_unit_boolean.""" + This function will check the boolean field of the currently + logged user is true or false. + And it will pass the value to price_unit_boolean.""" for rec in self: - u_id = self.env['res.users'].search([('id', '=', self._uid)]) - if u_id.readonly_unit_price_invoicing == False: - rec.price_unit_boolean = False - else: - rec.price_unit_boolean = True + rec.price_unit_boolean = self.env.user.readonly_unit_price_invoicing diff --git a/readonly_unit_price_cybrosys/models/res_users.py b/readonly_unit_price_cybrosys/models/res_users.py index 9d9354f28..099aa7d83 100644 --- a/readonly_unit_price_cybrosys/models/res_users.py +++ b/readonly_unit_price_cybrosys/models/res_users.py @@ -20,23 +20,22 @@ # ############################################################################# -from odoo import api, fields, models, _ +from odoo import fields, models, _ class ResUsers(models.Model): _inherit = 'res.users' - readonly_unit_price_sales = fields.Boolean('Readonly Unit Price for Sales', - help='If enabled, the Unit Price in the Sale Order Line will be readonly for this user.') + readonly_unit_price_sales = fields.Boolean( + string='Readonly Unit Price for Sales', + help="This field used to enable readonly or not for sales ") readonly_unit_price_invoicing = fields.Boolean( 'Readonly Unit Price for Invoice', - help='If enabled, the Unit Price in the Invoice Lines will be readonly for this user.') + help='If enabled, the Unit Price in the Invoice Lines will be readonly ' + 'for this user.') is_admin_boolean = fields.Boolean(compute='_compute_is_admin_boolean') def _compute_is_admin_boolean(self): """ checks if the currently logged user is admin or not""" - u_id = self.search([('id','=',self._uid)]) - if u_id._is_admin() == True: - self.is_admin_boolean = True - else: - self.is_admin_boolean = False + for rec in self: + rec.is_admin_boolean = rec.env.user._is_admin() diff --git a/readonly_unit_price_cybrosys/models/sale_order.py b/readonly_unit_price_cybrosys/models/sale_order.py index 31dc11365..9c4172ce2 100644 --- a/readonly_unit_price_cybrosys/models/sale_order.py +++ b/readonly_unit_price_cybrosys/models/sale_order.py @@ -20,22 +20,22 @@ # ############################################################################# -from odoo import api, fields, models, _ +from odoo import fields, models, _ class SaleOrderLine(models.Model): _inherit = 'sale.order.line' - price_unit_boolean = fields.Boolean(default=False, - compute='_compute_price_unit_boolean') + price_unit_boolean = fields.Boolean( + string='Price unite boolean', + help="This field check whether readonly for user on not ", + default=lambda self: self.env.user.readonly_unit_price_sales, + compute='_compute_price_unit_boolean') def _compute_price_unit_boolean(self): """ Compute function for price_unit_boolean. - This function will check the boolean field of the currently logged user is true or false. - And it will pass the value to price_unit_boolean.""" + This function will check the boolean field of the currently + logged user is true or false. + And it will pass the value to price_unit_boolean.""" for rec in self: - u_id = self.env['res.users'].search([('id', '=', self._uid)]) - if u_id.readonly_unit_price_sales == False: - rec.price_unit_boolean = False - else: - rec.price_unit_boolean = True + rec.price_unit_boolean = self.env.user.readonly_unit_price_sales