Skip to content

Commit

Permalink
[IMP]price_security_sale_margin: new module
Browse files Browse the repository at this point in the history
hides sale margin fields in sale order views
  • Loading branch information
jok-adhoc committed Aug 22, 2023
1 parent daa0abe commit 3be139d
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 0 deletions.
80 changes: 80 additions & 0 deletions price_security_sale_margin/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
.. |company| replace:: ADHOC SA

.. |company_logo| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-logo.png
:alt: ADHOC SA
:target: https://www.adhoc.com.ar

.. |icon| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-icon.png

.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

===============================
Price Security with sale margin
===============================

This module is an integration of Price Security with Sale Margin.

Installation
============

To install this module, you need to:

#. Just install this module.


Configuration
=============

To configure this module, you need to:

#. Set 'Restrict Prices' for users you want to restrict.
#. For the same users, configure discounts range on "Discounts Permissions" users tab.


Usage
=====

To use this module, you need to:

For users with price restriction, it restricts:

* on sales orders: change payment term or pricelist
* on sales order lines: change unit price and set limits on discount (limits configured on user)
* on partners: change payment term or pricelist
* on invoices: change unit price
* on invoice lines: change unit price and set limits on discount (limits configured on user)
* on product: change price

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: http://runbot.adhoc.com.ar/

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/ingadhoc/product/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.

Credits
=======

Images
------

* |company| |icon|

Contributors
------------

Maintainer
----------

|company_logo|

This module is maintained by the |company|.

To contribute to this module, please visit https://www.adhoc.com.ar.
5 changes: 5 additions & 0 deletions price_security_sale_margin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from . import models
33 changes: 33 additions & 0 deletions price_security_sale_margin/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
##############################################################################
#
# Copyright (C) 2015 ADHOC SA (http://www.adhoc.com.ar)
# All Rights Reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Price Security with sale margin',
'version': "16.0.1.0.0",
'category': 'Sales Management',
'author': 'ADHOC SA',
'website': 'http://www.adhoc.com.ar/',
'license': 'AGPL-3',
'depends': [
'price_security',
'sale_margin',
],
'installable': True,
'auto_install': True,
}
15 changes: 15 additions & 0 deletions price_security_sale_margin/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-04-25 13:24+0000\n"
"PO-Revision-Date: 2022-04-19 21:47+0000\n"
"Language-Team: Spanish (https://www.transifex.com/adhoc/teams/133229/es/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: es\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
2 changes: 2 additions & 0 deletions price_security_sale_margin/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import sale_order
from . import sale_order_line
30 changes: 30 additions & 0 deletions price_security_sale_margin/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from odoo import models, api
import json


class SaleOrder(models.Model):
_inherit = 'sale.order'

@api.model
def _get_view(self, view_id=None, view_type='form', **options):
arch, view = super()._get_view(view_id, view_type, **options)
if view_type == 'form':
if self.env.user.has_group('price_security.group_only_view'):
readonly_fields = (arch.xpath("//field[@name='purchase_price']")
+ arch.xpath("//field[@name='margin']")
+ arch.xpath("//field[@name='margin_percent']"))
for node in readonly_fields:
node.set('readonly', '1')
modifiers = json.loads(node.get("modifiers") or "{}")
modifiers['readonly'] = True
node.set("modifiers", json.dumps(modifiers))
if self.env.user.has_group('price_security.group_only_view_sale_price'):
invisible_fields = (arch.xpath("//field[@name='purchase_price']")
+ arch.xpath("//field[@name='margin']")
+ arch.xpath("//field[@name='margin_percent']"))
for node in invisible_fields:
node.set('invisible', '1')
modifiers = json.loads(node.get("modifiers") or "{}")
modifiers['invisible'] = True
node.set("modifiers", json.dumps(modifiers))
return arch, view
30 changes: 30 additions & 0 deletions price_security_sale_margin/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from odoo import models, api
import json


class SaleOrder(models.Model):
_inherit = 'sale.order.line'

@api.model
def _get_view(self, view_id=None, view_type='form', **options):
arch, view = super()._get_view(view_id, view_type, **options)
if view_type == 'tree':
if self.env.user.has_group('price_security.group_only_view'):
readonly_fields = (arch.xpath("//field[@name='purchase_price']")
+ arch.xpath("//field[@name='margin']")
+ arch.xpath("//field[@name='margin_percent']"))
for node in readonly_fields:
node.set('readonly', '1')
modifiers = json.loads(node.get("modifiers") or "{}")
modifiers['readonly'] = True
node.set("modifiers", json.dumps(modifiers))
if self.env.user.has_group('price_security.group_only_view_sale_price'):
invisible_fields = (arch.xpath("//field[@name='purchase_price']")
+ arch.xpath("//field[@name='margin']")
+ arch.xpath("//field[@name='margin_percent']"))
for node in invisible_fields:
node.set('invisible', '1')
modifiers = json.loads(node.get("modifiers") or "{}")
modifiers['invisible'] = True
node.set("modifiers", json.dumps(modifiers))
return arch, view

0 comments on commit 3be139d

Please sign in to comment.