Skip to content

Commit

Permalink
[REF] product_print_category : do not creeate 'user' print Category G…
Browse files Browse the repository at this point in the history
…roup, because it make the default computation failing on the product.product form view if user is not member of the group. Also to align with the rest of odoo : print_category_id is a regular field that can be user by any user that is member of base.group_user as all the other field

[FIX] use _for_xml_id to avoid error if user is not admin, when using the print wizard
[REF] use expression.AND to simplify code
  • Loading branch information
legalsylvain committed Nov 6, 2023
1 parent fb9fe5e commit a7df4f6
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 42 deletions.
1 change: 0 additions & 1 deletion product_print_category/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"demo/product_product.xml",
],
"data": [
"security/ir_module_category.xml",
"security/res_groups.xml",
"security/ir_rule.xml",
"security/ir.model.access.csv",
Expand Down
17 changes: 8 additions & 9 deletions product_print_category/models/product_print_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models
from odoo.osv import expression


class ProductPrintCategory(models.Model):
Expand Down Expand Up @@ -79,14 +80,12 @@ def _compute_to_print(self):
# Action Section
def action_view_product_product(self):
self.ensure_one()
action = self.env.ref("product.product_normal_action")
action_data = action.read()[0]
action = self.env["ir.actions.actions"]._for_xml_id(
"product.product_normal_action"
)
action["domain"] = [("print_category_id", "=", self.id)]
if self.env.context.get("to_print"):
action_data["domain"] = (
"['&', ('print_category_id','=', "
+ str(self.id)
+ "), ('to_print','=', True)]"
action["domain"] = expression.AND(
[action["domain"], [("to_print", "=", True)]]
)
else:
action_data["domain"] = "[('print_category_id','=', " + str(self.id) + ")]"
return action_data
return action
6 changes: 3 additions & 3 deletions product_print_category/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
ir_model_access_product_print_category_user,Print Category User,product_print_category.model_product_print_category,product_print_category.user,1,0,0,0
ir_model_access_product_print_category_user,Print Category User,product_print_category.model_product_print_category,base.group_user,1,0,0,0
ir_model_access_product_print_category_manager,Print Category Manager,product_print_category.model_product_print_category,product_print_category.manager,1,1,1,1
product_print_category.access_product_print_wizard,access_product_print_wizard,product_print_category.model_product_print_wizard,product_print_category.user,1,1,1,1
product_print_category.access_product_print_wizard_line,access_product_print_wizard_line,product_print_category.model_product_print_wizard_line,product_print_category.user,1,1,1,1
product_print_category.access_product_print_wizard,access_product_print_wizard,product_print_category.model_product_print_wizard,base.group_user,1,1,1,1
product_print_category.access_product_print_wizard_line,access_product_print_wizard_line,product_print_category.model_product_print_wizard_line,base.group_user,1,1,1,1
ir_model_access_product_print_category_rule_user,Print Category Rule User,product_print_category.model_product_print_category_rule,,1,0,0,0
ir_model_access_product_print_category_rule_manager,Print Category Rule Manager,product_print_category.model_product_print_category_rule,product_print_category.manager,1,1,1,1
15 changes: 0 additions & 15 deletions product_print_category/security/ir_module_category.xml

This file was deleted.

8 changes: 1 addition & 7 deletions product_print_category/security/res_groups.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>

<record id="user" model="res.groups">
<field name="name">Print Category User</field>
<field name="category_id" ref="module_product_print_category" />
</record>

<record id="manager" model="res.groups">
<field name="name">Print Category Manager</field>
<field name="implied_ids" eval="[(4, ref('user'))]" />
<field name="category_id" ref="module_product_print_category" />
<field name="category_id" ref="base.module_category_hidden" />
</record>

</odoo>
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
parent="sale.product_menu_catalog"
sequence="110"
action="action_product_print_category"
groups="product_print_category.user"
/>

</odoo>
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
parent="sale.product_menu_catalog"
sequence="115"
action="action_product_print_category_rule"
groups="product_print_category.user"
/>

</odoo>
4 changes: 2 additions & 2 deletions product_print_category/views/view_product_product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="inherit_id" ref="product.product_normal_form_view" />
<field name="arch" type="xml">
<xpath expr="//group[@name='group_general']" position="inside">
<field name="print_category_id" groups="product_print_category.user" />
<field name="to_print" groups="product_print_category.user" />
<field name="print_category_id" />
<field name="to_print" />
</xpath>
</field>
</record>
Expand Down
3 changes: 0 additions & 3 deletions product_print_category/views/view_product_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field
name="print_category_id"
attrs="{'invisible': [('product_variant_count', '&gt;', 1)]}"
groups="product_print_category.user"
/>
<field
name="to_print"
attrs="{'invisible': [('product_variant_count', '&gt;', 1)]}"
groups="product_print_category.user"
/>
<p
attrs="{'invisible': [('product_variant_count', '&lt;=', 1)]}"
groups="product_print_category.user"
class="fst-italic text-muted"
colspan="2"
>Print options should be configured on Product Variants</p>
Expand Down

0 comments on commit a7df4f6

Please sign in to comment.