Make component fields readonly on non draft sale and purchase
Closes #14130
This commit is contained in:
@@ -253,6 +253,9 @@ def order_line_component_mixin(prefix):
|
||||
domain=[
|
||||
('product.type', '=', 'kit'),
|
||||
])
|
||||
line_state = fields.Function(
|
||||
fields.Selection('get_line_states', "Line State"),
|
||||
'on_change_with_line_state', searcher='search_line_state')
|
||||
moves = fields.One2Many('stock.move', 'origin', 'Moves', readonly=True)
|
||||
moves_ignored = fields.Many2Many(
|
||||
prefix + '.line.component-ignored-stock.move',
|
||||
@@ -278,6 +281,21 @@ def order_line_component_mixin(prefix):
|
||||
super().__setup__()
|
||||
cls.__access__.add('line')
|
||||
|
||||
@classmethod
|
||||
def get_line_states(cls):
|
||||
pool = Pool()
|
||||
Line = pool.get(f'{prefix}.line')
|
||||
return getattr(Line, f'get_{prefix}_states')()
|
||||
|
||||
@fields.depends('line', f'_parent_line.{prefix}_state')
|
||||
def on_change_with_line_state(self, name=None):
|
||||
if self.line:
|
||||
return getattr(self.line, f'{prefix}_state')
|
||||
|
||||
@classmethod
|
||||
def search_line_state(cls, name, clause):
|
||||
return [(f'line.{prefix}_state', *clause[1:])]
|
||||
|
||||
@fields.depends('line', '_parent_line.product')
|
||||
def on_change_with_parent_type(self, name=None):
|
||||
if self.line and self.line.product:
|
||||
|
||||
@@ -7,6 +7,7 @@ from trytond.i18n import gettext
|
||||
from trytond.model import ModelSQL, ModelView, fields
|
||||
from trytond.modules.product import round_price
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
from .common import (
|
||||
@@ -78,6 +79,17 @@ class LineComponent(
|
||||
ModelSQL, ModelView):
|
||||
__name__ = 'purchase.line.component'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
states = {
|
||||
'readonly': Eval('line_state') != 'draft',
|
||||
}
|
||||
cls.product.states = states
|
||||
cls.quantity.states = states
|
||||
cls.unit.states = states
|
||||
cls.fixed.states = states
|
||||
|
||||
def get_move(self, move_type):
|
||||
from trytond.modules.purchase.exceptions import PartyLocationError
|
||||
pool = Pool()
|
||||
|
||||
@@ -4,6 +4,7 @@ from trytond.i18n import gettext
|
||||
from trytond.model import ModelSQL, ModelView, fields
|
||||
from trytond.modules.product import round_price
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
from .common import (
|
||||
@@ -72,6 +73,17 @@ class LineComponent(
|
||||
ModelSQL, ModelView):
|
||||
__name__ = 'sale.line.component'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
states = {
|
||||
'readonly': Eval('line_state') != 'draft',
|
||||
}
|
||||
cls.product.states = states
|
||||
cls.quantity.states = states
|
||||
cls.unit.states = states
|
||||
cls.fixed.states = states
|
||||
|
||||
@property
|
||||
def warehouse(self):
|
||||
return self.line.warehouse
|
||||
|
||||
Reference in New Issue
Block a user