Prevent to delete shipment costs if they are not cancelled or draft
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -9,5 +9,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<record model="ir.message" id="msg_shipment_cost_post_same_parties">
|
||||
<field name="text">The shipment "%(shipment)s" of shipment cost "%(shipment_cost)s" has already shipment cost from the same party "%(other)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_shipment_cost_delete_cancel">
|
||||
<field name="text">To delete shipment cost "%(shipment_cost)s" you must cancel it.</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user