Require a carrier to quote sale with shipment cost method
Closes #11985
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
* Require carrier to quote sale with shipment cost method
|
||||
|
||||
Version 6.6.0 - 2022-10-31
|
||||
--------------------------
|
||||
* Bug fixes (see mercurial logs for details)
|
||||
|
||||
@@ -6,6 +6,9 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<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_sale_carrier_required_for_quotation">
|
||||
<field name="text">To get a quote for sale "%(sale)s" you must enter a carrier.</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>
|
||||
|
||||
@@ -6,7 +6,8 @@ from trytond import backend
|
||||
from trytond.i18n import gettext
|
||||
from trytond.model import ModelView, Workflow, fields
|
||||
from trytond.modules.product import price_digits, round_price
|
||||
from trytond.modules.sale.exceptions import SaleConfirmError
|
||||
from trytond.modules.sale.exceptions import (
|
||||
SaleConfirmError, SaleQuotationError)
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval, If
|
||||
from trytond.transaction import Transaction
|
||||
@@ -198,6 +199,19 @@ class Sale(metaclass=PoolMeta):
|
||||
elif not self.available_carriers:
|
||||
self.carrier = None
|
||||
|
||||
def check_for_quotation(self):
|
||||
super().check_for_quotation()
|
||||
if self.shipment_cost_method and self.available_carriers:
|
||||
for line in self.lines:
|
||||
if (line.product
|
||||
and line.product.type != 'service'
|
||||
and line.quantity >= 0
|
||||
and not self.carrier):
|
||||
raise SaleQuotationError(
|
||||
gettext('sale'
|
||||
'.msg_sale_carrier_required_for_quotation',
|
||||
sale=self.rec_name))
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@Workflow.transition('quotation')
|
||||
|
||||
Reference in New Issue
Block a user