Skip to content

Commit

Permalink
[IMP] sale_margin_security: Allows more flexibility in groups
Browse files Browse the repository at this point in the history
As in some flows, people want to split fields visibility to buyers and
salesmen, restore the margin group. As in cost module, there is
two groups, add a group for sale margins + edit costs
  • Loading branch information
rousseldenis committed Dec 11, 2024
1 parent 1227f62 commit cef55d7
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 15 deletions.
3 changes: 2 additions & 1 deletion sale_margin_security/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Sale Margin Security",
"version": "16.0.3.1.0",
"version": "16.0.3.2.0",
"author": "Tecnativa," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/margin-analysis",
"category": "Sales",
Expand All @@ -11,6 +11,7 @@
"maintainers": ["sergio-teruel", "rafaelbn", "yajo"],
"depends": ["sale_margin", "product_cost_security"],
"data": [
"security/security.xml",
"views/sale_margin_security_view.xml",
],
"auto_install": True,
Expand Down
25 changes: 25 additions & 0 deletions sale_margin_security/migrations/16.0.3.2.0/post-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2024 Moduon Team S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)
from odoo import SUPERUSER_ID, api


def migrate(cr, version):
env = api.Environment(cr, SUPERUSER_ID, {})

users_read = env["res.users"].search(
[("groups_id", "in", env.ref("product_cost_security.group_product_cost").ids)]
)
users_read.groups_id += env.ref("sale_margin_security.group_sale_margin_security")

users_edit = env["res.users"].search(
[
(
"groups_id",
"in",
env.ref("product_cost_security.group_product_edit_cost").ids,
)
]
)
users_edit.groups_id += env.ref(
"sale_margin_security.group_sale_margin_edit_security"
)
14 changes: 9 additions & 5 deletions sale_margin_security/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@

class SaleOrder(models.Model):
_name = "sale.order"
_inherit = ["sale.order", "product.cost.security.mixin"]
_inherit = ["sale.order"]

margin = fields.Monetary(groups="product_cost_security.group_product_cost")
margin_percent = fields.Float(groups="product_cost_security.group_product_cost")
margin = fields.Monetary(groups="sale_margin_security.group_sale_margin_security")
margin_percent = fields.Float(
groups="sale_margin_security.group_sale_margin_security"
)


class SaleOrderLine(models.Model):
_name = "sale.order.line"
_inherit = ["sale.order.line", "product.cost.security.mixin"]

margin = fields.Float(groups="product_cost_security.group_product_cost")
margin_percent = fields.Float(groups="product_cost_security.group_product_cost")
margin = fields.Float(groups="sale_margin_security.group_sale_margin_security")
margin_percent = fields.Float(
groups="sale_margin_security.group_sale_margin_security"
)
purchase_price = fields.Float(groups="product_cost_security.group_product_cost")
4 changes: 2 additions & 2 deletions sale_margin_security/report/sale_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

class SaleReport(models.Model):
_name = "sale.report"
_inherit = ["sale.report", "product.cost.security.mixin"]
_inherit = ["sale.report"]

margin = fields.Float(groups="product_cost_security.group_product_cost")
margin = fields.Float(groups="sale_margin_security.group_sale_margin_security")
22 changes: 22 additions & 0 deletions sale_margin_security/security/security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2018 Tecnativa - Sergio Teruel
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="group_sale_margin_security" model="res.groups">
<field name="name">Show Sale Margin (and Show Costs)</field>
<field name="category_id" ref="base.module_category_hidden" />
<field
name="implied_ids"
eval="[(4, ref('product_cost_security.group_product_cost'))]"
/>
</record>

<record id="group_sale_margin_edit_security" model="res.groups">
<field name="name">Show Sale Margin (and Edit Costs)</field>
<field name="category_id" ref="base.module_category_hidden" />
<field
name="implied_ids"
eval="[(4, ref('group_sale_margin_security')), (4, ref('product_cost_security.group_product_edit_cost'))]"
/>
</record>
</odoo>
11 changes: 7 additions & 4 deletions sale_margin_security/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -445,7 +446,9 @@ <h2><a class="toc-backref" href="#toc-entry-8">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-9">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
4 changes: 2 additions & 2 deletions sale_margin_security/tests/test_sale_margin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ def setUpClass(cls):
login="salesperson_edit",
groups=(
"sales_team.group_sale_salesman,"
"product_cost_security.group_product_edit_cost"
"sale_margin_security.group_sale_margin_edit_security"
),
)
cls.salesperson_read = new_test_user(
cls.env,
name="Salesperson PC Read",
login="salesperson_read",
groups="sales_team.group_sale_salesman,product_cost_security.group_product_cost",
groups="sales_team.group_sale_salesman,sale_margin_security.group_sale_margin_security",
)
cls.salesperson_none = new_test_user(
cls.env,
Expand Down
2 changes: 1 addition & 1 deletion sale_margin_security/views/sale_margin_security_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<xpath expr="//field[@name='margin']/.." position="attributes">
<attribute
name="groups"
>product_cost_security.group_product_cost</attribute>
>sale_margin_security.group_sale_margin_security</attribute>
</xpath>
</field>
</record>
Expand Down

0 comments on commit cef55d7

Please sign in to comment.