Skip to content

Commit

Permalink
Merge PR #47 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by andhit-r
  • Loading branch information
ssi-bot committed Jun 20, 2024
2 parents 6229eaf + e1e9ce4 commit 6090344
Show file tree
Hide file tree
Showing 4 changed files with 396 additions and 7 deletions.
2 changes: 2 additions & 0 deletions ssi_stock/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
"stock_inventory_preparation_filter",
"stock_move_line_auto_fill",
"ssi_print_mixin",
"ssi_policy_mixin",
],
"data": [
"security/ir_module_category_data.xml",
"security/res_group_data.xml",
"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",
Expand Down
266 changes: 266 additions & 0 deletions ssi_stock/data/policy_template_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2024 OpenSynergy Indonesia
Copyright 2024 PT. Simetri Sinergi Indonesia
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<data>
<record id="stock_picking_policy_template" model="policy.template">
<field name="name">Standard</field>
<field name="model_id" ref="model_stock_picking" />
<field
name="state_field_id"
search="[('model_id.model','=','stock.picking'),('name','=','state')]"
/>
<field name="sequence" eval="100" />
<field name="python_code">result=True</field>
</record>

<!-- Mark as Todo -->
<record
id="stock_picking_policy_template_detail_mark_as_to_do"
model="policy.template_detail"
>
<field name="template_id" ref="stock_picking_policy_template" />
<field
name="field_id"
search="[('model_id.model','=','stock.picking'),('name','=','mark_as_todo_ok')]"
/>
<field name="restrict_state" eval="0" />
<field name="restrict_user" eval="0" />
<field name="restrict_additional" eval="1" />
<field name="additional_python_code">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
</field>
</record>

<!-- Check Availability -->
<record
id="stock_picking_policy_template_detail_check_availability"
model="policy.template_detail"
>
<field name="template_id" ref="stock_picking_policy_template" />
<field
name="field_id"
search="[('model_id.model','=','stock.picking'),('name','=','check_availability_ok')]"
/>
<field name="restrict_state" eval="0" />
<field name="restrict_user" eval="0" />
<field name="restrict_additional" eval="1" />
<field name="additional_python_code">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
</field>
</record>

<!-- Validate -->
<record
id="stock_picking_policy_template_detail_check_validate"
model="policy.template_detail"
>
<field name="template_id" ref="stock_picking_policy_template" />
<field
name="field_id"
search="[('model_id.model','=','stock.picking'),('name','=','validate_ok')]"
/>
<field name="restrict_state" eval="0" />
<field name="restrict_user" eval="0" />
<field name="restrict_additional" eval="1" />
<field name="additional_python_code">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
</field>
</record>

<!-- Unreserve -->
<record
id="stock_picking_policy_template_detail_unreserve"
model="policy.template_detail"
>
<field name="template_id" ref="stock_picking_policy_template" />
<field
name="field_id"
search="[('model_id.model','=','stock.picking'),('name','=','unreserved_ok')]"
/>
<field name="restrict_state" eval="0" />
<field name="restrict_user" eval="0" />
<field name="restrict_additional" eval="1" />
<field name="additional_python_code">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
</field>
</record>

<!-- Return -->
<record id="stock_picking_policy_template_detail_return" model="policy.template_detail">
<field name="template_id" ref="stock_picking_policy_template" />
<field
name="field_id"
search="[('model_id.model','=','stock.picking'),('name','=','return_ok')]"
/>
<field name="restrict_state" eval="0" />
<field name="restrict_user" eval="0" />
<field name="restrict_additional" eval="1" />
<field name="additional_python_code">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
</field>
</record>

<!-- approve -->
<!-- <record
id="stock_picking_policy_template_detail_approve"
model="policy.template_detail"
>
<field name="template_id" ref="stock_picking_policy_template" />
<field
name="field_id"
search="[('model_id.model','=','stock_picking'),('name','=','approve_ok')]"
/>
<field name="restrict_state" eval="1" />
<field
name="state_ids"
search="[('field_id.model_id.model','=','stock_picking'),('value','=','confirm')]"
/>
<field name="restrict_user" eval="0" />
<field name="restrict_additional" eval="1" />
<field name="additional_python_code">result = False
if env.user.id in document.active_approver_user_ids.ids:
result = True
</field>
</record> -->

<!-- reject -->
<!-- <record id="stock_picking_policy_template_detail_reject" model="policy.template_detail">
<field name="template_id" ref="stock_picking_policy_template" />
<field
name="field_id"
search="[('model_id.model','=','stock_picking'),('name','=','reject_ok')]"
/>
<field name="restrict_state" eval="1" />
<field
name="state_ids"
search="[('field_id.model_id.model','=','stock_picking'),('value','=','confirm')]"
/>
<field name="restrict_user" eval="0" />
<field name="restrict_additional" eval="1" />
<field name="additional_python_code">result = False
if env.user.id in document.active_approver_user_ids.ids:
result = True
</field>
</record> -->

<!-- restart approval -->
<!-- <record
id="stock_picking_policy_template_detail_restart_approval"
model="policy.template_detail"
>
<field name="template_id" ref="stock_picking_policy_template" />
<field
name="field_id"
search="[('model_id.model','=','stock_picking'),('name','=','restart_approval_ok')]"
/>
<field name="restrict_state" eval="1" />
<field
name="state_ids"
search="[('field_id.model_id.model','=','stock_picking'),('value','=','confirm')]"
/>
<field name="restrict_user" eval="1" />
<field name="computation_method">use_group</field>
<field name="group_ids" eval="[(6,0,[ref('stock_picking_validator_group')])]" />
<field name="restrict_additional" eval="1" />
<field name="additional_python_code">result = False
if not document.approval_template_id:
result = True
</field>
</record> -->

<!-- cancel -->
<record id="stock_picking_policy_template_detail_cancel" model="policy.template_detail">
<field name="template_id" ref="stock_picking_policy_template" />
<field
name="field_id"
search="[('model_id.model','=','stock.picking'),('name','=','cancel_ok')]"
/>
<field name="restrict_state" eval="0" />
<field name="restrict_user" eval="0" />
<field name="computation_method">use_group</field>
<field name="restrict_additional" eval="1" />
<field name="additional_python_code">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
</field>
</record>

<!-- restart -->
<record
id="stock_picking_policy_template_detail_restart"
model="policy.template_detail"
>
<field name="template_id" ref="stock_picking_policy_template" />
<field
name="field_id"
search="[('model_id.model','=','stock.picking'),('name','=','restart_ok')]"
/>
<field name="restrict_state" eval="0" />
<field name="restrict_user" eval="0" />
<field name="restrict_additional" eval="1" />
<field name="additional_python_code">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
</field>
</record>
</data>
</odoo>
57 changes: 56 additions & 1 deletion ssi_stock/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
# 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):
_name = "stock.picking"
_inherit = [
"stock.picking",
"mixin.print_document",
"mixin.policy",
]
_automatically_insert_print_button = True

Expand Down Expand Up @@ -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:
Expand Down
Loading

0 comments on commit 6090344

Please sign in to comment.