changeset 34a5debdca00 in modules/sale_shipment_cost:default
details:
https://hg.tryton.org/modules/sale_shipment_cost?cmd=changeset&node=34a5debdca00
description:
Support warehouse pickup
issue11574
review419411003
diffstat:
sale.py | 27 +++++++++++++++++++++------
1 files changed, 21 insertions(+), 6 deletions(-)
diffs (55 lines):
diff -r 84769bd18480 -r 34a5debdca00 sale.py
--- a/sale.py Sat Sep 10 17:35:38 2022 +0200
+++ b/sale.py Sat Sep 10 18:34:29 2022 +0200
@@ -92,10 +92,16 @@
fields.Many2Many('carrier', None, None, 'Available Carriers'),
'on_change_with_available_carriers')
shipment_cost_method = fields.Selection([
- (None, "None"),
- ('order', 'On Order'),
- ('shipment', 'On Shipment'),
- ], 'Shipment Cost Method', states={
+ (None, "None"),
+ ('order', "On Order"),
+ ('shipment', "On Shipment"),
+ ], "Shipment Cost Method",
+ domain=[
+ If(~Eval('carrier'),
+ ('shipment_cost_method', '=', None),
+ ()),
+ ],
+ states={
'readonly': Eval('state') != 'draft',
})
@@ -134,11 +140,18 @@
pattern['to_country'] = None
return pattern
- @fields.depends(methods=['_get_carrier_selection_pattern'])
+ @fields.depends(
+ 'warehouse', 'shipment_address',
+ methods=['_get_carrier_selection_pattern'])
def on_change_with_available_carriers(self, name=None):
pool = Pool()
CarrierSelection = pool.get('carrier.selection')
+ if (self.warehouse
+ and self.shipment_address
+ and self.warehouse.address == self.shipment_address):
+ return []
+
pattern = self._get_carrier_selection_pattern()
carriers = CarrierSelection.get_carriers(pattern)
return [c.id for c in carriers]
@@ -152,7 +165,9 @@
self.carrier = self.available_carriers[0]
elif not self.available_carriers:
self.carrier = None
- if self.party and self.party.sale_shipment_cost_method:
+ if not self.carrier:
+ self.shipment_cost_method = None
+ elif self.party and self.party.sale_shipment_cost_method:
self.shipment_cost_method = self.party.sale_shipment_cost_method
else:
self.shipment_cost_method = self.default_shipment_cost_method()