diff --git a/ssi_stock/__manifest__.py b/ssi_stock/__manifest__.py index 8b67844..4d34f4c 100644 --- a/ssi_stock/__manifest__.py +++ b/ssi_stock/__manifest__.py @@ -17,6 +17,7 @@ "stock_inventory_preparation_filter", "stock_move_line_auto_fill", "ssi_print_mixin", + "ssi_policy_mixin", ], "data": [ "security/ir_module_category_data.xml", @@ -24,6 +25,7 @@ "security/ir.model.access.csv", "data/location_type_data.xml", "data/stock_picking_type_category_data.xml", + "data/policy_template_data.xml", "menu.xml", "templates/picking_type_m2_configurator_templates.xml", "templates/picking_type_category_m2_configurator_templates.xml", diff --git a/ssi_stock/data/policy_template_data.xml b/ssi_stock/data/policy_template_data.xml new file mode 100644 index 0000000..6c81fca --- /dev/null +++ b/ssi_stock/data/policy_template_data.xml @@ -0,0 +1,266 @@ + + + + + + Standard + + + + result=True + + + + + + + + + + result = False +allowed_user = False +if env.user.id == document.picking_type_id.warehouse_id.manager_id.id: + allowed_user = True +elif env.user.id in document.picking_type_id.warehouse_id.supervisor_ids.ids: + allowed_user = True +elif env.user.id in document.picking_type_id.warehouse_id.user_ids.ids: + allowed_user = True + +if document.show_mark_as_todo and allowed_user: + result = True + + + + + + + + + + + result = False +allowed_user = False +if env.user.id == document.picking_type_id.warehouse_id.manager_id.id: + allowed_user = True +elif env.user.id in document.picking_type_id.warehouse_id.supervisor_ids.ids: + allowed_user = True +elif env.user.id in document.picking_type_id.warehouse_id.user_ids.ids: + allowed_user = True + +if document.show_check_availability and allowed_user: + result = True + + + + + + + + + + + result = False +allowed_user = False +if env.user.id == document.picking_type_id.warehouse_id.manager_id.id: + allowed_user = True +elif env.user.id in document.picking_type_id.warehouse_id.supervisor_ids.ids: + allowed_user = True + +if document.show_validate and allowed_user: + result = True + + + + + + + + + + + result = False +allowed_user = False +if env.user.id == document.picking_type_id.warehouse_id.manager_id.id: + allowed_user = True +elif env.user.id in document.picking_type_id.warehouse_id.supervisor_ids.ids: + allowed_user = True + +if document.picking_type_code != 'incoming' and allowed_user: + result = True +elif not document.immediate_transfer and allowed_user: + result = True +elif document.state in ['assigned', 'partially_available'] and allowed_user and document.move_type != 'one': + result = True +elif document.state == 'assigned' and allowed_user and document.move_type == 'one': + result = True + + + + + + + + + + + result = False +allowed_user = False +if env.user.id == document.picking_type_id.warehouse_id.manager_id.id: + allowed_user = True +elif env.user.id in document.picking_type_id.warehouse_id.supervisor_ids.ids: + allowed_user = True + +if document.state == 'done' and allowed_user: + result = True + + + + + + + + + + + + + + + + + + + use_group + + result = False +allowed_user = False +if env.user.id == document.picking_type_id.warehouse_id.manager_id.id: + allowed_user = True +elif env.user.id in document.picking_type_id.warehouse_id.supervisor_ids.ids: + allowed_user = True + +if document.state != 'cancel' and allowed_user: + result = True + + + + + + + + + + + result = False +allowed_user = False +if env.user.id == document.picking_type_id.warehouse_id.manager_id.id: + allowed_user = True +elif env.user.id in document.picking_type_id.warehouse_id.supervisor_ids.ids: + allowed_user = True + +if document.state == 'cancel' and allowed_user: + result = True + + + + diff --git a/ssi_stock/models/stock_picking.py b/ssi_stock/models/stock_picking.py index b6a302d..2ec3b53 100644 --- a/ssi_stock/models/stock_picking.py +++ b/ssi_stock/models/stock_picking.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import fields, models +from odoo import api, fields, models class StockPicking(models.Model): @@ -11,6 +11,7 @@ class StockPicking(models.Model): _inherit = [ "stock.picking", "mixin.print_document", + "mixin.policy", ] _automatically_insert_print_button = True @@ -53,6 +54,60 @@ class StockPicking(models.Model): related="picking_type_id.allowed_product_ids", store=False, ) + mark_as_todo_ok = fields.Boolean( + string="Can Mark As To Do", + compute="_compute_policy", + compute_sudo=True, + ) + check_availability_ok = fields.Boolean( + string="Can Check Availability", + compute="_compute_policy", + compute_sudo=True, + ) + unreserved_ok = fields.Boolean( + string="Can Unreserved", + compute="_compute_policy", + compute_sudo=True, + ) + return_ok = fields.Boolean( + string="Can Return", + compute="_compute_policy", + compute_sudo=True, + ) + validate_ok = fields.Boolean( + string="Can Validate", + compute="_compute_policy", + compute_sudo=True, + ) + cancel_ok = fields.Boolean( + string="Can Cancel", + compute="_compute_policy", + compute_sudo=True, + ) + restart_ok = fields.Boolean( + string="Can Restart", + compute="_compute_policy", + compute_sudo=True, + ) + + def _compute_policy(self): + _super = super(StockPicking, self) + _super._compute_policy() + + @api.model + def _get_policy_field(self): + res = super(StockPicking, self)._get_policy_field() + policy_field = [ + "mark_as_todo_ok", + "check_availability_ok", + "unreserved_ok", + "cancel_ok", + "restart_ok", + "validate_ok", + "return_ok", + ] + res += policy_field + return res def _assign_auto_lot_number(self): for record in self: diff --git a/ssi_stock/views/stock_picking_views.xml b/ssi_stock/views/stock_picking_views.xml index ac0e200..1e2e84c 100644 --- a/ssi_stock/views/stock_picking_views.xml +++ b/ssi_stock/views/stock_picking_views.xml @@ -49,6 +49,44 @@ extension + + {'invisible':[('mark_as_todo_ok','=',False)]} + + + + {'invisible':[('check_availability_ok','=',False)]} + + + + {'invisible':[('check_availability_ok','=',False)]} + + + + {'invisible':[('unreserved_ok','=',False)]} + + + + {'invisible':[('cancel_ok','=',False)]} + + + + + 0 + {'invisible':[('validate_ok','=',False)]} + + {} + + 1 + {} + + {} - - {'invisible': [('state', 'not in', ('draft', 'waiting', 'confirmed', 'assigned', 'done'))]} -