Cédric Krier pushed to branch branch/default at Tryton / Tryton
Commits:
bf0b2af7 by Cédric Krier at 2023-01-03T11:17:51+01:00
Require a carrier to quote sale with shipment cost method
Closes #11985
- - - - -
ee4a5e9b by Cédric Krier at 2023-01-03T11:23:03+01:00
Do not enforce empty shipment cost method for draft sale
As draft sale can be created by other modules, we must put such constraint
when quoting the sale.
Closes #11900
- - - - -
3 changed files:
- modules/sale_shipment_cost/CHANGELOG
- modules/sale_shipment_cost/message.xml
- modules/sale_shipment_cost/sale.py
Changes:
=====================================
modules/sale_shipment_cost/CHANGELOG
=====================================
@@ -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)
=====================================
modules/sale_shipment_cost/message.xml
=====================================
@@ -6,6 +6,9 @@
<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>
=====================================
modules/sale_shipment_cost/sale.py
=====================================
@@ -6,7 +6,8 @@
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
@@ -97,7 +98,7 @@
('shipment', "On Shipment"),
], "Shipment Cost Method",
domain=[
- If(~Eval('carrier'),
+ If(~Eval('carrier') & (Eval('state') != 'draft'),
('shipment_cost_method', '=', None),
()),
],
@@ -198,6 +199,19 @@
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')
View it on Heptapod:
https://foss.heptapod.net/tryton/tryton/-/compare/316842e2d77c16f0b3175ecf9ed9a117ebf21bf3...ee4a5e9b7439d29eab649ba633847aa23e93407f
--
View it on Heptapod:
https://foss.heptapod.net/tryton/tryton/-/compare/316842e2d77c16f0b3175ecf9ed9a117ebf21bf3...ee4a5e9b7439d29eab649ba633847aa23e93407f
You're receiving this email because of your account on foss.heptapod.net.