Add ir.message and use custom exceptions
issue3672
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
# 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.exceptions import UserError
|
||||
|
||||
|
||||
class InvoiceShipmentCostError(UserError):
|
||||
pass
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data group="1">
|
||||
<record model="ir.message" id="msg_sale_invalid_carrier">
|
||||
<field name="text">To confirm sale "%(sale)s" you must change the carrier "%(carrier)s".</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_shipment_cost_invoice_missing_account_revenue">
|
||||
<field name="text">To invoice shipment cost of "%(shipment)s", you must define an account revenue for product "%(product)s".</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
@@ -3,12 +3,14 @@
|
||||
from decimal import Decimal
|
||||
|
||||
from trytond import backend
|
||||
from trytond.i18n import gettext
|
||||
from trytond.model import ModelView, Workflow, fields
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pyson import Eval, If
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
|
||||
from trytond.modules.product import price_digits
|
||||
from trytond.modules.sale.exceptions import SaleConfirmError
|
||||
|
||||
__all__ = ['Configuration', 'ConfigurationSaleMethod', 'Sale', 'SaleLine',
|
||||
'ReturnSale', 'Promotion']
|
||||
@@ -96,15 +98,6 @@ class Sale(metaclass=PoolMeta):
|
||||
'readonly': Eval('state') != 'draft',
|
||||
}, depends=['state'])
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Sale, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'invalid_carrier': (
|
||||
"The carrier '%(carrier)s' on sale '%(sale)s' "
|
||||
"is not valid."),
|
||||
})
|
||||
|
||||
@staticmethod
|
||||
def default_shipment_cost_method():
|
||||
Config = Pool().get('sale.configuration')
|
||||
@@ -193,10 +186,10 @@ class Sale(metaclass=PoolMeta):
|
||||
def confirm(cls, sales):
|
||||
for sale in sales:
|
||||
if sale.carrier and sale.carrier not in sale.available_carriers:
|
||||
cls.raise_user_error('invalid_carrier', {
|
||||
'sale': sale.rec_name,
|
||||
'carrier': sale.carrier.rec_name,
|
||||
})
|
||||
raise SaleConfirmError(
|
||||
gettext('sale_shipment_cost.msg_sale_invalid_carrier',
|
||||
sale=sale.rec_name,
|
||||
carrier=sale.carrier.rec_name))
|
||||
super(Sale, cls).confirm(sales)
|
||||
|
||||
def _get_carrier_context(self):
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from decimal import Decimal
|
||||
|
||||
from trytond.i18n import gettext
|
||||
from trytond.model import fields
|
||||
from trytond.pyson import Eval, Bool
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
|
||||
from trytond.modules.product import price_digits
|
||||
from .exceptions import InvoiceShipmentCostError
|
||||
|
||||
__all__ = ['ShipmentOut']
|
||||
|
||||
@@ -35,14 +37,6 @@ class ShipmentOut(metaclass=PoolMeta):
|
||||
cost_invoice_line = fields.Many2One('account.invoice.line',
|
||||
'Cost Invoice Line', readonly=True)
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(ShipmentOut, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'missing_account_revenue': ('Missing "Account Revenue" on '
|
||||
'product "%s".'),
|
||||
})
|
||||
|
||||
def _get_carrier_context(self):
|
||||
return {}
|
||||
|
||||
@@ -119,6 +113,9 @@ class ShipmentOut(metaclass=PoolMeta):
|
||||
|
||||
invoice_line.account = product.account_revenue_used
|
||||
if not invoice_line.account:
|
||||
self.raise_user_error('missing_account_revenue',
|
||||
error_args=(product.rec_name,))
|
||||
raise InvoiceShipmentCostError(
|
||||
gettext('sale_shipment_cost'
|
||||
'.msg_shipment_cost_invoice_missing_account_revenue',
|
||||
shipment=self.rec_name,
|
||||
product=product.rec_name))
|
||||
return invoice_line
|
||||
|
||||
@@ -13,3 +13,4 @@ extras_depend:
|
||||
xml:
|
||||
sale.xml
|
||||
stock.xml
|
||||
message.xml
|
||||
|
||||
Reference in New Issue
Block a user