From da43d5b2e4a7bf6354eb152856cd7bc304eac64f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 18 Dec 2020 00:19:07 +0100 Subject: [PATCH] Allow choosing the DPD product and formats issue9857 review328991002 --- CHANGELOG | 2 ++ carrier.py | 48 +++++++++++++++++++++++++++++++++ carrier.xml | 6 +++++ doc/index.rst | 9 +++++++ stock.py | 6 ++--- tests/scenario_shipping_dpd.rst | 3 +++ view/carrier_form.xml | 15 +++++++++++ 7 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 view/carrier_form.xml diff --git a/CHANGELOG b/CHANGELOG index 28cde10f51..59c1404aac 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Allow choosing the DPD product and formats + Version 5.8.0 - 2020-11-02 * Bug fixes (see mercurial logs for details) * Remove support for Python 3.5 diff --git a/carrier.py b/carrier.py index a8085be700..41bb559fbd 100644 --- a/carrier.py +++ b/carrier.py @@ -8,6 +8,7 @@ from zeep.exceptions import Fault from trytond.i18n import gettext from trytond.model import ModelSQL, ModelView, MatchMixin, fields from trytond.pool import PoolMeta +from trytond.pyson import Eval from .configuration import get_client, LOGIN_SERVICE from .exceptions import DPDError @@ -54,7 +55,54 @@ class CredentialDPD(ModelSQL, ModelView, MatchMixin): class Carrier(metaclass=PoolMeta): __name__ = 'carrier' + dpd_product = fields.Selection([ + (None, ''), + ('CL', "DPD CLASSIC"), + ('E830', "DPD 8:30"), + ('E10', "DPD 10:00"), + ('E12', "DPD 12:00"), + ('E18', "DPD 18:00"), + ('IE2', "DPD EXPRESS"), + ('PL', "DPD PARCEL Letter"), + ('PL+', "DPD PARCEL Letter Plus"), + ('MAIL', "DPD International Mail"), + ], "Product", sort=False, translate=False, + states={ + 'required': Eval('shipping_service') == 'dpd', + 'invisible': Eval('shipping_service') != 'dpd', + }, + depends=['shipping_service']) + dpd_printer_language = fields.Selection([ + (None, ''), + ('PDF', "PDF"), + ('ZPL', "ZPL"), + ], "Printer Language", sort=False, translate=False, + states={ + 'required': Eval('shipping_service') == 'dpd', + 'invisible': Eval('shipping_service') != 'dpd', + }, + depends=['shipping_service']) + dpd_paper_format = fields.Selection([ + (None, ''), + ('A4', "A4"), + ('A6', "A6"), + ('A7', "A7"), + ], "Paper Format", sort=False, translate=False, + states={ + 'required': Eval('shipping_service') == 'dpd', + 'invisible': Eval('shipping_service') != 'dpd', + }, + depends=['shipping_service']) + @classmethod def __setup__(cls): super(Carrier, cls).__setup__() cls.shipping_service.selection.append(('dpd', 'DPD')) + + @classmethod + def view_attributes(cls): + return super().view_attributes() + [ + ("/form/separator[@id='dpd']", 'states', { + 'invisible': Eval('shipping_service') != 'dpd', + }), + ] diff --git a/carrier.xml b/carrier.xml index 24544e0fde..7efc451e7b 100644 --- a/carrier.xml +++ b/carrier.xml @@ -3,6 +3,12 @@ this repository contains the full copyright notices and license terms. --> + + carrier + + carrier_form + + carrier.credential.dpd form diff --git a/doc/index.rst b/doc/index.rst index 0ccd954adc..903254ebfe 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -20,3 +20,12 @@ Shipment. - *Password*: The Password used to access the DPD API. - *Server*: Are those credentials used for accessing the Testing or the Production server. + +Carrier +******* + +The Carrier model is extended with the following fields: + +- *Product*: The DPD product requested. +- *Printer Language*: The type of file used for the label sent by DPD +- *Paper Format*: The format of the label sent by DPD diff --git a/stock.py b/stock.py index fc5a6ea7c1..f5a5890fb0 100644 --- a/stock.py +++ b/stock.py @@ -152,8 +152,8 @@ class CreateDPDShipping(Wizard): def get_print_options(self, shipment): return { - 'printerLanguage': 'PDF', - 'paperFormat': 'A6', + 'printerLanguage': shipment.carrier.dpd_printer_language, + 'paperFormat': shipment.carrier.dpd_paper_format, } def shipping_party(self, party, address): @@ -216,7 +216,7 @@ class CreateDPDShipping(Wizard): 'generalShipmentData': { 'identificationNumber': shipment.number, 'sendingDepot': credential.depot, - 'product': 'CL', + 'product': shipment.carrier.dpd_product, 'sender': self.shipping_party( shipment.company.party, shipment.warehouse.address), 'recipient': self.shipping_party( diff --git a/tests/scenario_shipping_dpd.rst b/tests/scenario_shipping_dpd.rst index f6b985cc81..79df91076f 100644 --- a/tests/scenario_shipping_dpd.rst +++ b/tests/scenario_shipping_dpd.rst @@ -175,6 +175,9 @@ Create a DPD Carrier and the related credential:: >>> carrier.party = dpd >>> carrier.carrier_product = carrier_product >>> carrier.shipping_service = 'dpd' + >>> carrier.dpd_product = 'CL' + >>> carrier.dpd_printer_language = 'PDF' + >>> carrier.dpd_paper_format = 'A6' >>> carrier.save() >>> catchall_selection = CarrierSelection(carrier=carrier) diff --git a/view/carrier_form.xml b/view/carrier_form.xml new file mode 100644 index 0000000000..51c35f23a7 --- /dev/null +++ b/view/carrier_form.xml @@ -0,0 +1,15 @@ + + + + + + +