changeset 53790b0b786f in modules/product_cost_warehouse:default
details:
https://hg.tryton.org/modules/product_cost_warehouse?cmd=changeset&node=53790b0b786f
description:
Prevent editing list and cost prices without proper context
issue10773
review338951002
diffstat:
CHANGELOG | 1 +
__init__.py | 2 ++
product.py | 22 ++++++++++++++++++++++
res.py | 15 +++++++++++++++
tryton.cfg | 1 +
5 files changed, 41 insertions(+), 0 deletions(-)
diffs (103 lines):
diff -r 97a0ff35ecf0 -r 53790b0b786f CHANGELOG
--- a/CHANGELOG Thu Sep 23 10:08:37 2021 +0200
+++ b/CHANGELOG Fri Oct 08 19:16:44 2021 +0200
@@ -1,3 +1,4 @@
+* Prevent editing cost price without a warehouse when required
* Replace cost_warehouse by warehouse of stock module
Version 6.0.0 - 2021-05-03
diff -r 97a0ff35ecf0 -r 53790b0b786f __init__.py
--- a/__init__.py Thu Sep 23 10:08:37 2021 +0200
+++ b/__init__.py Fri Oct 08 19:16:44 2021 +0200
@@ -3,6 +3,7 @@
from trytond.pool import Pool
from . import ir
+from . import res
from . import company
from . import product
from . import account
@@ -15,6 +16,7 @@
Pool.register(
ir.Cron,
ir.CronWarehouse,
+ res.User,
company.Company,
product.Configuration,
product.ConfigurationCostPriceWarehouse,
diff -r 97a0ff35ecf0 -r 53790b0b786f product.py
--- a/product.py Thu Sep 23 10:08:37 2021 +0200
+++ b/product.py Fri Oct 08 19:16:44 2021 +0200
@@ -36,6 +36,17 @@
class Product(metaclass=PoolMeta):
__name__ = 'product.product'
+ @classmethod
+ def __setup__(cls):
+ super().__setup__()
+ readonly = (
+ Eval('context', {}).get('cost_price_warehouse', False)
+ & ~Eval('context', {}).get('warehouse'))
+ if cls.cost_price.states['readonly']:
+ cls.cost_price.states['readonly'] |= readonly
+ else:
+ cls.cost_price.states['readonly'] = readonly
+
def multivalue_records(self, field):
Value = self.multivalue_model(field)
records = super().multivalue_records(field)
@@ -64,6 +75,8 @@
company = Company(context['company'])
if company.cost_price_warehouse:
pattern.setdefault('warehouse', context.get('warehouse'))
+ if not value and not pattern.get('warehouse'):
+ return []
return super().set_multivalue(name, value, save=save, **pattern)
@classmethod
@@ -162,6 +175,15 @@
]
return domain
+ @classmethod
+ def default_cost_price(cls, **pattern):
+ context = Transaction().context
+ default = super().default_cost_price()
+ if (context.get('cost_price_warehouse')
+ and not pattern.get('warehouse', context.get('warehouse'))):
+ default = None
+ return default
+
class CostPrice(metaclass=PoolMeta):
__name__ = 'product.cost_price'
diff -r 97a0ff35ecf0 -r 53790b0b786f res.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/res.py Fri Oct 08 19:16:44 2021 +0200
@@ -0,0 +1,15 @@
+# This file is part of Tryton. The COPYRIGHT file at the top level of
+# this repository contains the full copyright notices and license terms.
+from trytond.pool import PoolMeta
+
+
+class User(metaclass=PoolMeta):
+ __name__ = 'res.user'
+
+ @classmethod
+ def _get_preferences(cls, user, context_only=False):
+ preferences = super()._get_preferences(user, context_only=context_only)
+ if user.company:
+ preferences['cost_price_warehouse'] = (
+ user.company.cost_price_warehouse)
+ return preferences
diff -r 97a0ff35ecf0 -r 53790b0b786f tryton.cfg
--- a/tryton.cfg Thu Sep 23 10:08:37 2021 +0200
+++ b/tryton.cfg Fri Oct 08 19:16:44 2021 +0200
@@ -4,6 +4,7 @@
company
ir
product
+ res
stock
extras_depend:
account_invoice_stock