Skip to content

Commit

Permalink
Merge pull request OCA#42 from cyrilgdn/price_unit_readonly
Browse files Browse the repository at this point in the history
Trello OCA#137: Price unit readonly
  • Loading branch information
Cyril Gaudin committed Nov 18, 2016
2 parents 0366227 + 177cb0e commit 8bda4a5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
29 changes: 28 additions & 1 deletion odoo/local-src/specific_discount_program/models/sale_order.py
Expand Up @@ -6,7 +6,7 @@
from datetime import date
from dateutil.relativedelta import relativedelta

from openerp import api, fields, models
from openerp import api, fields, models, SUPERUSER_ID


class SaleOrder(models.Model):
Expand Down Expand Up @@ -133,3 +133,30 @@ def action_cancel(self):
program.sudo().unlink()

return result


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

can_edit_price_unit = fields.Boolean(
compute='_compute_can_edit_price_unit'
)
price_unit_readonly = fields.Float(
'Unit Price',
related='price_unit',
readonly=True,
)

@api.depends()
def _compute_can_edit_price_unit(self):
""" price_unit is editable only for admin and Depiltech Admin.
"""
admin = self.env.user.id == SUPERUSER_ID or self.env.user.has_group(
'specific_base.group_admin_depiltech'
)
for line in self:
line.can_edit_price_unit = admin

@api.onchange('price_unit_readonly')
def onchange_price_unit_readonly(self):
self.price_unit = self.price_unit_readonly
16 changes: 16 additions & 0 deletions odoo/local-src/specific_discount_program/views/sale_order.xml
Expand Up @@ -17,6 +17,22 @@
<xpath expr="//field[@name='order_line']/tree//field[@name='discount']" position="attributes">
<attribute name="readonly">1</attribute>
</xpath>

<xpath expr="//field[@name='order_line']/form//field[@name='price_unit']" position="before">
<field name="can_edit_price_unit" invisible="1"/>
<field name="price_unit_readonly" attrs="{'readonly': [('can_edit_price_unit', '=', False)]}"/>
</xpath>
<xpath expr="//field[@name='order_line']/form//field[@name='price_unit']" position="attributes">
<attribute name="invisible">True</attribute>
</xpath>

<xpath expr="//field[@name='order_line']/tree//field[@name='price_unit']" position="before">
<field name="can_edit_price_unit" invisible="1"/>
<field name="price_unit_readonly" attrs="{'readonly': [('can_edit_price_unit', '=', False)]}"/>
</xpath>
<xpath expr="//field[@name='order_line']/tree//field[@name='price_unit']" position="attributes">
<attribute name="invisible">True</attribute>
</xpath>
</field>
</record>
</odoo>

0 comments on commit 8bda4a5

Please sign in to comment.