diff --git a/modules/account_stock_shipment_cost/account.py b/modules/account_stock_shipment_cost/account.py index 3e45e861f7..24365afe22 100644 --- a/modules/account_stock_shipment_cost/account.py +++ b/modules/account_stock_shipment_cost/account.py @@ -7,6 +7,7 @@ from sql.functions import CharLength from trytond.i18n import gettext from trytond.model import Index, ModelSQL, ModelView, Workflow, fields +from trytond.model.exceptions import AccessError from trytond.modules.company.model import CompanyValueMixin from trytond.modules.product import price_digits, round_price from trytond.pool import Pool, PoolMeta @@ -334,6 +335,16 @@ class ShipmentCost(Workflow, ModelSQL, ModelView): company=values.get('company', default_company)).get() return super().create(vlist) + @classmethod + def delete(cls, shipment_costs): + for shipment_cost in shipment_costs: + if shipment_cost.state not in {'cancelled', 'draft'}: + raise AccessError( + gettext('account_stock_shipment_cost' + '.msg_shipment_cost_delete_cancel', + shipment_cost=shipment_cost.rec_name)) + super().delete(shipment_costs) + class ShipmentCost_Shipment(ModelSQL): __name__ = 'account.shipment_cost-stock.shipment.out' diff --git a/modules/account_stock_shipment_cost/message.xml b/modules/account_stock_shipment_cost/message.xml index 339e9264fc..8887d16264 100644 --- a/modules/account_stock_shipment_cost/message.xml +++ b/modules/account_stock_shipment_cost/message.xml @@ -9,5 +9,8 @@ this repository contains the full copyright notices and license terms. --> The shipment "%(shipment)s" of shipment cost "%(shipment_cost)s" has already shipment cost from the same party "%(other)s". + + To delete shipment cost "%(shipment_cost)s" you must cancel it. + diff --git a/modules/account_stock_shipment_cost/tests/scenario_account_stock_shipment_cost.rst b/modules/account_stock_shipment_cost/tests/scenario_account_stock_shipment_cost.rst index 122219981e..21bb24047d 100644 --- a/modules/account_stock_shipment_cost/tests/scenario_account_stock_shipment_cost.rst +++ b/modules/account_stock_shipment_cost/tests/scenario_account_stock_shipment_cost.rst @@ -219,6 +219,13 @@ Check shipment cost:: >>> shipment2.cost Decimal('5.0000') +Can not delete posted shipment cost:: + + >>> shipment_cost1.delete() + Traceback (most recent call last): + ... + AccessError: ... + Cancel shipment cost remove the price:: >>> shipment_cost1.click('cancel') @@ -234,3 +241,7 @@ Check shipment cost:: >>> shipment2.reload() >>> shipment2.cost Decimal('0.0000') + +Can delete cancelled shipment cost:: + + >>> shipment_cost1.delete()